Form2.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using JLHHJSvr.Com.Model;
  2. using LJLib.Tools.File;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data.SqlClient;
  6. using System.Linq;
  7. using System.Windows.Forms;
  8. using JLHHJSvr.Com;
  9. using JLHHJSvr.LJFramework.Tools;
  10. using LJLib.DAL.SQL;
  11. using Newtonsoft.Json.Linq;
  12. using DirectService.Tools;
  13. namespace JLHHJSvr
  14. {
  15. public partial class Form2 : Form
  16. {
  17. public Form2()
  18. {
  19. InitializeComponent();
  20. }
  21. private void button1_Click(object sender, EventArgs e)
  22. {
  23. if (string.IsNullOrEmpty(textBox1.Text))
  24. {
  25. MessageBox.Show("请输入内容");
  26. return;
  27. }
  28. try
  29. {
  30. XmlConfig xmlconfig = new XmlConfig();
  31. string connectionString = xmlconfig.GetXmlFileValue(GlobalVar.XmlFile, string.Empty, "ConnectionString", string.Empty);
  32. using (var con = new SqlConnection(connectionString))
  33. using (var cmd = con.CreateCommand())
  34. {
  35. con.Open();
  36. var url = textBox4.Text;
  37. var loginReq = new LoginRequest()
  38. {
  39. usercode = textBox2.Text,
  40. psw = textBox3.Text,
  41. };
  42. var loginRsp = LJHttpUtil.PostRequest(url + loginReq.GetApiName(), JObject.FromObject(loginReq))
  43. .ToObject<LoginResponse>();
  44. if (!string.IsNullOrEmpty(loginRsp.ErrMsg))
  45. {
  46. MessageBox.Show("登录失败:" + loginRsp.ErrMsg);
  47. return;
  48. }
  49. var token = loginRsp.token;
  50. var list = new List<u_mattress>();
  51. var textStr = textBox1.Text.Replace(",", ",");
  52. var whereStr = $"mattresscode IN {ListEx.getString(textStr)}";
  53. DbSqlHelper.Select(cmd, list, whereStr, "mattressid,deptid,mattresstypeid,mattress_width,mattress_length,mattress_height,packtype,packqty,woodpallettype,total_hr_cost,total_material_cost,fees_dscrp,total_fees_cost,total_cost,taxrate,taxes,commissionrate,commission,fob,profitrate,createtime,createby,extras_cost,dept_profitrate,moneyrate,nottax_factory_cost,nottax_dept_cost,dept_cost,foreign_cost,mattresscode,mattressname,diameter,area,cabinet_type,loading_type,hrcost,biandaicost,fob_replace_formula,hrcost_replace_formula,biandaicost_replace_formula,mattressrelcode,other_rate,gydscrp,flag,dept_profitrate_rangli,auditingrep,auditingdate,profitrate_point,if_moneyrate,discount,if_discount,erp_mtrlid,erp_configcodetype,erp_mtrlcode,erp_mtrlname,erp_mtrlmode,erp_mtrltypeid,erp_mtrltype,erp_mtrlunit,erp_mtrlengname,erp_piccode,yw_flag,yw_auditingrep,yw_auditingdate,js1_flag,js1_auditingrep,js1_auditingdate,js2_flag,js2_auditingrep,js2_auditingdate,creatmtrl_flag,creatmtrl_auditingrep,creatmtrl_auditingdate,creatmtrlqd_flag,creatmtrlqd_auditingrep,creatmtrlqd_auditingdate,if_m_chai,if_z_chai,if_d_chai,if_n_butao,if_w_butao,if_m_wbutao_way,if_db_wbutao_way,s_cover_qty,z_cover_qty,x_cover_qty,biandai_qty,s_m_cover_qty,z_m_cover_qty,x_m_cover_qty,butao_point,chaizhuang_point,if_haimian_type,haimian_point,if_zhedie_type,old_mtrlname,xd_flag,xd_auditingrep,xd_auditingdate,qr_flag,qr_auditingrep,qr_auditingdate,temp_code,erp_cb_updatetime,bcptypeid,if_bcp_type,bcp_m_id,bcp_m_name,bcp_d_id,bcp_d_name,bcp_dc_id,bcp_dc_name,bcp_xc_id,bcp_xc_name,bcp_vc_id,bcp_vc_name,bcp_cw_id,bcp_cw_name,zhizao_amt,guanli_rate,dannum_rate,cubage,foreign_cost_bz,foreign_cost_dd,parentid,dannum_type");
  54. var idList = textStr.Split(',').Select(x => x.Trim());
  55. var failIDs = new HashSet<string>(idList);
  56. var okIDs = new HashSet<string>();
  57. var errMsg = string.Empty;
  58. foreach (var mattress in list)
  59. {
  60. var id = mattress.mattressid;
  61. try
  62. {
  63. mattress.mattressid = 0;
  64. var mxList = new List<u_mattress_mx_mtrl>();
  65. whereStr = $"mattressid = {id}";
  66. DbSqlHelper.Select(cmd, mxList, whereStr, "mattressmxid,formulaid,formula,mtrlid,price,gram_weight,cloth_width,if_inputqty,qty,costamt,if_15strip,if_success,shrinkage,replace_formula,priceunit,if_areaprice,thickness,chastr,dv_dscrp,xu,useqty,useformula,replace_useformula,gydscrp,cw_erpmtrlcode,erp_mtrlid,mattress_width,mattress_length");
  67. var saveReq = new SaveMattressRequest()
  68. {
  69. mattress = mattress,
  70. mattressMx = mxList,
  71. token = token,
  72. };
  73. var saveRsp = LJHttpUtil.PostRequest(url + saveReq.GetApiName(), JObject.FromObject(saveReq))
  74. .ToObject<SaveMattressResponse>();
  75. if (!string.IsNullOrEmpty(saveRsp.ErrMsg))
  76. {
  77. errMsg += $"{id}: {saveRsp.ErrMsg}\r\n";
  78. }
  79. else
  80. {
  81. okIDs.Add(mattress.mattresscode);
  82. failIDs.Remove(mattress.mattresscode);
  83. }
  84. }
  85. catch (Exception ex)
  86. {
  87. errMsg += $"{id}: {ex}\r\n";
  88. }
  89. }
  90. textBox1.Text = $"同步失败:{string.Join(",", failIDs)}\r\n同步成功:{string.Join(",", okIDs)}\r\n{errMsg}";
  91. }
  92. }
  93. catch (Exception ex)
  94. {
  95. MessageBox.Show(ex.ToString());
  96. }
  97. }
  98. }
  99. }