コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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");
                }
            }
        }
コード例 #3
0
        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("from", new JSON(rangeDateBox1.FromDate.Value.ToString("yyyy-MM-dd")));
                opt.ObjAdd("to", new JSON(rangeDateBox1.ToDate.Value.ToString("yyyy-MM-dd")));

                string host = "https://devwiser.sas-autoparts.com";
                using (var db = new Database())
                {
                    db.Commands.Add(db.CreateCommand("[usp_AppSetting_LIST]"));
                    db.Commands[0].Parameters.Add(new Parameter("@Key", SqlDbType.VarChar, "Wiser_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");
                    }
                }

                string apiu = host;
                apiu += "/api/toko/synch/" + GlobalVar.Gudang;

                XNet       xn  = new XNet(apiu, XNetMode.Synchronous);
                XNetThread xnt = xn.Get(opt, c =>
                {
                    if (bgw.CancellationPending)
                    {
                        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();

                                        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)
                                                    {
                                                        switch (k2)
                                                        {
                                                        case "int":
                                                            dtbl0.Columns.Add(k2, typeof(int));
                                                            break;

                                                        case "total":
                                                        case "count":
                                                            dtbl0.Columns.Add(k2, typeof(double));
                                                            break;

                                                        default:
                                                            dtbl0.Columns.Add(k2);
                                                            break;
                                                        }
                                                    }
                                                    itm.Add(cur[k2].Value);
                                                    break;
                                                }
                                            }

                                            dtbl0.Rows.Add(itm.ToArray());
                                        }

                                        dset = new DataSet();
                                        mdat = jdat["Data"];
                                        dset.Tables.Add(dtbl0);
                                        GV01.Invoke(new Action(() => GV01.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("Server error: " + jdat.ToString());
                                    }
                                }
                            }
                            else
                            {
                                throw new Exception("Server error: " + 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))
                {
                    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 if (dtbl0.Rows.Count == 0) { MessageBox.Show("Tidak Ada Data"); return; }
                else
                {
                    r = true;
                }

                ipProgress.Close(r);
            };

            ipProgress.OpenDialog(this, a =>
            {
            }, () => bgw.CancelAsync());
            bgw.RunWorkerAsync();
        }