private void SyncTglTerima(int wiserid) { string host = "http://devwiserdc.sas-autoparts.com:8000"; using (var db = new Database()) { db.Commands.Add(db.CreateCommand("[usp_AppSetting_LIST]")); db.Commands[0].Parameters.Add(new Parameter("@Key", SqlDbType.VarChar, "WiserDC_Host")); DataTable dtbl = db.Commands[0].ExecuteDataTable(); if (dtbl.Rows.Count > 0) { host = dtbl.Rows[0]["Value"].ToString(); } else { throw new Exception("Wiser belum di setting"); } } JSON opt = new JSON(JSONType.Object); opt.ObjAdd("id", new JSON(wiserid)); string errm = ""; XNet xn = new XNet(host + "/api/antargudang/synchtglterima", XNetMethod.GET); XNetThread xnt = xn.Get(opt, r => { if (r.Error != null) { errm = r.Error.Message; } else if (r.Output.Length > 0) { JSON jres = JSON.Parse(r.Output); if (jres.Type == JSONType.Object) { if (jres.ObjExists("Result") && jres["Result"].BoolValue) { errm = ""; } else if (jres.ObjExists("Msg")) { errm = jres["Msg"].StringValue; } else { errm = "Marking to server failed"; } return; } } errm = "Marking to server failed"; }); if (errm.Length > 0) { MessageBox.Show("Server message:\n" + errm); } }
static void Main(string[] args) { #region 与通信服务建立tcp连接 CommTcp commTcp = new CommTcp("127.0.0.1", 2323);//1.连接服务exe try { commTcp.Connect(); } catch (XNetException ex) { Console.WriteLine(ex.Message); return; } #endregion #region 配置通信参数 XNetConnectParams XNetParams = new XNetConnectParams("192.168.6.6", DeviceType.XDPLC); //2.指定设备地址 XNet xnet = new XNet(XNetParams, commTcp); //3.构造信捷协议栈 #endregion #region 通信 XNetComm hComm = new XNetComm(xnet);//4.构造通信句柄 //读10个寄存器 try { short[] readRegs = new short[10]; //10个 hComm.Read(PLCRegType.D, 1000, readRegs); //从D1000位置开始读10个寄存器,存入readRegs } catch (XNetException ex) { Console.WriteLine(ex.Message);//读取失败的错误信息 return; } //写10个寄存器 try { short[] writeRegs = new short[10]; //10个 hComm.Write(PLCRegType.D, 1000, writeRegs); //从D1000位置开始写10个寄存器,把writeRegs写入 } catch (XNetException ex) { Console.WriteLine(ex.Message); return; } #endregion Console.WriteLine("成功"); Console.ReadLine(); }
static void Main(string[] args) { string err; #region 查找设备 XNet xnet = XNet.FindLocalDevice("127.0.0.1", 2323, DeviceType.XDPLC, out err);//对电脑的所有(USB/串口)端口进行查找XDPLC if (xnet == null) { return;//查找失败 } #endregion #region 通信 XNetComm hComm = new XNetComm(xnet);//4.构造通信句柄 //读10个寄存器 short[] readRegs = new short[10];//10个 try { hComm.Read(PLCRegType.D, 0, readRegs);//从D1000位置开始读10个寄存器,存入readRegs } catch (XNetException ex) { Console.WriteLine(ex.Message);//读取失败的错误信息 return; } //写10个寄存器 short[] writeRegs = new short[10];//10个 try { hComm.Write(PLCRegType.D, 1000, writeRegs);//从D1000位置开始写10个寄存器,把writeRegs写入 } catch (XNetException ex) { Console.WriteLine(ex.Message); return; } #endregion Console.WriteLine("成功"); Console.ReadLine(); }
private void ImportData(int[] ids) { Form thisx = this; if (ipProgress == null) { ipProgress = new InPopup(this, pnlProgress); } if (fpProgress == null) { fpProgress = new FakeProgress(progbProgress); } BackgroundWorker bgw = new BackgroundWorker(); bgw.DoWork += (a, b) => { fpProgress.Start(); using (var db = new Database()) { if (bgw.CancellationPending) { return; } db.Commands.Add(db.CreateCommand("[usp_AppSetting_LIST]")); db.Commands[0].Parameters.Add(new Parameter("@Key", SqlDbType.VarChar, "WiserDC_Host")); DataTable dtbl2 = db.Commands[0].ExecuteDataTable(); string host = "http://devwiserdc.sas-autoparts.com:8000"; if (dtbl2.Rows.Count > 0) { host = dtbl2.Rows[0]["Value"].ToString(); } else { MessageBox.Show("Download gagal, Wiser belum di setting"); return; } Guid _headerRowID, _detailID; List <int> scs = new List <int>(); foreach (int i in ids) { JSON cur = mdat[i.ToString()]; List <Parameter> cmdl = new List <Parameter>(); db.Commands.Clear(); //DateTime tTerima = DateTime.ParseExact(cur["TglTerima"].StringValue, "yyyy-MM-dd", CultureInfo.InvariantCulture); //MessageBox.Show(cur["NotaRowID"].GuidValue(DBNull.Value).ToString()); //return; generateNoKoreksi(); _headerRowID = Guid.NewGuid(); cmdl.Add(new Parameter("@RowID", SqlDbType.UniqueIdentifier, _headerRowID)); cmdl.Add(new Parameter("@RecordID", SqlDbType.VarChar, FingerPrintWiser(cur["wiserid"].StringValue))); cmdl.Add(new Parameter("@NotaJualDetailWiserID", SqlDbType.Int, cur["NotaJualDetailWiserID"].NumberValue)); cmdl.Add(new Parameter("@TglKoreksi", SqlDbType.DateTime, cur["TglKoreksi"].DateTimeValue(DBNull.Value))); cmdl.Add(new Parameter("@NoKoreksi", SqlDbType.VarChar, strNoKoreksi)); cmdl.Add(new Parameter("@BarangID", SqlDbType.VarChar, cur["BarangID"].StringValue)); cmdl.Add(new Parameter("@QtyNotaBaru", SqlDbType.Int, cur["QtyNotaBaru"].NumberValue)); cmdl.Add(new Parameter("@HrgJualBaru", SqlDbType.Money, cur["HrgJualBaru"].NumberValue)); cmdl.Add(new Parameter("@Catatan", SqlDbType.VarChar, cur["Catatan"].StringValue)); cmdl.Add(new Parameter("@KodeToko", SqlDbType.VarChar, cur["KodeToko"].StringValue)); cmdl.Add(new Parameter("@Sumber", SqlDbType.VarChar, cur["Sumber"].StringValue)); cmdl.Add(new Parameter("@HrgJualKoreksi", SqlDbType.Int, cur["HrgJualKoreksi"].NumberValue)); cmdl.Add(new Parameter("@QtyNotaKoreksi", SqlDbType.Int, cur["QtyNotaKoreksi"].NumberValue)); cmdl.Add(new Parameter("@SyncFlag", SqlDbType.Bit, 0)); //cmdl.Add(new Parameter("@LinkID", SqlDbType.VarChar, "")); cmdl.Add(new Parameter("@LastUpdatedBy", SqlDbType.VarChar, cur["LastUpdatedBy"].StringValue)); cmdl.Add(new Parameter("@wiserid", SqlDbType.Int, cur["wiserid"].NumberValue)); cmdl.Add(new Parameter("@WiserTag", SqlDbType.VarChar, "WISERDC")); try { db.Commands.Clear(); db.Commands.Add(db.CreateCommand("usp_KoreksiPenjualan_WISERDC_SET")); db.Commands[0].Parameters = cmdl; db.Commands[0].ExecuteNonQuery(); db.Commands.Add(db.CreateCommand("usp_Numerator_UPDATE")); db.Commands[1].Parameters.Add(new Parameter("@doc", SqlDbType.VarChar, docNoKoreksi)); db.Commands[1].Parameters.Add(new Parameter("@depan", SqlDbType.VarChar, depan)); db.Commands[1].Parameters.Add(new Parameter("@belakang", SqlDbType.VarChar, belakang)); db.Commands[1].Parameters.Add(new Parameter("@nomor", SqlDbType.Int, iNomor)); db.Commands[1].Parameters.Add(new Parameter("@lebar", SqlDbType.VarChar, lebar)); db.Commands[1].Parameters.Add(new Parameter("@lastUpdatedBy", SqlDbType.VarChar, SecurityManager.UserID)); db.Commands[1].ExecuteNonQuery(); scs.Add((int)cur["wiserid"].NumberValue); } catch (Exception ex) { MessageBox.Show("Error: " + ex); } } if (scs.Count > 0) { MessageBox.Show("DATA BERHASIL DITAMBAHKAN"); } else { MessageBox.Show("Synch gagal"); } if (scs.Count > 0) { if (!hasSynch) { hasSynch = true; } MarkAsSuccess(scs.ToArray()); JSON opt = new JSON(JSONType.Object); JSON lst = new JSON(JSONType.Array); foreach (int ix in scs) { lst.ArrAdd(new JSON(ix)); } opt.ObjAdd("mark", new JSON(true)); opt.ObjAdd("ids", lst); string errm = ""; XNet xn = new XNet(host + "/api/koreksipenjualan/synch", XNetMethod.GET); XNetThread xnt = xn.Send(opt, r => { if (r.Error != null) { errm = r.Error.Message; } else if (r.Output.Length > 0) { JSON jres = JSON.Parse(r.Output); if (jres.Type == JSONType.Object) { if (jres.ObjExists("Result") && jres["Result"].BoolValue) { errm = ""; } else if (jres.ObjExists("Msg")) { errm = jres["Msg"].StringValue; } else { errm = "Marking to server failed"; } return; } } errm = "Marking to server failed"; }); if (errm.Length > 0) { MessageBox.Show("Server message:\n" + errm); } } else { MessageBox.Show("Synch gagal"); } b.Result = true; return; } if (b.Result != null && !b.Result.Equals(true)) { MessageBox.Show(b.Result.ToString()); return; } }; bgw.RunWorkerCompleted += (a, b) => { bool r = false; if (b.Cancelled) { MessageBox.Show(thisx, "Operasi di gagalkan"); } else if (b.Error != null) { MessageBox.Show(thisx, b.Error.Message); } else { r = true; } ipProgress.Close(r); this.Close(); }; ipProgress.OpenDialog(this, a => { }, () => bgw.CancelAsync()); bgw.RunWorkerAsync(); }
private void GetData() { Form thisx = this; if (ipProgress == null) { ipProgress = new InPopup(this, pnlProgress); } if (fpProgress == null) { fpProgress = new FakeProgress(progbProgress); } BackgroundWorker bgw = new BackgroundWorker(); bgw.DoWork += (a, b) => { fpProgress.Start(); JSON opt = new JSON(JSONType.Object); opt.ObjAdd("gudang", new JSON(InitGudang)); opt.ObjAdd("fromdate", new JSON(rangeDateBox1.FromDate.Value.ToString("yyyy-MM-dd"))); opt.ObjAdd("todate", new JSON(rangeDateBox1.ToDate.Value.ToString("yyyy-MM-dd"))); string host = "http://devwiserdc.sas-autoparts.com:8000"; using (var db = new Database()) { db.Commands.Add(db.CreateCommand("[usp_AppSetting_LIST]")); db.Commands[0].Parameters.Add(new Parameter("@Key", SqlDbType.VarChar, "WiserDC_Host")); DataTable dtbl = db.Commands[0].ExecuteDataTable(); if (dtbl.Rows.Count > 0) { host = dtbl.Rows[0]["Value"].ToString(); } else { MessageBox.Show("Wiser belum di setting"); return; } } XNet xn = new XNet(host + "/api/koreksipenjualan/get", XNetMethod.GET); //XNet xn = new XNet("https://postman-echo.com/get", XNetMethod.GET); XNetThread xnt = xn.Send(opt, c => { if (bgw.CancellationPending) { return; } ///return; try { if (c.Error != null) { throw new Exception("Terjadi error: " + c.Error.Message); } else if (c.Output.Length > 0) { JSON jdat = JSON.Parse(c.Output); if (jdat.Type == JSONType.Object) { if (jdat.ObjExists("Result") && jdat["Result"].BoolValue) { if (jdat.ObjExists("Data")) { DataTable dtbl0 = new DataTable(); DataTable dtbl1 = new DataTable(); //return; dtbl0.Columns.Add("check"); foreach (string k in jdat["Data"].ObjKeys) { JSON cur = jdat["Data"][k]; List <object> itm = new List <object>(); itm.Add(true); foreach (string k2 in cur.ObjKeys) { switch (k2) { case "Details": // do nothing break; default: if (dtbl0.Rows.Count <= 0) { dtbl0.Columns.Add(k2); } itm.Add(cur[k2].Value); break; } } dtbl0.Rows.Add(itm.ToArray()); } dset = new DataSet(); mdat = jdat["Data"]; dset.Tables.Add(dtbl0); GVHeader.Invoke(new Action(() => GVHeader.DataSource = dset.Tables[0])); b.Result = true; return; } throw new Exception("Response server is not expected"); } else { if (jdat.ObjExists("Msg")) { throw new Exception("Server error: " + jdat["Msg"]); } else { throw new Exception(jdat.ToString()); } } } else { throw new Exception(c.Output); } } else { throw new Exception("Tidak ada response dari server"); } } catch (Exception ex) { b.Result = ex.Message; } }); while (xnt.OnWorking) { if (bgw.CancellationPending) { b.Cancel = true; xnt.Cancel(); break; } } ; if (b.Result != null && !b.Result.Equals(true)) { MessageBox.Show(b.Result.ToString()); return; } //throw new Exception(b.Result.ToString()); }; bgw.RunWorkerCompleted += (a, b) => { bool r = false; if (b.Cancelled) { MessageBox.Show(thisx, "Operasi di gagalkan"); } else if (b.Error != null) { MessageBox.Show(thisx, b.Error.Message); } else { r = true; } ipProgress.Close(r); }; ipProgress.OpenDialog(this, a => { }, () => bgw.CancelAsync()); bgw.RunWorkerAsync(); }
static void Main(string[] args) { #region 与通信服务建立tcp连接 CommTcp commTcp = new CommTcp("127.0.0.1", 2323);//1.连接到服务 X_Net_Windows.exe try { commTcp.Connect(); } catch (XNetException ex) { Console.WriteLine("连接服务失败" + ex.Message); return; } #endregion #region 配置通信参数 //设备ID,安全模式,PLC密码,用户名,密码(目前,安全模式为1,用户名密码都为“”空) XNetConnectRemoteParams xnetRemoteParams = new XNetConnectRemoteParams("020001003b0f00004", 1, "12345678", "", ""); //远程通信的通信端口为240 XNetConnectParams XNetParams = new XNetConnectParams(240, DeviceType.GBOX_4G, null, xnetRemoteParams);//查找4GBox_M而不是PLC XNet xnet = new XNet(XNetParams, commTcp); #endregion #region 建立远程连接 try { xnet.Connect_RemoteDevice(); } catch (XNetException ex) { Console.WriteLine("建立远程连接失败:" + ex.Message); return; } #endregion #region 查找设备 try { xnet.Connect_Find_Device();//查找设备 } catch (XNetException ex) { Console.WriteLine(ex.Message); return; } #endregion #region 通信 XNetComm hComm = new XNetComm(xnet); XNetComm_XC h_XCComm = new XNetComm_XC(hComm);//构造XC的通信句柄 //读10个寄存器 short[] readRegs = new short[10];//10个 try { h_XCComm.Read(XCPLCRegType.D, 1000, readRegs);//从D1000位置开始读10个寄存器,存入readRegs } catch (XNetException ex) { Console.WriteLine(ex.Message);//读取失败的错误信息 return; } //写10个寄存器 short[] writeRegs = new short[10];//10个 try { h_XCComm.Write(XCPLCRegType.D, 2000, writeRegs);//从D2000位置开始写10个寄存器,把writeRegs写入 } catch (XNetException ex) { Console.WriteLine(ex.Message); return; } #endregion Console.WriteLine("成功"); Console.ReadLine(); }
private void ImportData(int[] ids) { using (var db = new Database()) { db.Commands.Add(db.CreateCommand("[usp_AppSetting_LIST]")); db.Commands[0].Parameters.Add(new Parameter("@Key", SqlDbType.VarChar, "WiserDC_Host")); DataTable dtbl2 = db.Commands[0].ExecuteDataTable(); string host = "http://devwiserdc.sas-autoparts.com:8000"; if (dtbl2.Rows.Count > 0) { host = dtbl2.Rows[0]["Value"].ToString(); } else { MessageBox.Show("Download gagal, Wiser belum di setting"); return; } Guid HeaderID, DetailID; List <int> scs = new List <int>(); foreach (int i in ids) { JSON cur = mdat[i.ToString()]; List <Parameter> cmdl = new List <Parameter>(); db.Commands.Clear(); if (cur["isarowid"].GuidValue(DBNull.Value) == DBNull.Value) { HeaderID = Guid.NewGuid(); } else { HeaderID = (Guid)cur["isarowid"].GuidValue(DBNull.Value); } cmdl.Add(new Parameter("@RowID", SqlDbType.UniqueIdentifier, HeaderID)); cmdl.Add(new Parameter("@RecordID", SqlDbType.VarChar, FingerPrintWiser(cur["wiserid"].StringValue))); cmdl.Add(new Parameter("@DrGudang", SqlDbType.VarChar, cur["DrGudang"].StringValue)); cmdl.Add(new Parameter("@KeGudang", SqlDbType.VarChar, cur["KeGudang"].StringValue)); cmdl.Add(new Parameter("@TglKirim", SqlDbType.DateTime, cur["TglKirim"].DateTimeValue(DBNull.Value))); cmdl.Add(new Parameter("@TglTerima", SqlDbType.DateTime, cur["TglTerima"].DateTimeValue(DBNull.Value))); cmdl.Add(new Parameter("@NoAG", SqlDbType.VarChar, cur["NoAG"].StringValue)); cmdl.Add(new Parameter("@Pengirim", SqlDbType.VarChar, cur["Pengirim"].StringValue)); cmdl.Add(new Parameter("@Penerima", SqlDbType.VarChar, cur["Penerima"].StringValue)); cmdl.Add(new Parameter("@DrCheck1", SqlDbType.VarChar, cur["DrCheck1"].StringValue)); cmdl.Add(new Parameter("@DrCheck2", SqlDbType.VarChar, cur["DrCheck2"].StringValue)); cmdl.Add(new Parameter("@KeCheck1", SqlDbType.VarChar, cur["KeCheck1"].StringValue)); cmdl.Add(new Parameter("@KeCheck2", SqlDbType.VarChar, cur["KeCheck2"].StringValue)); cmdl.Add(new Parameter("@Catatan", SqlDbType.VarChar, cur["Catatan"].StringValue)); cmdl.Add(new Parameter("@expedisi", SqlDbType.VarChar, cur["Expedisi"].StringValue)); cmdl.Add(new Parameter("@NoKendaraan", SqlDbType.VarChar, cur["NoKendaraan"].StringValue)); cmdl.Add(new Parameter("@NamaSopir", SqlDbType.VarChar, cur["NamaSopir"].StringValue)); cmdl.Add(new Parameter("@LastUpdatedBy", SqlDbType.VarChar, cur["LastUpdatedBy"].StringValue)); cmdl.Add(new Parameter("@wiserid", SqlDbType.Int, cur["wiserid"].NumberValue)); cmdl.Add(new Parameter("@WiserTag", SqlDbType.VarChar, "WISERDC")); try { db.Commands.Clear(); db.Commands.Add(db.CreateCommand("[usp_AntarGudang_WISERDC_SET]")); db.Commands[0].Parameters = cmdl; DataTable dtbl = db.Commands[0].ExecuteDataTable(); if (dtbl.Rows.Count > 0) { if (dtbl.Rows[0]["Result"].ToString() == "1") { Guid id = (Guid)dtbl.Rows[0]["RowID"]; int cid = 0; bool itOk = true; bool itTrasaction = false; try { db.Commands.Clear(); foreach (string ck in cur["Details"].ObjKeys) { /* * * "wiserid" => $row2->id, * "KodeBarang" => $row2->barang->kodebarang, * "QtyKirim" => $row2->qtynotaag, * "QtyTerima" => 0, * "Catatan" => $row2->catatan, * "Ongkos" => null, * "SyncFlag" => 1, * "QtyDO" => $row2->qtyrqag, * "isarowid" => $row2->isarowid, * "LastUpdatedBy" => $tmp["LastUpdatedBy"], * "LastUpdatedTime" => $tmp["LastUpdatedTime"], * "HrgBeli" => 0 */ JSON curd = cur["Details"][ck]; if (curd["isarowid"].GuidValue(DBNull.Value) == DBNull.Value) { DetailID = Guid.NewGuid(); } else { DetailID = (Guid)curd["isarowid"].GuidValue(DBNull.Value); } cmdl = new List <Parameter>(); cmdl.Add(new Parameter("@RowID", SqlDbType.UniqueIdentifier, DetailID)); cmdl.Add(new Parameter("@HeaderID", SqlDbType.UniqueIdentifier, id)); cmdl.Add(new Parameter("@RecordID", SqlDbType.VarChar, FingerPrintWiser(curd["wiserid"].StringValue))); cmdl.Add(new Parameter("@TransactionID", SqlDbType.VarChar, FingerPrintWiser(curd["wiserid"].StringValue))); cmdl.Add(new Parameter("@KodeBarang", SqlDbType.VarChar, curd["KodeBarang"].StringValue)); cmdl.Add(new Parameter("@QtyKirim", SqlDbType.Int, curd["QtyKirim"].NumberValue)); cmdl.Add(new Parameter("@QtyTerima", SqlDbType.Int, curd["QtyTerima"].NumberValue)); cmdl.Add(new Parameter("@QtyDO", SqlDbType.Int, curd["QtyDO"].NumberValue)); cmdl.Add(new Parameter("@Ongkos", SqlDbType.Money, curd["Ongkos"].NumberValue)); cmdl.Add(new Parameter("@HrgBeli", SqlDbType.Money, curd["HrgBeli"].NumberValue)); cmdl.Add(new Parameter("@Catatan", SqlDbType.VarChar, curd["Catatan"].StringValue)); cmdl.Add(new Parameter("@SyncFlag", SqlDbType.Bit, 0)); cmdl.Add(new Parameter("@LastUpdatedBy", SqlDbType.VarChar, curd["LastUpdatedBy"].StringValue)); cmdl.Add(new Parameter("@WiserID", SqlDbType.Int, curd["wiserid"].NumberValue)); cmdl.Add(new Parameter("@WiserHeaderID", SqlDbType.Int, curd["wiserheaderid"].NumberValue)); cmdl.Add(new Parameter("@WiserTag", SqlDbType.VarChar, "WISERDC")); db.Commands.Add(db.CreateCommand("[usp_AntarGudangDetail_WISERDC_SET]")); db.Commands[cid].Parameters = cmdl; cid += 1; } itTrasaction = true; db.BeginTransaction(); foreach (Command cmd in db.Commands) { try { cmd.ExecuteNonQuery(); } catch (Exception ex) { Error.LogError(ex); if (itTrasaction) { db.RollbackTransaction(); } itOk = false; break; } } } catch (Exception) { itOk = false; } if (itOk) { if (itTrasaction) { db.CommitTransaction(); } scs.Add((int)cur["wiserid"].NumberValue); } else { try { db.Commands.Clear(); db.Commands.Add(db.CreateCommand("[usp_AntarGudang_WISERDC_DELETE]")); db.Commands[0].Parameters.Add(new Parameter("@RowID", SqlDbType.UniqueIdentifier, id)); db.Commands[0].Parameters.Add(new Parameter("@WiserID", SqlDbType.Int, cur["wiserid"].NumberValue)); db.Commands[0].ExecuteNonQuery(); } catch (Exception) { } } } } } catch (Exception ex) { MessageBox.Show("Error: " + ex); } } if (scs.Count > 0) { if (!hasSynch) { hasSynch = true; } MarkAsSuccess(scs.ToArray()); JSON opt = new JSON(JSONType.Object); JSON lst = new JSON(JSONType.Array); foreach (int ix in scs) { lst.ArrAdd(new JSON(ix)); } opt.ObjAdd("mark", new JSON(true)); opt.ObjAdd("ids", lst); string errm = ""; XNet xn = new XNet(host + "/api/antargudang/synch", XNetMethod.GET); XNetThread xnt = xn.Get(opt, r => { if (r.Error != null) { errm = r.Error.Message; } else if (r.Output.Length > 0) { JSON jres = JSON.Parse(r.Output); if (jres.Type == JSONType.Object) { if (jres.ObjExists("Result") && jres["Result"].BoolValue) { errm = ""; } else if (jres.ObjExists("Msg")) { errm = jres["Msg"].StringValue; } else { errm = "Marking to server failed"; } return; } } errm = "Marking to server failed"; }); if (errm.Length > 0) { MessageBox.Show("Server message:\n" + errm); } if (scs.Count == mdat.Count) { this.Close(); } } else { MessageBox.Show("Synch gagal"); } } }
private void SetupRemoteLinkBtn_Click(object sender, EventArgs e) { #region 与通信服务建立tcp连接 commTcp = new CommTcp("127.0.0.1", 2323);//1.连接到服务 X_Net_Windows.exe try { commTcp.Connect(); } catch (XNetException ex) { MessageBox.Show("连接服务失败" + ex.Message); return; } #endregion #region 配置通信参数 //设备ID,安全模式,PLC密码,用户名,密码(目前,安全模式为1,用户名密码都为“”空) xnetRemoteParams = new XNetConnectRemoteParams(IDBox.Text, 1, PasswordBox.Text, "", ""); DeviceType deviceType; switch (DeviceTypeCB.Text) { case "PLC_XD": deviceType = DeviceType.XDPLC; break; case "GBOX_4G": deviceType = DeviceType.GBOX_4G; break; case "WBOX": deviceType = DeviceType.WBOX; break; default: deviceType = DeviceType.WBOX; break; } //远程通信的通信端口为240,支持各种查找,这里没填ID是类型查找。 XNetParams = new XNetConnectParams(240, deviceType, null, xnetRemoteParams); xnet = new XNet(XNetParams, commTcp); #endregion #region 建立远程连接 try { xnet.Connect_RemoteDevice(); } catch (XNetException ex) { MessageBox.Show("建立远程连接失败:" + ex.Message); return; } #endregion #region 查找设备 try { xnet.Connect_Find_Device();//查找设备 } catch (XNetException ex) { MessageBox.Show(ex.Message); return; } #endregion MessageBox.Show("成功"); }
static void Main(string[] args) { #region 与通信服务建立tcp连接 CommTcp commTcp = new CommTcp("127.0.0.1", 2323);//1.连接到服务 X_Net_Windows.exe try { commTcp.Connect(); } catch (XNetException ex) { Console.WriteLine("连接服务失败" + ex.Message); return; } #endregion #region 配置通信参数 //129为以太网口 不填ID为类型查找 不填远程参数 //XNetConnectParams XNetParams = new XNetConnectParams(129, DeviceType.XDPLC, null, null); //类型查找 XNetConnectParams XNetParams = new XNetConnectParams(129, DeviceType.XDPLC, "00300900170a00002", null); //ID查找 XNet xnet = new XNet(XNetParams, commTcp); #endregion #region 查找设备 try { xnet.Connect_Find_Device();//查找设备 } catch (XNetException ex) { Console.WriteLine(ex.Message); return; } #endregion #region 通信 XNetComm hComm = new XNetComm(xnet);//构造通信句柄 //读10个寄存器 short[] readRegs = new short[10];//10个 try { hComm.Read(PLCRegType.D, 1000, readRegs);//从D1000位置开始读10个寄存器,存入readRegs } catch (XNetException ex) { Console.WriteLine(ex.Message);//读取失败的错误信息 return; } //写10个寄存器 short[] writeRegs = new short[10];//10个 try { hComm.Write(PLCRegType.D, 1000, writeRegs);//从D1000位置开始写10个寄存器,把writeRegs写入 } catch (XNetException ex) { Console.WriteLine(ex.Message); return; } #endregion Console.WriteLine("成功"); Console.ReadLine(); }
private void ImportData(int[] ids) { Form thisx = this; if (ipProgress == null) { ipProgress = new InPopup(this, pnlProgress); } if (fpProgress == null) { fpProgress = new FakeProgress(progbProgress); } BackgroundWorker bgw = new BackgroundWorker(); bgw.DoWork += (a, b) => { fpProgress.Start(); using (var db = new Database()) { if (bgw.CancellationPending) { return; } db.Commands.Add(db.CreateCommand("[usp_AppSetting_LIST]")); db.Commands[0].Parameters.Add(new Parameter("@Key", SqlDbType.VarChar, "WiserDC_Host")); DataTable dtbl2 = db.Commands[0].ExecuteDataTable(); string host = "http://devwiserdc.sas-autoparts.com:8000"; if (dtbl2.Rows.Count > 0) { host = dtbl2.Rows[0]["Value"].ToString(); } else { MessageBox.Show("Download gagal, Wiser belum di setting"); return; } Guid _headerRowID, _detailID; List <int> scs = new List <int>(); foreach (int i in ids) { JSON cur = mdat[i.ToString()]; List <Parameter> cmdl = new List <Parameter>(); db.Commands.Clear(); //DateTime tTerima = DateTime.ParseExact(cur["TglTerima"].StringValue, "yyyy-MM-dd", CultureInfo.InvariantCulture); //MessageBox.Show(cur["NotaRowID"].GuidValue(DBNull.Value).ToString()); //return; if (cur["NotaRowID"].GuidValue(DBNull.Value) == DBNull.Value) { _headerRowID = Guid.NewGuid(); } else { _headerRowID = (Guid)cur["NotaRowID"].GuidValue(DBNull.Value); } cmdl.Add(new Parameter("@RowID", SqlDbType.UniqueIdentifier, _headerRowID)); cmdl.Add(new Parameter("@HtrID", SqlDbType.VarChar, FingerPrintWiser(cur["wiserid"].StringValue))); cmdl.Add(new Parameter("@RecordID", SqlDbType.VarChar, FingerPrintWiser(cur["wiserid"].StringValue))); cmdl.Add(new Parameter("@DOID", SqlDbType.UniqueIdentifier, cur["DOID"].GuidValue(DBNull.Value))); cmdl.Add(new Parameter("@Cabang1", SqlDbType.VarChar, cur["Cabang1"].StringValue)); cmdl.Add(new Parameter("@Cabang2", SqlDbType.VarChar, cur["Cabang2"].StringValue)); cmdl.Add(new Parameter("@Cabang3", SqlDbType.VarChar, cur["Cabang3"].StringValue)); cmdl.Add(new Parameter("@NoNota", SqlDbType.VarChar, cur["NoNota"].StringValue)); cmdl.Add(new Parameter("@TglNota", SqlDbType.DateTime, cur["TglNota"].DateTimeValue(DBNull.Value))); cmdl.Add(new Parameter("@NoSuratJalan", SqlDbType.VarChar, cur["NoSuratJalan"].StringValue)); cmdl.Add(new Parameter("@TglSuratJalan", SqlDbType.DateTime, cur["TglSuratJalan"].DateTimeValue(DBNull.Value))); cmdl.Add(new Parameter("@KodeToko", SqlDbType.VarChar, cur["KodeToko"].StringValue)); cmdl.Add(new Parameter("@KodeSales", SqlDbType.VarChar, cur["KodeSales"].StringValue)); cmdl.Add(new Parameter("@TglTerima", SqlDbType.DateTime, cur["TglTerima"].DateTimeValue(DBNull.Value))); cmdl.Add(new Parameter("@TglSerahTerimaChecker", SqlDbType.DateTime, cur["TglSerahTerimaChecker"].DateTimeValue(DBNull.Value))); cmdl.Add(new Parameter("@TglExpedisi", SqlDbType.DateTime, cur["TglExpedisi"].DateTimeValue(DBNull.Value))); cmdl.Add(new Parameter("@AlamatKirim", SqlDbType.VarChar, cur["AlamatKirim"].StringValue)); cmdl.Add(new Parameter("@Kota", SqlDbType.VarChar, cur["Kota"].StringValue)); cmdl.Add(new Parameter("@isClosed", SqlDbType.Bit, 0)); cmdl.Add(new Parameter("@Catatan1", SqlDbType.VarChar, cur["Catatan1"].StringValue)); cmdl.Add(new Parameter("@Catatan2", SqlDbType.VarChar, cur["Catatan2"].StringValue)); cmdl.Add(new Parameter("@Catatan3", SqlDbType.VarChar, cur["Catatan3"].StringValue)); cmdl.Add(new Parameter("@Catatan4", SqlDbType.VarChar, cur["Catatan4"].StringValue)); cmdl.Add(new Parameter("@Catatan5", SqlDbType.VarChar, cur["Catatan5"].StringValue)); cmdl.Add(new Parameter("@SyncFlag", SqlDbType.Bit, 0)); //cmdl.Add(new Parameter("@LinkID", SqlDbType.VarChar, "")); cmdl.Add(new Parameter("@NPrint", SqlDbType.Int, cur["NPrint"].NumberValue)); cmdl.Add(new Parameter("@TransactionType", SqlDbType.VarChar, cur["TransactionType"].StringValue)); cmdl.Add(new Parameter("@HariKredit", SqlDbType.Int, cur["HariKredit"].NumberValue)); cmdl.Add(new Parameter("@HariKirim", SqlDbType.Int, cur["HariKirim"].NumberValue)); cmdl.Add(new Parameter("@HariSales", SqlDbType.Int, cur["HariSales"].NumberValue)); cmdl.Add(new Parameter("@Checker1", SqlDbType.VarChar, cur["Checker1"].StringValue)); cmdl.Add(new Parameter("@Checker2", SqlDbType.VarChar, cur["Checker2"].StringValue)); cmdl.Add(new Parameter("@LastUpdatedBy", SqlDbType.VarChar, cur["LastUpdatedBy"].StringValue)); DateTime TglSuratJalan = new DateTime(); DateTime.TryParse(cur["TglNota"].DateTimeValue(DBNull.Value).ToString(), out TglSuratJalan); string barcode = cur["NoNota"].StringValue + TglSuratJalan.ToString("yyyy").Substring(1, 3) + TglSuratJalan.ToString("MM"); cmdl.Add(new Parameter("@Barcode", SqlDbType.VarChar, barcode)); cmdl.Add(new Parameter("@WiserTag", SqlDbType.VarChar, "WISERDC")); cmdl.Add(new Parameter("@wiserid", SqlDbType.Int, cur["wiserid"].NumberValue)); try { db.Commands.Clear(); db.Commands.Add(db.CreateCommand("usp_NotaPenjualan_WISERDC_SET")); db.Commands[0].Parameters = cmdl; DataTable dtbl = db.Commands[0].ExecuteDataTable(); if (dtbl.Rows.Count > 0) { if (dtbl.Rows[0]["Result"].ToString() == "1") { Guid id = (Guid)dtbl.Rows[0]["RowID"]; int cid = 0; bool itOk = true; bool itTrasaction = false; try { db.Commands.Clear(); itTrasaction = true; db.BeginTransaction(); foreach (string ck in cur["Details"].ObjKeys) { _detailID = Guid.NewGuid(); JSON curd = cur["Details"][ck]; cmdl = new List <Parameter>(); cmdl.Add(new Parameter("@RowID", SqlDbType.UniqueIdentifier, _detailID)); cmdl.Add(new Parameter("@HeaderID", SqlDbType.UniqueIdentifier, id)); cmdl.Add(new Parameter("@DOID", SqlDbType.UniqueIdentifier, curd["DOID"].GuidValue(DBNull.Value))); cmdl.Add(new Parameter("@DODetailID", SqlDbType.UniqueIdentifier, curd["DODetailID"].GuidValue(DBNull.Value))); cmdl.Add(new Parameter("@RecordID", SqlDbType.VarChar, FingerPrintWiser(curd["wiserid"].StringValue))); cmdl.Add(new Parameter("@HtrID", SqlDbType.VarChar, FingerPrintWiser(curd["wiserid"].StringValue))); cmdl.Add(new Parameter("@KodeGudang", SqlDbType.VarChar, curd["KodeGudang"].StringValue)); cmdl.Add(new Parameter("@BarangID", SqlDbType.VarChar, curd["BarangID"].StringValue)); cmdl.Add(new Parameter("@QtySuratJalan", SqlDbType.Int, curd["QtySuratJalan"].NumberValue)); cmdl.Add(new Parameter("@QtyNota", SqlDbType.Int, curd["QtyNota"].NumberValue)); cmdl.Add(new Parameter("@HrgJual", SqlDbType.Money, curd["HrgJual"].NumberValue)); cmdl.Add(new Parameter("@Disc1", SqlDbType.Decimal, curd["Disc1"].NumberValue)); cmdl.Add(new Parameter("@Disc2", SqlDbType.Decimal, curd["Disc2"].NumberValue)); cmdl.Add(new Parameter("@Disc3", SqlDbType.Decimal, curd["Disc3"].NumberValue)); cmdl.Add(new Parameter("@Pot", SqlDbType.Money, 0)); cmdl.Add(new Parameter("@DiscFormula", SqlDbType.VarChar, "")); cmdl.Add(new Parameter("@QtyKoli", SqlDbType.Int, curd["QtyKoli"].NumberValue)); cmdl.Add(new Parameter("@KoliAwal", SqlDbType.Int, curd["KoliAwal"].NumberValue)); cmdl.Add(new Parameter("@KoliAkhir", SqlDbType.Int, curd["KoliAkhir"].NumberValue)); cmdl.Add(new Parameter("@NoKoli", SqlDbType.VarChar, curd["NoKoli"].StringValue)); cmdl.Add(new Parameter("@Catatan", SqlDbType.VarChar, curd["Catatan"].StringValue)); cmdl.Add(new Parameter("@SyncFlag", SqlDbType.Bit, 0)); cmdl.Add(new Parameter("@KetKoli", SqlDbType.VarChar, curd["KetKoli"].StringValue)); cmdl.Add(new Parameter("@NPackingListPrint", SqlDbType.Int, curd["NPackingListPrint"].NumberValue)); cmdl.Add(new Parameter("@LastUpdatedBy", SqlDbType.VarChar, curd["LastUpdatedBy"].StringValue)); cmdl.Add(new Parameter("@CreatedBy", SqlDbType.VarChar, curd["LastUpdatedBy"].StringValue)); cmdl.Add(new Parameter("@QtyStock", SqlDbType.Int, curd["QtyStock"].NumberValue)); cmdl.Add(new Parameter("@WiserID", SqlDbType.Int, curd["wiserid"].NumberValue)); cmdl.Add(new Parameter("@WiserHeaderID", SqlDbType.Int, cur["wiserid"].NumberValue)); cmdl.Add(new Parameter("@WiserTag", SqlDbType.VarChar, "WISERDC")); db.Commands.Add(db.CreateCommand("[usp_NotaPenjualanDetail_WISERDC_SET]")); db.Commands[cid].Parameters = cmdl; cid += 1; } foreach (Command cmd in db.Commands) { try { cmd.ExecuteNonQuery(); } catch (Exception ex) { Error.LogError(ex); } } } catch (Exception) { if (itTrasaction) { db.RollbackTransaction(); } itOk = false; } if (itOk) { if (itTrasaction) { db.CommitTransaction(); } try { //Link Ke Piutang GetDataNota(id); if ((new JSON(cur["TglTerima"].DateTimeValue(DBNull.Value))).DateTimeValue(null) != null) { IsiTglTerima((DateTime)cur["TglTerima"].DateTimeValue(DBNull.Value), (string)cur["TransactionType"].StringValue, (int)cur["HariKredit"].NumberValue, (int)cur["HariKirim"].NumberValue, (int)cur["HariSales"].NumberValue, (string)cur["LastUpdatedBy"].StringValue); GetDataNota(id); LinkKePiutang(); successMessage = "DATA BERHASIL DITAMBAHKAN DAN SUDAH DILINK KE PIUTANG"; } else { successMessage = "DATA BERHASIL DITAMBAHKAN TAPI BELUM DILINK KE PIUTANG KARENA TGL TERIMA MASIH KOSONG"; } } catch (Exception ex) { itOk = false; } } if (itOk) { //if (itTrasaction) db.CommitTransaction(); scs.Add((int)cur["wiserid"].NumberValue); } else { try { db.Commands.Clear(); db.Commands.Add(db.CreateCommand("[usp_NotaPenjualan_WISERDC_DELETE]")); db.Commands[0].Parameters.Add(new Parameter("@RowID", SqlDbType.UniqueIdentifier, id)); db.Commands[0].Parameters.Add(new Parameter("@WiserID", SqlDbType.Int, cur["wiserid"].NumberValue)); db.Commands[0].ExecuteNonQuery(); } catch (Exception) { } } } else if (dtbl.Rows[0]["Result"].ToString() == "2") { MessageBox.Show("Order Penjualan atas Nota " + cur["NoNota"].StringValue + " tidak ditemukan"); //return; } else { if (successMessage != "") { if (!successMessage.Contains("SURAT JALAN")) { successMessage = successMessage + " ADA NOTA YANG BELUM DIBUAT SURAT JALAN."; } } else { if (!successMessage.Contains("SURAT JALAN") && !successMessage.Contains("PIUTANG")) { successMessage = "ADA NOTA YANG BELUM DIBUAT SURAT JALAN."; } } } } } catch (Exception ex) { MessageBox.Show("Error: " + ex); return; } } if (scs.Count > 0) { MessageBox.Show(successMessage); } else { MessageBox.Show("Synch gagal"); } if (scs.Count > 0) { if (!hasSynch) { hasSynch = true; } MarkAsSuccess(scs.ToArray()); JSON opt = new JSON(JSONType.Object); JSON lst = new JSON(JSONType.Array); foreach (int ix in scs) { lst.ArrAdd(new JSON(ix)); } opt.ObjAdd("mark", new JSON(true)); opt.ObjAdd("ids", lst); string errm = ""; XNet xn = new XNet(host + "/api/notapenjualan/synch", XNetMethod.GET); XNetThread xnt = xn.Send(opt, r => { if (r.Error != null) { errm = r.Error.Message; } else if (r.Output.Length > 0) { JSON jres = JSON.Parse(r.Output); if (jres.Type == JSONType.Object) { if (jres.ObjExists("Result") && jres["Result"].BoolValue) { errm = ""; } else if (jres.ObjExists("Msg")) { errm = jres["Msg"].StringValue; } else { errm = "Marking to server failed"; } return; } } errm = "Marking to server failed"; }); if (errm.Length > 0) { MessageBox.Show("Server message:\n" + errm); } } else { MessageBox.Show("Synch gagal"); } b.Result = true; return; } if (b.Result != null && !b.Result.Equals(true)) { MessageBox.Show(b.Result.ToString()); return; } }; bgw.RunWorkerCompleted += (a, b) => { bool r = false; if (b.Cancelled) { MessageBox.Show(thisx, "Operasi di gagalkan"); } else if (b.Error != null) { MessageBox.Show(thisx, b.Error.Message); } else { r = true; } ipProgress.Close(r); //if (scs.Count == mdat.Count) this.Close(); }; ipProgress.OpenDialog(this, a => { }, () => bgw.CancelAsync()); bgw.RunWorkerAsync(); }
private void ImportData(int[] ids) { Form thisx = this; if (ipProgress == null) { ipProgress = new InPopup(this, pnlProgress); } if (fpProgress == null) { fpProgress = new FakeProgress(progbProgress); } BackgroundWorker bgw = new BackgroundWorker(); bgw.DoWork += (a, b) => { fpProgress.Start(); using (var db = new Database()) { if (bgw.CancellationPending) { return; } db.Commands.Add(db.CreateCommand("[usp_AppSetting_LIST]")); db.Commands[0].Parameters.Add(new Parameter("@Key", SqlDbType.VarChar, "WiserDC_Host")); DataTable dtbl2 = db.Commands[0].ExecuteDataTable(); string host = "http://devwiserdc.sas-autoparts.com:8000"; if (dtbl2.Rows.Count > 0) { host = dtbl2.Rows[0]["Value"].ToString(); } else { MessageBox.Show("Download gagal, Wiser belum di setting"); return; } Guid _headerRowID, _detailID; List <int> scs = new List <int>(); foreach (int i in ids) { JSON cur = mdat[i.ToString()]; List <Parameter> cmdl = new List <Parameter>(); db.Commands.Clear(); //DateTime tTerima = DateTime.ParseExact(cur["TglTerima"].StringValue, "yyyy-MM-dd", CultureInfo.InvariantCulture); //MessageBox.Show(cur["NotaRowID"].GuidValue(DBNull.Value).ToString()); //return; if (cur["RJRowID"].GuidValue(DBNull.Value) == DBNull.Value) { _headerRowID = Guid.NewGuid(); } else { _headerRowID = (Guid)cur["RJRowID"].GuidValue(DBNull.Value); } cmdl.Add(new Parameter("@RowID", SqlDbType.UniqueIdentifier, _headerRowID)); cmdl.Add(new Parameter("@ReturID", SqlDbType.VarChar, FingerPrintWiser(cur["wiserid"].StringValue))); cmdl.Add(new Parameter("@Cabang1", SqlDbType.VarChar, cur["Cabang1"].StringValue)); cmdl.Add(new Parameter("@Cabang2", SqlDbType.VarChar, cur["Cabang2"].StringValue)); cmdl.Add(new Parameter("@NoMPR", SqlDbType.VarChar, cur["NoMPR"].StringValue)); cmdl.Add(new Parameter("@NoNotaRetur", SqlDbType.VarChar, cur["NoNotaRetur"].StringValue)); cmdl.Add(new Parameter("@NoTolak", SqlDbType.VarChar, cur["NoTolak"].StringValue)); cmdl.Add(new Parameter("@TglMPR", SqlDbType.DateTime, cur["TglMPR"].DateTimeValue(DBNull.Value))); cmdl.Add(new Parameter("@TglNotaRetur", SqlDbType.DateTime, cur["TglNotaRetur"].DateTimeValue(DBNull.Value))); cmdl.Add(new Parameter("@TglTolak", SqlDbType.DateTime, cur["TglTolak"].DateTimeValue(DBNull.Value))); cmdl.Add(new Parameter("@KodeToko", SqlDbType.VarChar, cur["KodeToko"].StringValue)); cmdl.Add(new Parameter("@Pengambilan", SqlDbType.VarChar, cur["Pengambilan"].StringValue)); cmdl.Add(new Parameter("@TglPengambilan", SqlDbType.DateTime, cur["TglPengambilan"].DateTimeValue(DBNull.Value))); cmdl.Add(new Parameter("@TglGudang", SqlDbType.DateTime, cur["TglGudang"].DateTimeValue(DBNull.Value))); cmdl.Add(new Parameter("@BagPenjualan", SqlDbType.VarChar, cur["BagPenjualan"].StringValue)); cmdl.Add(new Parameter("@Penerima", SqlDbType.VarChar, cur["Penerima"].StringValue)); cmdl.Add(new Parameter("@isClosed", SqlDbType.Bit, 0)); cmdl.Add(new Parameter("@SyncFlag", SqlDbType.Bit, 0)); //cmdl.Add(new Parameter("@LinkID", SqlDbType.VarChar, "")); cmdl.Add(new Parameter("@NPrint", SqlDbType.Int, cur["NPrint"].NumberValue)); cmdl.Add(new Parameter("@TglRQRetur", SqlDbType.DateTime, cur["TglRQRetur"].DateTimeValue(DBNull.Value))); cmdl.Add(new Parameter("@LastUpdatedBy", SqlDbType.VarChar, cur["LastUpdatedBy"].StringValue)); cmdl.Add(new Parameter("@ACCSPV", SqlDbType.VarChar, cur["ACCSPV"].StringValue)); cmdl.Add(new Parameter("@wiserid", SqlDbType.Int, cur["wiserid"].NumberValue)); cmdl.Add(new Parameter("@WiserTag", SqlDbType.VarChar, "WISERDC")); try { db.Commands.Clear(); db.Commands.Add(db.CreateCommand("usp_ReturPenjualan_WISERDC_SET")); db.Commands[0].Parameters = cmdl; DataTable dtbl = db.Commands[0].ExecuteDataTable(); if (dtbl.Rows.Count > 0) { if (dtbl.Rows[0]["Result"].ToString() == "1") { Guid id = (Guid)dtbl.Rows[0]["RowID"]; int cid = 0; bool itOk = true; bool itTrasaction = false; try { db.Commands.Clear(); itTrasaction = true; db.BeginTransaction(); foreach (string ck in cur["Details"].ObjKeys) { JSON curd = cur["Details"][ck]; if (curd["RJDRowID"].GuidValue(DBNull.Value) == DBNull.Value) { _detailID = Guid.NewGuid(); } else { _detailID = (Guid)curd["RJDRowID"].GuidValue(DBNull.Value); } cmdl = new List <Parameter>(); cmdl.Add(new Parameter("@RowID", SqlDbType.UniqueIdentifier, _detailID)); cmdl.Add(new Parameter("@HeaderID", SqlDbType.UniqueIdentifier, id)); cmdl.Add(new Parameter("@NotaJualDetailWiserID", SqlDbType.Int, curd["NotaJualDetailWiserID"].NumberValue)); cmdl.Add(new Parameter("@RecordID", SqlDbType.VarChar, FingerPrintWiser(curd["wiserid"].StringValue))); cmdl.Add(new Parameter("@KodeRetur", SqlDbType.VarChar, curd["KodeRetur"].StringValue)); cmdl.Add(new Parameter("@KodeGudang", SqlDbType.VarChar, curd["KodeGudang"].StringValue)); cmdl.Add(new Parameter("@BarangID", SqlDbType.VarChar, curd["BarangID"].StringValue)); cmdl.Add(new Parameter("@QtyMemo", SqlDbType.Int, curd["QtyMemo"].NumberValue)); cmdl.Add(new Parameter("@QtyTarik", SqlDbType.Int, curd["QtyTarik"].NumberValue)); cmdl.Add(new Parameter("@QtyTerima", SqlDbType.Int, curd["QtyTerima"].NumberValue)); cmdl.Add(new Parameter("@QtyGudang", SqlDbType.Int, curd["QtyGudang"].NumberValue)); cmdl.Add(new Parameter("@QtyTolak", SqlDbType.Int, curd["QtyTolak"].NumberValue)); cmdl.Add(new Parameter("@HrgJual", SqlDbType.Money, curd["HrgJual"].NumberValue)); cmdl.Add(new Parameter("@Catatan1", SqlDbType.VarChar, curd["Catatan1"].StringValue)); cmdl.Add(new Parameter("@Catatan2", SqlDbType.VarChar, curd["Catatan2"].StringValue)); cmdl.Add(new Parameter("@SyncFlag", SqlDbType.Bit, 0)); cmdl.Add(new Parameter("@Kategori", SqlDbType.VarChar, curd["Kategori"].StringValue)); cmdl.Add(new Parameter("@NoACC", SqlDbType.VarChar, curd["NoACC"].StringValue)); cmdl.Add(new Parameter("@LastUpdatedBy", SqlDbType.VarChar, curd["LastUpdatedBy"].StringValue)); cmdl.Add(new Parameter("@WiserID", SqlDbType.Int, curd["wiserid"].NumberValue)); cmdl.Add(new Parameter("@WiserHeaderID", SqlDbType.Int, cur["wiserid"].NumberValue)); cmdl.Add(new Parameter("@WiserTag", SqlDbType.VarChar, "WISERDC")); db.Commands.Add(db.CreateCommand("[usp_ReturPenjualanDetail_WISERDC_SET]")); db.Commands[cid].Parameters = cmdl; cid += 1; } foreach (Command cmd in db.Commands) { try { cmd.ExecuteNonQuery(); } catch (Exception ex) { Error.LogError(ex); } } } catch (Exception) { if (itTrasaction) { db.RollbackTransaction(); } itOk = false; } if (itOk) { if (itTrasaction) { db.CommitTransaction(); } scs.Add((int)cur["wiserid"].NumberValue); } else { try { db.Commands.Clear(); db.Commands.Add(db.CreateCommand("[usp_ReturPenjualan_WISERDC_DELETE]")); db.Commands[0].Parameters.Add(new Parameter("@RowID", SqlDbType.UniqueIdentifier, id)); db.Commands[0].Parameters.Add(new Parameter("@WiserID", SqlDbType.Int, cur["wiserid"].NumberValue)); db.Commands[0].ExecuteNonQuery(); } catch (Exception) { } } //Link Ke Piutang //GetDataNota(id); //LinkKePiutang(); } else if (dtbl.Rows[0]["Result"].ToString() == "2") { MessageBox.Show("Order Penjualan atas Nota " + cur["NoNota"].StringValue + " tidak ditemukan"); return; } else { MessageBox.Show("Unknown Error"); return; } } } catch (Exception ex) { MessageBox.Show("Error: " + ex); } } if (scs.Count > 0) { MessageBox.Show("DATA BERHASIL DITAMBAHKAN"); } else { MessageBox.Show("Synch gagal"); } if (scs.Count > 0) { if (!hasSynch) { hasSynch = true; } MarkAsSuccess(scs.ToArray()); JSON opt = new JSON(JSONType.Object); JSON lst = new JSON(JSONType.Array); foreach (int ix in scs) { lst.ArrAdd(new JSON(ix)); } opt.ObjAdd("mark", new JSON(true)); opt.ObjAdd("ids", lst); string errm = ""; XNet xn = new XNet(host + "/api/returpenjualan/synch", XNetMethod.GET); XNetThread xnt = xn.Send(opt, r => { if (r.Error != null) { errm = r.Error.Message; } else if (r.Output.Length > 0) { JSON jres = JSON.Parse(r.Output); if (jres.Type == JSONType.Object) { if (jres.ObjExists("Result") && jres["Result"].BoolValue) { errm = ""; } else if (jres.ObjExists("Msg")) { errm = jres["Msg"].StringValue; } else { errm = "Marking to server failed"; } return; } } errm = "Marking to server failed"; }); if (errm.Length > 0) { MessageBox.Show("Server message:\n" + errm); } } else { MessageBox.Show("Synch gagal"); } b.Result = true; return; } if (b.Result != null && !b.Result.Equals(true)) { MessageBox.Show(b.Result.ToString()); return; } }; bgw.RunWorkerCompleted += (a, b) => { bool r = false; if (b.Cancelled) { MessageBox.Show(thisx, "Operasi di gagalkan"); } else if (b.Error != null) { MessageBox.Show(thisx, b.Error.Message); } else { r = true; } ipProgress.Close(r); this.Close(); }; ipProgress.OpenDialog(this, a => { }, () => bgw.CancelAsync()); bgw.RunWorkerAsync(); }