using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using WebAPI; using WebAPI.Code; using WebAPI.Controllers; using WebAPI.Models; namespace WindowsFormsApp1 { public partial class TestAPI : Form { public TestAPI() { InitializeComponent(); } private JsonResult objJsonResult = new JsonResult(); public static string GetSession(string sMsg) { try { string s = Common.GetSession(); return s; } catch (Exception e) { return ""; } } private void btnCS_Click(object sender, EventArgs e) { // string a=string.Format("); PayRollController web = new PayRollController(); //WebAPIController web2=new WebAPIController(); //string Json="{\"HState\":\"未确认\",\"hmainid\":29,\"hdate\":\"2019-12-20\",\"hjhdate\":\"2019-12-20\",\"hbillno\":\"CGYH000000000072\",\"hbilltype\":\"1114\",\"hsupid\":2214,\"supHNumber\":\"01.001\",\"supHName\":\"戴尔(中国)有限公司\",\"hcurid\":0,\"curhnumber\":\"*\",\"curhname\":\"*\",\"hexrate\":0,\"HMTONO\":\"\",\"HEmpID\":0,\"hywnumber\":null,\"hywname\":null,\"hmanagerid\":0,\"hmanagerNumber\":null,\"hmanagerName\":null,\"HDeptID\":0,\"HDepNumber\":null,\"HDepName\":null,\"hexplanation\":\"\",\"hremark\":\"\",\"hinnerbillno\":\"\",\"hmaker\":\"admin\",\"hmakedate\":\"2019-12-20\",\"hchecker\":\"admin\",\"hcheckdate\":\"2019-12-20\",\"hupdater\":\"\",\"hupdatedate\":null,\"hcloseman\":\"\",\"hclosedate\":null,\"hdeleteman\":\"\",\"hdeletedate\":null,\"hsubid\":1,\"hmaterid\":178070,\"hmaterNumber\":\"CS0001\",\"hmaterName\":\"塑料ABS\",\"hmaterModel\":\"黑色麻面铁皮\",\"hunitid\":2635,\"hunitNumber\":\"03\",\"hunitName\":\"kg\",\"HQty\":300,\"hprice\":0,\"hmoney\":0,\"HTaxPrice\":0,\"hEcloseman\":\"\",\"hclosetype\":false,\"hEremark\":\"\",\"HSourceInterID\":230087,\"HSourceEntryID\":1,\"HSourceBillNo\":\"POORD177806\",\"HSourceBillType\":\"71\",\"HPOOrderInterID\":230087,\"HPOOrderEntryID\":1,\"HPOOrderBillNo\":\"POORD177806\",\"sumQty\":0,\"HWsumQty\":300}"; //JObject job = JObject.Parse(Json); // string json = "[{\"HInterID\":0,\"HEntryID\":0,\"HSourceInterID\":2213,\"HDate\":\"2017-12-12\",\"HSourceEntryID\":5,\"HRemark\":\"打草机HLT4027(56003871)\",\"HSourceBillNo\":\"NBA222\",\"SourceBillType\":\"\",\"HQty\":0,\"HPrice\":20,\"HMoney\":30,\"HPOOrderBillNo\":\"JJJJJ\"}]"; string json = "{\"HBillNo\":\"DD180730\",\"HDate\":\"2019-11-22T00:00:00\",\"HManagerName\":\"\",\"HManagerID\":\"0\",\"HSupName\":\"\",\"HSupID\":\"1034\",\"HRemark\":\"\",\"HEmpName\":\"\",\"HEmpID\":\"0\",\"HMakerDate\":\"\",\"HMaker\":\"毛映映\",\"HCheckDate\":\"2019-11-22T14:06:57\",\"HChecker\":\"毛映映\",\"HInterID\":\"55\"}"; // SaverPOInStock(json,json);//GetPOInStockShowBillSub SaverPOInStock(json); // web2.GetPOInStockShowBillSub("28", "28,5;"); //if (job["hbillno"].ToString() == "CGYH000000000072") //{ // MessageBox.Show(job["hbillno"].ToString()); //} //MessageBox.Show("没取到!"); // web.GetUser(Convert.ToInt64(txtTest.Text)); // web.GetUser(); } public object SaverPOInStock(string msg) { //var _value = msg["msg"].ToString(); //string msg1 = _value.ToString(); //string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); //string msg2 = sArray[0].ToString(); //string msg3 = sArray[1].ToString(); //HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context //HttpRequestBase request = context.Request;//定义传统request对象 //string callback = request.Form["callback"]; //using (StreamWriter sw = new StreamWriter(@"D:\log.txt")) //{ // sw.Write("callback:" + callback); //} ListModels oListModels = new ListModels(); try { DAL.ClsCg_POInStockBill oBill = new DAL.ClsCg_POInStockBill(); // TestDAL oBill = new TestDAL(); List lsmain = new List(); //msg2 = msg2.Substring(1, msg2.Length - 2); msg = msg.Replace("\\", ""); msg = msg.Replace("\n", ""); //\n lsmain = oListModels.getMainObjectByJson2(msg); foreach (Model.ClsCg_POInStockBillMain oItem in lsmain) { oItem.HMaker = GetSession(""); oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year); oItem.HDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd")); oItem.HCurID = 1; oItem.HMainSourceInterID = oItem.HInterID; oItem.HInterID = DBUtility.ClsPub.CreateBillID("1103", ref DBUtility.ClsPub.sExeReturnInfo); oBill.omodel = oItem; } // msg2= "[{\"HMaterID\":70952,\"HMaterNumber\":\"3.02.DT127.006\",\"HMaterName\":\"白板面板\",\"HMaterModel\":\"黑色麻面铁皮 412 * 412 * 0.21mm 1出1 468U00 - 04\n\",\"HUnitID\":249,\"HUnitName\":\"PCS\",\"HQty\":2268,\"HPrice\":0,\"HMoney\":0,\"HDate\":\"2019 / 12 / 18 0:00:00\",\"HDate2\":\"2019 / 12 / 20 8:30:22\",\"HSourceInterID\":819,\"HSourceEntryID\":4,\"HSourceBillNo\":\"CGPG000000000973\",\"HSourceBillType\":\"1114\",\"HPOOrderBillNo\":\"POORD047421\",\"HPOOrderInterID\":49365,\"HPOOrderEntryID\":5,\"HMTONO\":\"G19 - 339 - 05\"}]"; //表体数据 //按 },{来拆分数组 //去掉【和】 // msg3 = msg3.Substring(1, msg3.Length - 2); //msg3 = msg3.Replace("\\", ""); //msg3 = msg3.Replace("\n", ""); //\n //msg2 = msg2.Replace("'", "’"); List ls = new List(); ls = oListModels.getObjectByJson2(msg); int i = 1; foreach (Model.ClsCg_POInStockBillSub oItemSub in ls) { oItemSub.HEntryID = i; oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now); oItemSub.HCloseType = false; oBill.DetailColl.Add(oItemSub); i++; } //保存前判断(单据号重复,笔录项目) //保存 //保存完毕后处理 bool bResult; if (oBill.omodel.HInterID != 0) { // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); } else { bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo); } if (bResult) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "保存成功!"; objJsonResult.data = 1; return objJsonResult; } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!"; objJsonResult.data = 1; return objJsonResult; } } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!" + e.ToString(); objJsonResult.data = 1; return objJsonResult; } } } }