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 { /// /// 添加物品日志 /// /// /// /// /// /// 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; } /// /// 获取下个还款日 /// /// 计算时间 /// 账单日 /// 还款日模式 /// 还款日 /// 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); } } } /// /// post数据 /// /// /// /// 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; } /// /// post数据 /// /// /// /// 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 { /// /// 判断是否成功执行 /// 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); } } }