### MyHouse V1.0.2502.0801 - *.[新增]适配新版接口。 ### SmartHouseAPI V1.0.2502.0801 - *.[新增]支持Docker部署,支持NAS。
191 lines
7.1 KiB
C#
191 lines
7.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace MyHouse.API
|
|
{
|
|
public static class API
|
|
{
|
|
/// <summary>
|
|
/// 添加物品日志
|
|
/// </summary>
|
|
/// <param name="OpName"></param>
|
|
/// <param name="OpId"></param>
|
|
/// <param name="Des"></param>
|
|
/// <param name="AddTime"></param>
|
|
/// <returns></returns>
|
|
public static bool AddGoodsLogs(string OpName, int OpId, string Des,long AddTime=0)
|
|
{
|
|
string post_str = "api=AddLogs&id=" + OpId+ "&opName="+ RyWeb.WebDecode.UrlEncode(OpName)+"&Des="+ RyWeb.WebDecode.UrlEncode(Des) + "&AddTime=" + AddTime;
|
|
var jsonResult = API.Post("goods.aspx", post_str);
|
|
return jsonResult.IsOK;
|
|
}
|
|
/// <summary>
|
|
/// 获取下个还款日
|
|
/// </summary>
|
|
/// <param name="calcDt">计算时间</param>
|
|
/// <param name="BillDate">账单日</param>
|
|
/// <param name="RePayDateMode">还款日模式</param>
|
|
/// <param name="RePayDate">还款日</param>
|
|
/// <returns></returns>
|
|
public static DateTime GetNextRepayDate(DateTime calcDt, int BillDate,int RePayDateMode, int RePayDate)
|
|
{
|
|
int day = calcDt.Day;
|
|
int addmonth = 1;
|
|
if (RePayDateMode == 0)
|
|
{
|
|
if (BillDate < RePayDate && (BillDate > day && BillDate != 0)) { addmonth = 0; }
|
|
else if (RePayDate > day && BillDate == 0) { addmonth = 0; }
|
|
else if (BillDate <= day && BillDate != 0)
|
|
{
|
|
addmonth = RePayDate > BillDate ? 1 : 2;
|
|
}
|
|
return calcDt.AddDays(-day + RePayDate).AddMonths(addmonth);
|
|
}
|
|
else
|
|
{
|
|
if(BillDate>=day)
|
|
{
|
|
return calcDt.AddDays(-day + BillDate+RePayDate);
|
|
}
|
|
else
|
|
{
|
|
return calcDt.AddDays(-day+ BillDate).AddMonths(1).AddDays(RePayDate);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// post数据
|
|
/// </summary>
|
|
/// <param name="uri"></param>
|
|
/// <param name="postdata"></param>
|
|
/// <returns></returns>
|
|
public static PostResult Post(string group,string api, string postdata)
|
|
{
|
|
PostResult postResult = new PostResult();
|
|
var html = Public_Config.ry_api.Post(Public_Config.Api_Url + group + "/"+ api, postdata, Public_Config.Cookie);
|
|
if (html.StatusCode == System.Net.HttpStatusCode.OK)
|
|
{
|
|
postResult.json.Text = html.Html;
|
|
postResult.Result = postResult.json.GetJsonValue(ConstVar.json_Result, 0);
|
|
postResult.ResultText = postResult.json.GetJsonValue(ConstVar.json_ResultText, "");
|
|
if (postResult.Result == ResultVar.json_UnLogin)
|
|
{
|
|
postResult.Result = ResultVar.json_UnLogin;
|
|
postResult.ResultText = "登陆失败";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
postResult.Result = -10000;
|
|
postResult.ResultText = "服务器异常,请联系管理员";
|
|
}
|
|
return postResult;
|
|
}
|
|
public static PostResult Get(string group, string api)
|
|
{
|
|
PostResult postResult = new PostResult();
|
|
var html = Public_Config.ry_api.Get(Public_Config.Api_Url + group + "/" + api, Public_Config.Cookie);
|
|
if (html.StatusCode == System.Net.HttpStatusCode.OK)
|
|
{
|
|
postResult.json.Text = html.Html;
|
|
postResult.Result = postResult.json.GetJsonValue(ConstVar.json_Result, 0);
|
|
postResult.ResultText = postResult.json.GetJsonValue(ConstVar.json_ResultText, "");
|
|
if (postResult.Result == ResultVar.json_UnLogin)
|
|
{
|
|
postResult.Result = ResultVar.json_UnLogin;
|
|
postResult.ResultText = "登陆失败";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
postResult.Result = -10000;
|
|
postResult.ResultText = "服务器异常,请联系管理员";
|
|
}
|
|
return postResult;
|
|
}
|
|
/// <summary>
|
|
/// post数据
|
|
/// </summary>
|
|
/// <param name="uri"></param>
|
|
/// <param name="postdata"></param>
|
|
/// <returns></returns>
|
|
public static PostResult Post(string uri, string postdata)
|
|
{
|
|
PostResult postResult = new PostResult();
|
|
var html = Public_Config.ry_api.Post(Public_Config.Api_Url + uri+".aspx",postdata, Public_Config.Cookie);
|
|
if (html.StatusCode== System.Net.HttpStatusCode.OK)
|
|
{
|
|
postResult.json.Text = html.Html;
|
|
postResult.Result = postResult.json.GetJsonValue(ConstVar.json_Result, 0);
|
|
postResult.ResultText = postResult.json.GetJsonValue(ConstVar.json_ResultText, "");
|
|
if (postResult.Result == ResultVar.json_UnLogin)
|
|
{
|
|
postResult.Result = ResultVar.json_UnLogin;
|
|
postResult.ResultText = "登陆失败";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
postResult.Result = -10000;
|
|
postResult.ResultText = "服务器异常,请联系管理员";
|
|
}
|
|
return postResult;
|
|
}
|
|
public static void ErrorJson(PostResult result)
|
|
{
|
|
//if (result == ResultVar.json_UnLogin.ToString())
|
|
//{
|
|
// if (MessageBox.Show("登陆已失效,是否要重新登陆?", "错误代码:" + result, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
|
|
// {
|
|
// FrmLogin frm = new FrmLogin();
|
|
// frm.ShowDialog();
|
|
// }
|
|
//}
|
|
//else
|
|
//{
|
|
MessageBox.Show(result.ResultText, "错误代码:" + result.Result, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
//}
|
|
}
|
|
}
|
|
public class PostResult
|
|
{
|
|
/// <summary>
|
|
/// 判断是否成功执行
|
|
/// </summary>
|
|
public bool IsOK
|
|
{
|
|
get
|
|
{
|
|
return Result == ResultVar.json_Success;
|
|
}
|
|
}
|
|
public int Result { get; set; } = 0;
|
|
public string ResultText { get; set; } = "";
|
|
public Json json { get; set; } = new Json();
|
|
public DataTable List
|
|
{
|
|
get
|
|
{
|
|
return json.GetJsonValueByTable("datas");
|
|
}
|
|
}
|
|
public string Get(string id, string defValue)
|
|
{
|
|
return json.GetJsonValue(id, defValue);
|
|
}
|
|
public int Get(string id, int defValue)
|
|
{
|
|
return json.GetJsonValue(id, defValue);
|
|
}
|
|
public long Get(string id, long defValue)
|
|
{
|
|
return json.GetJsonValue(id, defValue);
|
|
}
|
|
}
|
|
}
|