protected void grid_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    {
        //e.NewValues["PartyName"] = SafeValue.SafeString(e.NewValues["PartyName"]);
        //e.NewValues["TransportName"] = SafeValue.SafeString(e.NewValues["TransportName"]);
        //e.NewValues["TransportStatus"] = SafeValue.SafeString(e.NewValues["TransportStatus"]);
        //e.NewValues["DriverName"] = SafeValue.SafeString(e.NewValues["DriverName"]);
        //e.NewValues["DriverIC"] = SafeValue.SafeString(e.NewValues["DriverIC"]);
        //e.NewValues["DriverTel"] = SafeValue.SafeString(e.NewValues["DriverTel"]);
        //e.NewValues["TptJobNo"] = SafeValue.SafeString(e.NewValues["TptJobNo"]);
        //e.NewValues["TransportStart"] = SafeValue.SafeDate(e.NewValues["TransportStart"],DateTime.Today);
        //e.NewValues["Remarks"] = SafeValue.SafeString(e.NewValues["Remarks"]);

        string      userId = HttpContext.Current.User.Identity.Name;
        ASPxTextBox txt_Id = grid.FindEditRowCellTemplateControl(null, "txt_Id") as ASPxTextBox;

        Wilson.ORMapper.OPathQuery query = new Wilson.ORMapper.OPathQuery(typeof(WhDo), "Id='" + txt_Id.Text + "'");
        WhDo whDo = C2.Manager.ORManager.GetObject(query) as WhDo;

        ASPxComboBox txt_TransportStatus = grid.FindEditRowCellTemplateControl(null, "txt_TransportStatus") as ASPxComboBox;
        ASPxTextBox  txt_DriveName       = grid.FindEditRowCellTemplateControl(null, "txt_DriveName") as ASPxTextBox;
        ASPxTextBox  txt_DriverIC        = grid.FindEditRowCellTemplateControl(null, "txt_DriverIC") as ASPxTextBox;
        ASPxTextBox  txt_DriverTel       = grid.FindEditRowCellTemplateControl(null, "txt_DriverTel") as ASPxTextBox;
        ASPxTextBox  txt_VechicleNo      = grid.FindEditRowCellTemplateControl(null, "txt_VechicleNo") as ASPxTextBox;
        ASPxTextBox  txt_TptJobNo        = grid.FindEditRowCellTemplateControl(null, "txt_TptJobNo") as ASPxTextBox;
        ASPxDateEdit date_TransportStart = grid.FindEditRowCellTemplateControl(null, "date_TransportStart") as ASPxDateEdit;
        ASPxMemo     meno_Remark         = grid.FindEditRowCellTemplateControl(null, "meno_Remark") as ASPxMemo;

        whDo.TransportStatus = SafeValue.SafeString(txt_TransportStatus.Text);
        whDo.DriverName      = SafeValue.SafeString(txt_DriveName.Text);
        whDo.DriverIC        = SafeValue.SafeString(txt_DriverIC.Text);
        whDo.DriverTel       = SafeValue.SafeString(txt_DriverTel.Text);
        whDo.VehicleNo       = SafeValue.SafeString(txt_VechicleNo.Text);
        whDo.TptJobNo        = SafeValue.SafeString(txt_TptJobNo.Text);
        whDo.TransportStart  = SafeValue.SafeDate(txt_TransportStatus.Text, DateTime.Today);
        whDo.Remarks         = SafeValue.SafeString(meno_Remark.Text);
        whDo.UpdateBy        = userId;
        whDo.UpdateDateTime  = DateTime.Now;

        Manager.ORManager.StartTracking(whDo, Wilson.ORMapper.InitialState.Updated);
        Manager.ORManager.PersistChanges(whDo);

        btn_search_Click(null, null);
    }
Esempio n. 2
0
    protected void grid_SKULine_CustomDataCallback(object sender, ASPxGridViewCustomDataCallbackEventArgs e)
    {
        string s      = e.Parameters;
        string soNo   = SafeValue.SafeString(Request.QueryString["no"].ToString());
        string schId  = SafeValue.SafeString(Request.QueryString["SchId"].ToString());
        string userId = HttpContext.Current.User.Identity.Name;

        if (s == "Save")
        {
            bool      result = false;
            string    issueN = "";
            string    sql    = string.Format(@"select * from Wh_TransDet where DoNo='{0}'", soNo);
            DataTable tab    = ConnectSql.GetTab(sql);
            for (int i = 0; i < tab.Rows.Count; i++)
            {
                if (SafeValue.SafeInt(tab.Rows[i]["Qty1"], 0) == 0)
                {
                    e.Result = "Fail,Please keyin Qty ";
                    return;
                }
            }
            C2.XAArInvoice inv    = null;
            C2.XAArInvoice inv_Do = null;
            if (tab.Rows.Count > 0)
            {
                //Get SO
                #region Get So
                bool isNew = false;
                Wilson.ORMapper.OPathQuery query1 = new Wilson.ORMapper.OPathQuery(typeof(WhTrans), "DoNo='" + soNo + "'");
                WhTrans   so     = C2.Manager.ORManager.GetObject(query1) as WhTrans;
                string    sql1   = string.Format("select doNo from wh_do where DoType='Out' and PoNo='{0}'", soNo);
                DataTable tab_do = ConnectSql.GetTab(sql1);
                string where = "(1=0";
                for (int i = 0; i < tab_do.Rows.Count; i++)
                {
                    where += string.Format(" or DoNo='{0}' ", tab_do.Rows[i][0]);
                }
                where += ")";

                int cnt = 0;
                sql = string.Format("select count(*) from wh_transDet where DoNo='{0}' and DoType='SO' and isnull(LotNo,'')='' ", soNo);
                cnt = SafeValue.SafeInt(ConnectSql.ExecuteSql(sql), 0);
                if (cnt > 0)
                {
                    e.Result = "No Balance Qty or No Lot No!";
                    return;
                }
                string update = string.Format(@"update Wh_Schedule set StatusCode='Closed' where Id='{1}'", soNo, schId);
                C2.Manager.ORManager.ExecuteCommand(update);
                #endregion
                #region Create SO Invoice
                int    invId = 0;
                string invN  = "";
                inv = Manager.ORManager.GetObject(typeof(XAArInvoice), SafeValue.SafeInt(invId, 0)) as XAArInvoice;
                if (inv == null)// first insert invoice
                {
                    string counterType = "AR-IV";
                    inv         = new XAArInvoice();
                    invN        = C2Setup.GetNextNo("", counterType, so.DoDate);
                    inv.PartyTo = SafeValue.SafeString(so.PartyId, "");
                    inv.DocType = "IV";
                    inv.DocNo   = invN.ToString();
                    inv.DocDate = so.DoDate;
                    string[] currentPeriod = EzshipHelper.GetAccPeriod(so.DoDate);

                    inv.AcYear   = SafeValue.SafeInt(currentPeriod[1], so.DoDate.Year);
                    inv.AcPeriod = SafeValue.SafeInt(currentPeriod[0], so.DoDate.Month);
                    inv.Term     = so.PayTerm;

                    //
                    int dueDay = 0;
                    if (so.PayTerm != null)
                    {
                        dueDay = SafeValue.SafeInt(so.PayTerm.ToUpper().Replace("DAYS", ""), 0);
                    }

                    inv.DocDueDate  = inv.DocDate.AddDays(dueDay);//SafeValue.SafeDate(dueDt.Text, DateTime.Now);
                    inv.Description = so.Remark;
                    inv.CurrencyId  = so.Currency;
                    inv.ExRate      = SafeValue.SafeDecimal(so.ExRate, 1);
                    if (inv.ExRate <= 0)
                    {
                        inv.ExRate = 1;
                    }
                    inv.AcCode      = EzshipHelper.GetAccArCode(inv.PartyTo, inv.CurrencyId);
                    inv.AcSource    = "DB";
                    inv.SpecialNote = "";

                    inv.MastType  = "WH";
                    inv.MastRefNo = so.DoNo;
                    inv.JobRefNo  = "";

                    inv.ExportInd  = "N";
                    inv.UserId     = HttpContext.Current.User.Identity.Name;
                    inv.EntryDate  = DateTime.Now;
                    inv.CancelDate = new DateTime(1900, 1, 1);
                    inv.CancelInd  = "N";
                    try
                    {
                        C2.Manager.ORManager.StartTracking(inv, Wilson.ORMapper.InitialState.Inserted);
                        C2.Manager.ORManager.PersistChanges(inv);
                        C2Setup.SetNextNo("", counterType, invN, inv.DocDate);
                    }
                    catch
                    {
                    }
                }
                #endregion
                #region Create DO
                //Create DoNo
                string doId = "";
                Wilson.ORMapper.OPathQuery query2 = new Wilson.ORMapper.OPathQuery(typeof(WhDo), "Id='" + doId + "'");
                WhDo whDo = C2.Manager.ORManager.GetObject(query2) as WhDo;

                if (whDo == null)
                {
                    whDo        = new WhDo();
                    isNew       = true;
                    issueN      = C2Setup.GetNextNo("", "DOOUT", so.DoDate);
                    whDo.DoType = "OUT";
                }
                whDo.DoNo           = issueN;
                whDo.PoNo           = so.DoNo;
                whDo.DoDate         = so.DoDate;
                whDo.PoDate         = so.DoDate;
                whDo.StatusCode     = "CLS";
                whDo.PartyId        = so.PartyId;
                whDo.PartyName      = so.PartyName;
                whDo.AgentId        = so.AgentId;
                whDo.AgentName      = so.AgentName;
                whDo.AgentTel       = so.AgentTel;
                whDo.AgentZip       = so.AgentZip;
                whDo.AgentCountry   = so.AgentCountry;
                whDo.AgentCity      = so.AgentCity;
                whDo.NotifyId       = so.NotifyId;
                whDo.NotifyName     = so.NotifyName;
                whDo.WareHouseId    = so.WareHouseId;
                whDo.CreateBy       = so.CreateBy;
                whDo.CreateDateTime = so.CreateDateTime;
                whDo.UpdateBy       = so.UpdateBy;
                whDo.UpdateDateTime = so.UpdateDateTime;
                if (isNew)
                {
                    Manager.ORManager.StartTracking(whDo, Wilson.ORMapper.InitialState.Inserted);
                    Manager.ORManager.PersistChanges(whDo);
                    C2Setup.SetNextNo("", "DOOUT", issueN, DateTime.Now);
                }
                #endregion
                #region Create DO Invoice
                inv_Do = Manager.ORManager.GetObject(typeof(XAArInvoice), SafeValue.SafeInt(invId, 0)) as XAArInvoice;
                if (inv_Do == null)// first insert invoice
                {
                    string counterType = "AR-IV";
                    inv_Do         = new XAArInvoice();
                    invN           = C2Setup.GetNextNo("", counterType, so.DoDate);
                    inv_Do.PartyTo = SafeValue.SafeString(so.PartyId, "");
                    inv_Do.DocType = "IV";
                    inv_Do.DocNo   = invN.ToString();
                    inv_Do.DocDate = so.DoDate;
                    string[] currentPeriod = EzshipHelper.GetAccPeriod(so.DoDate);

                    inv_Do.AcYear   = SafeValue.SafeInt(currentPeriod[1], so.DoDate.Year);
                    inv_Do.AcPeriod = SafeValue.SafeInt(currentPeriod[0], so.DoDate.Month);
                    inv_Do.Term     = so.PayTerm;

                    //
                    int dueDay = 0;
                    if (so.PayTerm != null)
                    {
                        dueDay = SafeValue.SafeInt(so.PayTerm.ToUpper().Replace("DAYS", ""), 0);
                    }

                    inv_Do.DocDueDate  = inv.DocDate.AddDays(dueDay);//SafeValue.SafeDate(dueDt.Text, DateTime.Now);
                    inv_Do.Description = so.Remark;
                    inv_Do.CurrencyId  = so.Currency;
                    inv_Do.ExRate      = SafeValue.SafeDecimal(so.ExRate, 1);
                    if (inv_Do.ExRate <= 0)
                    {
                        inv_Do.ExRate = 1;
                    }
                    inv_Do.AcCode      = EzshipHelper.GetAccArCode(inv.PartyTo, inv.CurrencyId);
                    inv_Do.AcSource    = "DB";
                    inv_Do.SpecialNote = "";

                    inv_Do.MastType  = "WH";
                    inv_Do.MastRefNo = whDo.DoNo;
                    inv_Do.JobRefNo  = "";

                    inv_Do.ExportInd  = "N";
                    inv_Do.UserId     = HttpContext.Current.User.Identity.Name;
                    inv_Do.EntryDate  = DateTime.Now;
                    inv_Do.CancelDate = new DateTime(1900, 1, 1);
                    inv_Do.CancelInd  = "N";
                    try
                    {
                        C2.Manager.ORManager.StartTracking(inv_Do, Wilson.ORMapper.InitialState.Inserted);
                        C2.Manager.ORManager.PersistChanges(inv_Do);
                        C2Setup.SetNextNo("", counterType, invN, inv_Do.DocDate);
                    }
                    catch
                    {
                    }
                }
                #endregion
            }
            #region Create Transfer
            for (int i = 0; i < tab.Rows.Count; i++)
            {
                string  product  = SafeValue.SafeString(tab.Rows[i]["ProductCode"]);
                string  lotNo    = SafeValue.SafeString(tab.Rows[i]["LotNo"]);
                int     qty      = SafeValue.SafeInt(tab.Rows[i]["Qty1"], 0);
                decimal price    = SafeValue.SafeDecimal(tab.Rows[i]["Price"]);
                string  des1     = SafeValue.SafeString(tab.Rows[i]["Des1"]);
                string  location = SafeValue.SafeString(tab.Rows[i]["LocationCode"]);

                sql  = @"Insert Into wh_DoDet(JobStatus,DoNo, DoType,ProductCode,ExpiredDate,Price,Qty1,Qty2,Qty3,Qty4,Qty5,LotNo,BatchNo,CustomsLot,Uom1,Uom2,Uom3,Uom4,[QtyPackWhole],[QtyWholeLoose],[QtyLooseBase],Att1,Att2,Att3,Att4,Att5,Att6,Att7,Att8,Att9,Att10,Des1,Packing,[CreateBy],[CreateDateTime],[UpdateBy],[UpdateDateTime],DoInId)";
                sql += string.Format(@" select * from (select 'Picked' as JobStatus,'{1}'as DoNo, 'Out' as DoType,ProductCode,ExpiredDate,Price
,Qty1 as Qty1
,0 as Qty2
,0 as Qty3
,Qty1 as Qty4
,0 as Qty5
, LotNo,BatchNo,CustomsLot,Uom1,Uom2,Uom3,Uom4,[QtyPackWhole],[QtyWholeLoose],[QtyLooseBase],Att1,Att2,Att3,Att4,Att5,Att6,Att7,Att8,Att9,Att10,Des1,Packing,'{2}' as CreateBy,getdate() as CreateDateTime,'{2}' as UpdateBy,getdate() as UpdateDateTime,Id as DoInId from Wh_TransDet where DoNo='{0}' and ProductCode='{4}' and LotNo='{5}' and DoType='SO' and LocationCode='{3}'
 ) as tab_aa where qty4>0  ", soNo, issueN, userId, location, product, lotNo);

                C2.Manager.ORManager.ExecuteCommand(sql);

                sql  = @"Insert Into Wh_DoDet2(DoNo,DoType,Product,Qty1,Qty2,Qty3,Price,LotNo,Uom1,Uom2,Uom3,Uom4,[QtyPackWhole],[QtyWholeLoose],[QtyLooseBase],[CreateBy],[CreateDateTime],[UpdateBy],[UpdateDateTime],Att1,Att2,Att3,Att4,Att5,Att6,Des1,Packing,Location,ProcessStatus)";
                sql += string.Format(@"select '{0}'as DoNo, 'OUT' as DoType,'{1}' as Sku
 ,'{2}' as Qty1
 ,0 as Qty2
 ,0 as Qty3
 ,'{3}' as Price
,'{4}' as LotNo
,ref.UomPacking as Uom1,ref.UomWhole as Uom2,ref.UomLoose as Uom3,ref.UomBase as Uom4
,ref.QtyPackingWhole as QtyPackWhole,ref.QtyWholeLoose as  QtyWholeLoose,ref.QtyLooseBase as QtyLooseBase
,'{5}' as CreateBy,getdate() as CreateDateTime,'{5}' as UpdateBy,getdate() as UpdateDateTime
,ref.Att4 as Att1,ref.Att5 as Att2,ref.att6 as Att3,ref.att7 as Att4,ref.att8 as Att5,ref.att9 as Att6,ref.Description as Des1,'' as Packing,'{6}' as Location,'Delivered' as ProcessStatus
from (select '{1}' as Sku) as tab inner join ref_product ref on ref.Code=tab.Sku", issueN, product, qty, price, lotNo, userId, location);
                C2.Manager.ORManager.ExecuteCommand(sql);
                InsertInv_Det(inv.SequenceId, inv.DocNo, i + 1, product, lotNo, des1, qty, price, inv.CurrencyId, inv.ExRate, 0, inv.MastRefNo, "", inv.MastType, "IV");
                UpdateMaster(inv.SequenceId);

                InsertInv_Det(inv_Do.SequenceId, inv_Do.DocNo, i + 1, product, lotNo, des1, qty, price, inv_Do.CurrencyId, inv_Do.ExRate, 0, inv_Do.MastRefNo, "", inv_Do.MastType, "IV");
                UpdateMaster(inv_Do.SequenceId);
                if (soNo.Length > 0)
                {
                    result = true;
                }
            }
            #endregion
            if (result)
            {
                e.Result = issueN;
            }
            else
            {
                e.Result = "Fail,Please keyin select product ";
            }
        }
    }
    protected void ASPxGridView1_CustomDataCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomDataCallbackEventArgs e)
    {
        string s     = e.Parameters;
        string schId = SafeValue.SafeString(Request.QueryString["SchId"].ToString());
        //string code = SafeValue.SafeString(Request.QueryString["Loc"].ToString());
        string salesman = SafeValue.SafeString(Request.QueryString["Salesman"].ToString());
        string location = SafeValue.SafeString(cmb_Location.Text.Trim());
        string userId   = HttpContext.Current.User.Identity.Name;

        if (s == "Save")
        {
            bool   result = false;
            string soNo   = "";
            string issueN = "";
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].qty == 0)
                {
                    e.Result = "Fail,Please keyin Qty ";
                    return;
                }
            }
            C2.XAArInvoice inv    = null;
            C2.XAArInvoice inv_Do = null;
            if (list.Count > 0)
            {
                //Create SO
                #region Create So
                Wilson.ORMapper.OPathQuery query = new Wilson.ORMapper.OPathQuery(typeof(WhSchedule), "Id='" + schId + "'");
                WhSchedule sch   = C2.Manager.ORManager.GetObject(query) as WhSchedule;
                bool       isNew = false;
                Wilson.ORMapper.OPathQuery query1 = new Wilson.ORMapper.OPathQuery(typeof(WhTrans), "DoNo='" + 0 + "'");
                WhTrans so = C2.Manager.ORManager.GetObject(query1) as WhTrans;
                if (so == null)
                {
                    isNew = true;
                    so    = new WhTrans();
                    soNo  = C2Setup.GetNextNo("", "SaleOrders", DateTime.Now);
                }


                so.DoNo           = soNo;
                so.DoDate         = DateTime.Now;
                so.PartyId        = sch.PartyId;
                so.PartyName      = sch.PartyName;
                so.Pic            = sch.PartyContact;
                so.PartyAdd       = sch.PartyAdd;
                so.AgentId        = sch.DoctorId;
                so.AgentName      = EzshipHelper.GetPartyName(sch.DoctorId);
                so.NotifyId       = sch.Patient;
                so.NotifyName     = GetPatientName(sch.Patient);
                so.Currency       = "SGD";
                so.DoType         = "SO";
                so.DoStatus       = "Draft";
                so.ExRate         = 1;
                so.SalesId        = salesman;
                so.CreateBy       = userId;
                so.CreateDateTime = DateTime.Now;
                so.UpdateBy       = userId;
                so.UpdateDateTime = DateTime.Now;
                if (isNew)
                {
                    Manager.ORManager.StartTracking(so, Wilson.ORMapper.InitialState.Inserted);
                    Manager.ORManager.PersistChanges(so);
                    C2Setup.SetNextNo("", "SaleOrders", soNo, DateTime.Now);
                }
                else
                {
                    Manager.ORManager.StartTracking(so, Wilson.ORMapper.InitialState.Updated);
                    Manager.ORManager.PersistChanges(so);
                }
                sch.DoNo = soNo;
                string update = string.Format(@"update Wh_Schedule set DoNo='{0}',StatusCode='Finished' where Id='{1}'", soNo, schId);
                C2.Manager.ORManager.ExecuteCommand(update);
                #endregion
                #region Create SO Invoice
                int    invId = 0;
                string invN  = "";
                inv = Manager.ORManager.GetObject(typeof(XAArInvoice), SafeValue.SafeInt(invId, 0)) as XAArInvoice;
                if (inv == null)// first insert invoice
                {
                    string counterType = "AR-IV";
                    inv         = new XAArInvoice();
                    invN        = C2Setup.GetNextNo("", counterType, so.DoDate);
                    inv.PartyTo = SafeValue.SafeString(so.PartyId, "");
                    inv.DocType = "IV";
                    inv.DocNo   = invN.ToString();
                    inv.DocDate = so.DoDate;
                    string[] currentPeriod = EzshipHelper.GetAccPeriod(so.DoDate);

                    inv.AcYear   = SafeValue.SafeInt(currentPeriod[1], so.DoDate.Year);
                    inv.AcPeriod = SafeValue.SafeInt(currentPeriod[0], so.DoDate.Month);
                    inv.Term     = so.PayTerm;

                    //
                    int dueDay = 0;
                    if (so.PayTerm != null)
                    {
                        dueDay = SafeValue.SafeInt(so.PayTerm.ToUpper().Replace("DAYS", ""), 0);
                    }

                    inv.DocDueDate  = inv.DocDate.AddDays(dueDay);//SafeValue.SafeDate(dueDt.Text, DateTime.Now);
                    inv.Description = so.Remark;
                    inv.CurrencyId  = so.Currency;
                    inv.ExRate      = SafeValue.SafeDecimal(so.ExRate, 1);
                    if (inv.ExRate <= 0)
                    {
                        inv.ExRate = 1;
                    }
                    inv.AcCode      = EzshipHelper.GetAccArCode(inv.PartyTo, inv.CurrencyId);
                    inv.AcSource    = "DB";
                    inv.SpecialNote = "";

                    inv.MastType  = "WH";
                    inv.MastRefNo = so.DoNo;
                    inv.JobRefNo  = "";

                    inv.ExportInd  = "N";
                    inv.UserId     = HttpContext.Current.User.Identity.Name;
                    inv.EntryDate  = DateTime.Now;
                    inv.CancelDate = new DateTime(1900, 1, 1);
                    inv.CancelInd  = "N";
                    try
                    {
                        C2.Manager.ORManager.StartTracking(inv, Wilson.ORMapper.InitialState.Inserted);
                        C2.Manager.ORManager.PersistChanges(inv);
                        C2Setup.SetNextNo("", counterType, invN, inv.DocDate);
                    }
                    catch
                    {
                    }
                }
                #endregion
                #region Create DO
                //Create DoNo
                string doId = "";
                Wilson.ORMapper.OPathQuery query2 = new Wilson.ORMapper.OPathQuery(typeof(WhDo), "Id='" + doId + "'");
                WhDo whDo = C2.Manager.ORManager.GetObject(query2) as WhDo;

                if (whDo == null)
                {
                    whDo        = new WhDo();
                    isNew       = true;
                    issueN      = C2Setup.GetNextNo("", "DOOUT", so.DoDate);
                    whDo.DoType = "OUT";
                }
                whDo.DoNo           = issueN;
                whDo.PoNo           = so.DoNo;
                whDo.DoDate         = so.DoDate;
                whDo.PoDate         = so.DoDate;
                whDo.StatusCode     = "CLS";
                whDo.PartyId        = so.PartyId;
                whDo.PartyName      = so.PartyName;
                whDo.AgentId        = so.AgentId;
                whDo.AgentName      = so.AgentName;
                whDo.AgentTel       = so.AgentTel;
                whDo.AgentZip       = so.AgentZip;
                whDo.AgentCountry   = so.AgentCountry;
                whDo.AgentCity      = so.AgentCity;
                whDo.NotifyId       = so.NotifyId;
                whDo.NotifyName     = so.NotifyName;
                whDo.WareHouseId    = location;
                whDo.CreateBy       = so.CreateBy;
                whDo.CreateDateTime = so.CreateDateTime;
                whDo.UpdateBy       = so.UpdateBy;
                whDo.UpdateDateTime = so.UpdateDateTime;
                if (isNew)
                {
                    Manager.ORManager.StartTracking(whDo, Wilson.ORMapper.InitialState.Inserted);
                    Manager.ORManager.PersistChanges(whDo);
                    C2Setup.SetNextNo("", "DOOUT", issueN, DateTime.Now);
                }
                #endregion
                #region Create DO Invoice
                inv_Do = Manager.ORManager.GetObject(typeof(XAArInvoice), SafeValue.SafeInt(invId, 0)) as XAArInvoice;
                if (inv_Do == null)// first insert invoice
                {
                    string counterType = "AR-IV";
                    inv_Do         = new XAArInvoice();
                    invN           = C2Setup.GetNextNo("", counterType, so.DoDate);
                    inv_Do.PartyTo = SafeValue.SafeString(so.PartyId, "");
                    inv_Do.DocType = "IV";
                    inv_Do.DocNo   = invN.ToString();
                    inv_Do.DocDate = so.DoDate;
                    string[] currentPeriod = EzshipHelper.GetAccPeriod(so.DoDate);

                    inv_Do.AcYear   = SafeValue.SafeInt(currentPeriod[1], so.DoDate.Year);
                    inv_Do.AcPeriod = SafeValue.SafeInt(currentPeriod[0], so.DoDate.Month);
                    inv_Do.Term     = so.PayTerm;

                    //
                    int dueDay = 0;
                    if (so.PayTerm != null)
                    {
                        dueDay = SafeValue.SafeInt(so.PayTerm.ToUpper().Replace("DAYS", ""), 0);
                    }

                    inv_Do.DocDueDate  = inv.DocDate.AddDays(dueDay);//SafeValue.SafeDate(dueDt.Text, DateTime.Now);
                    inv_Do.Description = so.Remark;
                    inv_Do.CurrencyId  = so.Currency;
                    inv_Do.ExRate      = SafeValue.SafeDecimal(so.ExRate, 1);
                    if (inv_Do.ExRate <= 0)
                    {
                        inv_Do.ExRate = 1;
                    }
                    inv_Do.AcCode      = EzshipHelper.GetAccArCode(inv.PartyTo, inv.CurrencyId);
                    inv_Do.AcSource    = "DB";
                    inv_Do.SpecialNote = "";

                    inv_Do.MastType  = "WH";
                    inv_Do.MastRefNo = whDo.DoNo;
                    inv_Do.JobRefNo  = "";

                    inv_Do.ExportInd  = "N";
                    inv_Do.UserId     = HttpContext.Current.User.Identity.Name;
                    inv_Do.EntryDate  = DateTime.Now;
                    inv_Do.CancelDate = new DateTime(1900, 1, 1);
                    inv_Do.CancelInd  = "N";
                    try
                    {
                        C2.Manager.ORManager.StartTracking(inv_Do, Wilson.ORMapper.InitialState.Inserted);
                        C2.Manager.ORManager.PersistChanges(inv_Do);
                        C2Setup.SetNextNo("", counterType, invN, inv_Do.DocDate);
                    }
                    catch
                    {
                    }
                }
                #endregion
            }
            #region Create Transfer
            for (int i = 0; i < list.Count; i++)
            {
                string  id      = list[i].id;
                string  product = list[i].product;
                string  lotNo   = list[i].lotNo;
                int     qty     = list[i].qty;
                decimal price   = list[i].price;
                //string loction = list[i].location;
                string des1   = list[i].des1;
                int    hanQty = list[i].hanQty;
                if (qty > hanQty)
                {
                    e.Result = "Fail,Please keyin the correct qty ";
                    return;
                }
                //string salesman = list[i].salesman;
                string sql = @"Insert Into Wh_TransDet(DoNo, DoType,ProductCode,Qty1,Qty2,Qty3,Price,LotNo,Uom1,Uom2,Uom3,Uom4,[QtyPackWhole],[QtyWholeLoose],[QtyLooseBase],[CreateBy],[CreateDateTime],[UpdateBy],[UpdateDateTime],Att1,Att2,Att3,Att4,Att5,Att6,Des1,LocationCode,DocAmt)";
                sql += string.Format(@"select '{0}'as DoNo, 'SO' as DoType,'{1}' as ProductCode
 ,'{2}' as Qty1
 ,0 as Qty2
 ,0 as Qty3
 ,'{3}' as Price
,'{4}' as LotNo
,ref.UomPacking as Uom1,ref.UomWhole as Uom2,ref.UomLoose as Uom3,ref.UomBase as Uom4
,ref.QtyPackingWhole as QtyPackWhole,ref.QtyWholeLoose as  QtyWholeLoose,ref.QtyLooseBase as QtyLooseBase
,'{5}' as CreateBy,getdate() as CreateDateTime,'{5}' as UpdateBy,getdate() as UpdateDateTime
,ref.Att4 as Att1,ref.Att5 as Att2,ref.att6 as Att3,ref.att7 as Att4,ref.att8 as Att5,ref.att9 as Att6,ref.Description as Des1,'{6}' as LocationCode,{2}*{3} as DocAmt
from (select '{1}' as Sku) as tab inner join ref_product ref on ref.Code=tab.Sku", soNo, product, qty, price, lotNo, EzshipHelper.GetUserName(), location);
                C2.Manager.ORManager.ExecuteCommand(sql);

                sql  = @"Insert Into wh_DoDet(JobStatus,DoNo, DoType,ProductCode,ExpiredDate,Price,Qty1,Qty2,Qty3,Qty4,Qty5,LotNo,BatchNo,CustomsLot,Uom1,Uom2,Uom3,Uom4,[QtyPackWhole],[QtyWholeLoose],[QtyLooseBase],Att1,Att2,Att3,Att4,Att5,Att6,Att7,Att8,Att9,Att10,Des1,Packing,[CreateBy],[CreateDateTime],[UpdateBy],[UpdateDateTime],DoInId)";
                sql += string.Format(@" select * from (select 'Picked' as JobStatus,'{1}'as DoNo, 'Out' as DoType,ProductCode,ExpiredDate,Price
,Qty1 as Qty1
,0 as Qty2
,0 as Qty3
,Qty1 as Qty4
,0 as Qty5
, LotNo,BatchNo,CustomsLot,Uom1,Uom2,Uom3,Uom4,[QtyPackWhole],[QtyWholeLoose],[QtyLooseBase],Att1,Att2,Att3,Att4,Att5,Att6,Att7,Att8,Att9,Att10,Des1,Packing,'{2}' as CreateBy,getdate() as CreateDateTime,'{2}' as UpdateBy,getdate() as UpdateDateTime,Id as DoInId from Wh_TransDet where DoNo='{0}' and ProductCode='{4}' and LotNo='{5}' and DoType='SO' and LocationCode='{3}'
 ) as tab_aa where qty4>0  ", soNo, issueN, userId, location, product, lotNo);

                C2.Manager.ORManager.ExecuteCommand(sql);

                sql  = @"Insert Into Wh_DoDet2(DoNo,DoType,Product,Qty1,Qty2,Qty3,Price,LotNo,Uom1,Uom2,Uom3,Uom4,[QtyPackWhole],[QtyWholeLoose],[QtyLooseBase],[CreateBy],[CreateDateTime],[UpdateBy],[UpdateDateTime],Att1,Att2,Att3,Att4,Att5,Att6,Des1,Packing,Location,ProcessStatus)";
                sql += string.Format(@"select '{0}'as DoNo, 'OUT' as DoType,'{1}' as Sku
 ,'{2}' as Qty1
 ,0 as Qty2
 ,0 as Qty3
 ,'{3}' as Price
,'{4}' as LotNo
,ref.UomPacking as Uom1,ref.UomWhole as Uom2,ref.UomLoose as Uom3,ref.UomBase as Uom4
,ref.QtyPackingWhole as QtyPackWhole,ref.QtyWholeLoose as  QtyWholeLoose,ref.QtyLooseBase as QtyLooseBase
,'{5}' as CreateBy,getdate() as CreateDateTime,'{5}' as UpdateBy,getdate() as UpdateDateTime
,ref.Att4 as Att1,ref.Att5 as Att2,ref.att6 as Att3,ref.att7 as Att4,ref.att8 as Att5,ref.att9 as Att6,ref.Description as Des1,'' as Packing,'{6}' as Location,'Delivered' as ProcessStatus
from (select '{1}' as Sku) as tab inner join ref_product ref on ref.Code=tab.Sku", issueN, product, qty, price, lotNo, userId, location);
                C2.Manager.ORManager.ExecuteCommand(sql);
                InsertInv_Det(inv.SequenceId, inv.DocNo, i + 1, product, lotNo, des1, qty, price, inv.CurrencyId, inv.ExRate, 0, inv.MastRefNo, "", inv.MastType, "IV");
                UpdateMaster(inv.SequenceId);

                InsertInv_Det(inv_Do.SequenceId, inv_Do.DocNo, i + 1, product, lotNo, des1, qty, price, inv_Do.CurrencyId, inv_Do.ExRate, 0, inv_Do.MastRefNo, "", inv_Do.MastType, "IV");
                UpdateMaster(inv_Do.SequenceId);
                if (soNo.Length > 0)
                {
                    result = true;
                }
            }
            #endregion
            if (result)
            {
                e.Result = soNo;
            }
            else
            {
                e.Result = "Fail,Please keyin select product ";
            }
        }
    }
Esempio n. 4
0
    public static string Import_Order(string filePath)
    {
        XmlDocument xmlDoc = new XmlDocument();
        string      doNo   = "";
        string      doType = "";

        if (filePath.Length > 0)
        {
            xmlDoc.Load(filePath);
            if (xmlDoc.SelectSingleNode("Order") != null)
            {
                XmlElement elem   = (XmlElement)xmlDoc.SelectSingleNode("Order");
                string     id     = SafeValue.SafeString(elem.GetAttribute("Id"));
                string     relaId = SafeValue.SafeString(elem.GetAttribute("RelaId"));

                bool isNew = false;
                WhDo whDo  = null;
                if (id.Length > 0 && relaId.Length == 0)// from company to warehouse
                {
                    Wilson.ORMapper.OPathQuery query = new Wilson.ORMapper.OPathQuery(typeof(WhDo), "RelaId='" + id + "'");
                    whDo = C2.Manager.ORManager.GetObject(query) as WhDo;

                    if (whDo == null)
                    {
                        isNew       = true;
                        whDo        = new WhDo();
                        whDo.RelaId = id;
                        whDo.DoDate = DateTime.Today;


                        whDo.PartyId = SafeValue.SafeString(elem.GetAttribute("PartyId"));
                        //whDo.PartyId = EzshipHelper.GetPartyId(SafeValue.SafeString(elem.GetAttribute("PartyId")));
                        whDo.PartyName = SafeValue.SafeString(elem.GetAttribute("Party"));
                        whDo.PartyAdd  = SafeValue.SafeString(elem.GetAttribute("PartyAddress"));
                    }
                }
                else if (id.Length > 0 && relaId.Length > 0)// from warehouse to company
                {
                    Wilson.ORMapper.OPathQuery query = new Wilson.ORMapper.OPathQuery(typeof(WhDo), "Id='" + relaId + "'");
                    whDo = C2.Manager.ORManager.GetObject(query) as WhDo;
                    if (whDo == null)
                    {
                        return("");
                        //isNew = true;
                        //whDo = new WhDo();
                        //whDo.RelatId = id;
                    }
                }
                else
                {
                    return("");
                }

                doType = "IN";
                string runType = "DOIN";//SIF/SIL/SIC
                if (SafeValue.SafeString(elem.GetAttribute("OrderType")) == "OUT")
                {
                    doType  = "OUT";
                    runType = "DOOUT";
                }
                #region ref
                whDo.PoNo   = SafeValue.SafeString(elem.GetAttribute("PoNo"));
                whDo.PoDate = SafeValue.SafeDate(elem.GetAttribute("PoDate"), DateTime.Today);
                //whDo.PartyId = EzshipHelper.GetPartyId(SafeValue.SafeString(elem.GetAttribute("Party")));
                //whDo.PartyName = SafeValue.SafeString(elem.GetAttribute("Party"));
                //whDo.PartyAdd = SafeValue.SafeString(elem.GetAttribute("PartyAddress"));
                //whDo.PartyPostalcode = SafeValue.SafeString(elem.GetAttribute("PartyPostal"));
                //whDo.PartyCity = SafeValue.SafeString(elem.GetAttribute("PartyCity"));
                //whDo.PartyCountry = SafeValue.SafeString(elem.GetAttribute("PartyCountry"));

                whDo.Priority     = SafeValue.SafeString(elem.GetAttribute("Type"));
                whDo.ExpectedDate = SafeValue.SafeDate(elem.GetAttribute("ExpectedDate"), DateTime.Today);
                whDo.DoStatus     = SafeValue.SafeString(elem.GetAttribute("DoStatus"));
                whDo.Remark1      = SafeValue.SafeString(elem.GetAttribute("Remark1"));
                whDo.Remark2      = SafeValue.SafeString(elem.GetAttribute("Remark2"));
                whDo.CollectFrom  = SafeValue.SafeString(elem.GetAttribute("PickFrom"));
                whDo.DeliveryTo   = SafeValue.SafeString(elem.GetAttribute("DeliveryTo"));

                //whDo.CustomerReference = SafeValue.SafeString(elem.GetAttribute("CustomsRef"));
                //whDo.CustomerDate= SafeValue.SafeDate(elem.GetAttribute("RefDate"), new DateTime(1753, 1, 1));

                whDo.CustomerReference = SafeValue.SafeString(elem.GetAttribute("OrderNo"));
                whDo.CustomerDate      = SafeValue.SafeDate(elem.GetAttribute("OrderDate"), new DateTime(1753, 1, 1));

                whDo.PartyInvNo   = SafeValue.SafeString(elem.GetAttribute("PartyInvNo"));
                whDo.PartyInvDate = SafeValue.SafeDate(elem.GetAttribute("PartyInvDate"), new DateTime(1753, 5, 1));
                //permit no
                whDo.PermitNo           = SafeValue.SafeString(elem.GetAttribute("PermitNo"));
                whDo.PermitApprovalDate = SafeValue.SafeDate(elem.GetAttribute("PermitApprovalDate"), new DateTime(1753, 5, 1));
                whDo.TptMode            = SafeValue.SafeString(elem.GetAttribute("TptMode"));
                whDo.PalletizedInd      = SafeValue.SafeBool(elem.GetAttribute("PalletizedInd"), true);
                whDo.EquipNo            = SafeValue.SafeString(elem.GetAttribute("EquipNo"));
                whDo.Personnel          = SafeValue.SafeString(elem.GetAttribute("Personnel"));
                //shipment
                whDo.Vessel  = SafeValue.SafeString(elem.GetAttribute("Vessel"));
                whDo.Voyage  = SafeValue.SafeString(elem.GetAttribute("Voyage"));
                whDo.Obl     = SafeValue.SafeString(elem.GetAttribute("OceanBl"));
                whDo.Hbl     = SafeValue.SafeString(elem.GetAttribute("HouseBl"));
                whDo.Pol     = SafeValue.SafeString(elem.GetAttribute("Pol"));
                whDo.Pod     = SafeValue.SafeString(elem.GetAttribute("Pod"));
                whDo.Eta     = SafeValue.SafeDate(elem.GetAttribute("Eta"), new DateTime(1753, 1, 1));
                whDo.Etd     = SafeValue.SafeDate(elem.GetAttribute("Etd"), new DateTime(1753, 1, 1));
                whDo.EtaDest = SafeValue.SafeDate(elem.GetAttribute("EtaDest"), new DateTime(1753, 1, 1));
                whDo.Vehicle = SafeValue.SafeString(elem.GetAttribute("Vehicle"));
                whDo.Coo     = SafeValue.SafeString(elem.GetAttribute("Coo"));
                whDo.Carrier = SafeValue.SafeString(elem.GetAttribute("Carrier"));
                //party
                whDo.AgentId      = EzshipHelper.GetPartyId(SafeValue.SafeString(elem.GetAttribute("Agent")));
                whDo.AgentName    = SafeValue.SafeString(elem.GetAttribute("Agent"));
                whDo.AgentZip     = SafeValue.SafeString(elem.GetAttribute("AgentZip"));
                whDo.AgentAdd     = SafeValue.SafeString(elem.GetAttribute("AgentAddress"));
                whDo.AgentTel     = SafeValue.SafeString(elem.GetAttribute("AgentTel"));
                whDo.AgentContact = SafeValue.SafeString(elem.GetAttribute("AgentContact"));
                whDo.AgentCountry = SafeValue.SafeString(elem.GetAttribute("AgentCountry"));
                whDo.AgentCity    = SafeValue.SafeString(elem.GetAttribute("AgentCity"));

                whDo.NotifyId      = EzshipHelper.GetPartyId(SafeValue.SafeString(elem.GetAttribute("Notify")));
                whDo.NotifyName    = SafeValue.SafeString(elem.GetAttribute("Notify"));
                whDo.NotifyZip     = SafeValue.SafeString(elem.GetAttribute("NotifyZip"));
                whDo.NotifyAdd     = SafeValue.SafeString(elem.GetAttribute("NotifyAddress"));
                whDo.NotifyTel     = SafeValue.SafeString(elem.GetAttribute("NotifyTel"));
                whDo.NotifyContact = SafeValue.SafeString(elem.GetAttribute("NotifyContact"));
                whDo.NotifyCountry = SafeValue.SafeString(elem.GetAttribute("NotifyCountry"));
                whDo.NotifyCity    = SafeValue.SafeString(elem.GetAttribute("NotifyCity"));

                whDo.ConsigneeId      = EzshipHelper.GetPartyId(SafeValue.SafeString(elem.GetAttribute("Cnee")));
                whDo.ConsigneeName    = SafeValue.SafeString(elem.GetAttribute("Cnee"));
                whDo.ConsigneeZip     = SafeValue.SafeString(elem.GetAttribute("CneeZip"));
                whDo.ConsigneeAdd     = SafeValue.SafeString(elem.GetAttribute("CneeAddress"));
                whDo.ConsigneeTel     = SafeValue.SafeString(elem.GetAttribute("CneeTel"));
                whDo.ConsigneeContact = SafeValue.SafeString(elem.GetAttribute("CneeContact"));
                whDo.ConsigneeCountry = SafeValue.SafeString(elem.GetAttribute("CneeCountry"));
                whDo.ConsigneeCity    = SafeValue.SafeString(elem.GetAttribute("CneeCity"));
                whDo.PermitBy         = SafeValue.SafeString(elem.GetAttribute("PermitBy"));
                whDo.OtherPermit      = SafeValue.SafeString(elem.GetAttribute("OtherPermit"));
                whDo.ModelType        = SafeValue.SafeString(elem.GetAttribute("ModelType"));

                if (isNew)
                {
                    doNo                = C2Setup.GetNextNo("", runType, DateTime.Today);
                    whDo.DoNo           = doNo;
                    whDo.DoType         = doType;
                    whDo.StatusCode     = "USE";
                    whDo.CreateBy       = EzshipHelper.GetUserName();
                    whDo.CreateDateTime = DateTime.Today;
                    Manager.ORManager.StartTracking(whDo, Wilson.ORMapper.InitialState.Inserted);
                    Manager.ORManager.PersistChanges(whDo);
                    C2Setup.SetNextNo("", runType, doNo, whDo.DoDate);
                }
                else
                {
                    doNo                = whDo.DoNo;
                    whDo.UpdateBy       = EzshipHelper.GetUserName();
                    whDo.UpdateDateTime = DateTime.Now;
                    Manager.ORManager.StartTracking(whDo, Wilson.ORMapper.InitialState.Updated);
                    Manager.ORManager.PersistChanges(whDo);
                }

                #endregion

                #region Delete
                if (!isNew)
                {
                    string sql_del = string.Format(@"delete from Wh_DoDet where DoNo='{0}'", doNo);
                    SafeValue.SafeInt(C2.Manager.ORManager.ExecuteScalar(sql_del), 0);

                    sql_del = string.Format(@"delete from Wh_DoDet2 where DoNo='{0}'", doNo);
                    SafeValue.SafeInt(C2.Manager.ORManager.ExecuteScalar(sql_del), 0);

                    sql_del = string.Format(@"delete from Wh_DoDet3 where DoNo='{0}'", doNo);
                    SafeValue.SafeInt(C2.Manager.ORManager.ExecuteScalar(sql_del), 0);
                }
                #endregion

                #region sku
                XmlNodeList nodeListCont = elem.SelectNodes("Sku");
                foreach (XmlNode xnMkg in nodeListCont)
                {
                    XmlElement elemSku = (XmlElement)xnMkg;
                    if (elemSku.Name == "Sku")
                    {
                        WhDoDet det = new WhDoDet();
                        det.DoNo           = doNo;
                        det.DoType         = doType;
                        det.LotNo          = SafeValue.SafeString(elemSku.GetAttribute("LotNo"));
                        det.BatchNo        = SafeValue.SafeString(elemSku.GetAttribute("BatchNo"));
                        det.CustomsLot     = SafeValue.SafeString(elemSku.GetAttribute("CustomsLot"));
                        det.ProductCode    = SafeValue.SafeString(elemSku.GetAttribute("Sku"));
                        det.Des1           = SafeValue.SafeString(elemSku.GetAttribute("Des"));
                        det.Qty1           = SafeValue.SafeInt(elemSku.GetAttribute("PackQty"), 0);
                        det.Qty2           = SafeValue.SafeInt(elemSku.GetAttribute("WholeQty"), 0);
                        det.Qty3           = SafeValue.SafeInt(elemSku.GetAttribute("LooseQty"), 0);
                        det.Qty4           = SafeValue.SafeInt(elemSku.GetAttribute("Expected"), 0);
                        det.Qty5           = SafeValue.SafeInt(elemSku.GetAttribute("Transit"), 0);
                        det.QtyPackWhole   = SafeValue.SafeInt(elemSku.GetAttribute("QtyPackWhole"), 0);
                        det.QtyWholeLoose  = SafeValue.SafeInt(elemSku.GetAttribute("QtyWholeLoose"), 0);
                        det.QtyLooseBase   = SafeValue.SafeInt(elemSku.GetAttribute("QtyLooseBase"), 0);
                        det.Uom1           = SafeValue.SafeString(elemSku.GetAttribute("PackUom"));
                        det.Uom2           = SafeValue.SafeString(elemSku.GetAttribute("WholeUom"));
                        det.Uom3           = SafeValue.SafeString(elemSku.GetAttribute("LooseUom"));
                        det.Uom4           = SafeValue.SafeString(elemSku.GetAttribute("BaseUom"));
                        det.Att1           = SafeValue.SafeString(elemSku.GetAttribute("Att1"));
                        det.Att2           = SafeValue.SafeString(elemSku.GetAttribute("Att2"));
                        det.Att3           = SafeValue.SafeString(elemSku.GetAttribute("Att3"));
                        det.Att4           = SafeValue.SafeString(elemSku.GetAttribute("Att4"));
                        det.Att5           = SafeValue.SafeString(elemSku.GetAttribute("Att5"));
                        det.Att6           = SafeValue.SafeString(elemSku.GetAttribute("Att6"));
                        det.Att7           = SafeValue.SafeString(elemSku.GetAttribute("Att7"));
                        det.Att8           = SafeValue.SafeString(elemSku.GetAttribute("Att8"));
                        det.Att9           = SafeValue.SafeString(elemSku.GetAttribute("Att9"));
                        det.Att10          = SafeValue.SafeString(elemSku.GetAttribute("Att10"));
                        det.CreateBy       = EzshipHelper.GetUserName();
                        det.CreateDateTime = DateTime.Now;
                        det.UpdateBy       = EzshipHelper.GetUserName();
                        det.UpdateDateTime = DateTime.Now;

                        Manager.ORManager.StartTracking(det, Wilson.ORMapper.InitialState.Inserted);
                        Manager.ORManager.PersistChanges(det);
                    }
                }
                #endregion

                #region PutAway
                XmlNodeList nodeListCont1 = elem.SelectNodes("PutAway");
                foreach (XmlNode xnMkg in nodeListCont1)
                {
                    XmlElement elemPutAway = (XmlElement)xnMkg;
                    if (elemPutAway.Name == "PutAway")
                    {
                        WhDoDet2 det = new WhDoDet2();
                        det.DoNo   = doNo;
                        det.DoType = doType;

                        det.LotNo          = SafeValue.SafeString(elemPutAway.GetAttribute("LotNo"));
                        det.Product        = SafeValue.SafeString(elemPutAway.GetAttribute("Product"));
                        det.Des1           = SafeValue.SafeString(elemPutAway.GetAttribute("Des"));
                        det.BatchNo        = SafeValue.SafeString(elemPutAway.GetAttribute("BatchNo"));
                        det.CustomsLot     = SafeValue.SafeString(elemPutAway.GetAttribute("CustomsLot"));
                        det.Location       = SafeValue.SafeString(elemPutAway.GetAttribute("Location"));
                        det.ProcessStatus  = SafeValue.SafeString(elemPutAway.GetAttribute("ProcessStatus"));
                        det.Qty1           = SafeValue.SafeInt(elemPutAway.GetAttribute("PackQty"), 0);
                        det.Qty2           = SafeValue.SafeInt(elemPutAway.GetAttribute("WholeQty"), 0);
                        det.Qty3           = SafeValue.SafeInt(elemPutAway.GetAttribute("LooseQty"), 0);
                        det.QtyPackWhole   = SafeValue.SafeInt(elemPutAway.GetAttribute("QtyPackWhole"), 0);
                        det.QtyWholeLoose  = SafeValue.SafeInt(elemPutAway.GetAttribute("QtyWholeLoose"), 0);
                        det.QtyLooseBase   = SafeValue.SafeInt(elemPutAway.GetAttribute("QtyLooseBase"), 0);
                        det.Uom1           = SafeValue.SafeString(elemPutAway.GetAttribute("PackUom"));
                        det.Uom2           = SafeValue.SafeString(elemPutAway.GetAttribute("WholeUom"));
                        det.Uom3           = SafeValue.SafeString(elemPutAway.GetAttribute("LooseUom"));
                        det.Uom4           = SafeValue.SafeString(elemPutAway.GetAttribute("BaseUom"));
                        det.Att1           = SafeValue.SafeString(elemPutAway.GetAttribute("Att1"));
                        det.Att2           = SafeValue.SafeString(elemPutAway.GetAttribute("Att2"));
                        det.Att3           = SafeValue.SafeString(elemPutAway.GetAttribute("Att3"));
                        det.Att4           = SafeValue.SafeString(elemPutAway.GetAttribute("Att4"));
                        det.Att5           = SafeValue.SafeString(elemPutAway.GetAttribute("Att5"));
                        det.Att6           = SafeValue.SafeString(elemPutAway.GetAttribute("Att6"));
                        det.Att7           = SafeValue.SafeString(elemPutAway.GetAttribute("Att7"));
                        det.Att8           = SafeValue.SafeString(elemPutAway.GetAttribute("Att8"));
                        det.Att9           = SafeValue.SafeString(elemPutAway.GetAttribute("Att9"));
                        det.Att10          = SafeValue.SafeString(elemPutAway.GetAttribute("Att10"));
                        det.CreateBy       = EzshipHelper.GetUserName();
                        det.CreateDateTime = DateTime.Now;
                        det.UpdateBy       = EzshipHelper.GetUserName();
                        det.UpdateDateTime = DateTime.Now;

                        Manager.ORManager.StartTracking(det, Wilson.ORMapper.InitialState.Inserted);
                        Manager.ORManager.PersistChanges(det);
                    }
                }
                #endregion

                #region Container
                XmlNodeList nodeListCont2 = elem.SelectNodes("Container");
                foreach (XmlNode xnMkg in nodeListCont2)
                {
                    XmlElement elemContainer = (XmlElement)xnMkg;
                    if (elemContainer.Name == "Container")
                    {
                        WhDoDet3 det = new WhDoDet3();
                        det.DoNo   = doNo;
                        det.DoType = doType;

                        det.ContainerNo    = SafeValue.SafeString(elemContainer.GetAttribute("ContainerNo"));
                        det.ContainerType  = SafeValue.SafeString(elemContainer.GetAttribute("ContainerType"));
                        det.SealNo         = SafeValue.SafeString(elemContainer.GetAttribute("SealNo"));
                        det.Weight         = SafeValue.SafeDecimal(elemContainer.GetAttribute("Weight"));
                        det.M3             = SafeValue.SafeDecimal(elemContainer.GetAttribute("M3"));
                        det.Qty            = SafeValue.SafeInt(elemContainer.GetAttribute("Qty"), 0);
                        det.PkgType        = SafeValue.SafeString(elemContainer.GetAttribute("PkgType"));
                        det.CreateBy       = EzshipHelper.GetUserName();
                        det.CreateDateTime = DateTime.Now;
                        det.UpdateBy       = EzshipHelper.GetUserName();
                        det.UpdateDateTime = DateTime.Now;
                        Manager.ORManager.StartTracking(det, Wilson.ORMapper.InitialState.Inserted);
                        Manager.ORManager.PersistChanges(det);
                    }
                }
                #endregion
            }
        }
        return("Type=" + doType + " , " + "No=" + doNo);
    }
Esempio n. 5
0
    protected void grid_CustomDataCallback(object sender, ASPxGridViewCustomDataCallbackEventArgs e)
    {
        string s = e.Parameters;

        if (s == "Save")
        {
            if (list.Count > 0)
            {
                string value    = "";
                string variable = "";
                for (int i = 0; i < list.Count; i++)
                {
                    int    newQty  = list[i].qty;
                    string id      = list[i].id;
                    string product = list[i].sku;
                    string lot     = list[i].lotNo;
                    string sql     = string.Format(@"update StockCountDet set NewQty=-{0} where Id='{1}'", newQty, id);
                    ConnectSql.ExecuteSql(sql);
                    ASPxTextBox txt_DoNo = this.grid.FindRowCellTemplateControl(i, (DevExpress.Web.ASPxGridView.GridViewDataColumn) this.grid.Columns["Product"], "txt_DoNo") as ASPxTextBox;

                    string    doNo   = SafeValue.SafeString(txt_DoNo.Text);
                    string    sql_do = string.Format(@"select distinct det2.Id,det2.Product,det2.LotNo,det2.Price,det2.Location,mast.PartyId,mast.PartyName,mast.PartyAdd,mast.WarehouseId 
from wh_dodet2 det2 inner join wh_do mast on mast.DoNo=det2.DoNo where mast.DoNo='{0}' and Product='{1}' and LotNo='{2}'", doNo, product, lot);
                    DataTable dt     = ConnectSql.GetTab(sql_do);

                    if (variable != doNo)
                    {
                        WhDo   whDo   = new WhDo();
                        string issueN = C2Setup.GetNextNo("", "DOOUT", DateTime.Today);
                        whDo.DoDate      = DateTime.Now;
                        whDo.DoType      = "OUT";
                        whDo.PartyId     = SafeValue.SafeString(dt.Rows[i]["PartyId"]);
                        whDo.PartyName   = SafeValue.SafeString(dt.Rows[i]["PartyName"]);
                        whDo.PartyAdd    = SafeValue.SafeString(dt.Rows[i]["PartyAdd"]);
                        whDo.DeliveryTo  = SafeValue.SafeString(dt.Rows[i]["PartyAdd"]);
                        whDo.WareHouseId = SafeValue.SafeString(dt.Rows[i]["WareHouseId"]);
                        string userId = HttpContext.Current.User.Identity.Name;
                        whDo.CreateBy       = userId;
                        whDo.CreateDateTime = DateTime.Now;
                        whDo.UpdateBy       = userId;
                        whDo.UpdateDateTime = DateTime.Now;
                        whDo.DoNo           = issueN;
                        whDo.StatusCode     = "CLS";

                        C2Setup.SetNextNo("", "DOOUT", issueN, whDo.DoDate);
                        Manager.ORManager.StartTracking(whDo, Wilson.ORMapper.InitialState.Inserted);
                        Manager.ORManager.PersistChanges(whDo);

                        value = issueN;
                    }

                    for (int j = 0; j < dt.Rows.Count; j++)
                    {
                        string  sku   = SafeValue.SafeString(dt.Rows[j]["Product"]);
                        string  lotNo = SafeValue.SafeString(dt.Rows[j]["LotNo"]);
                        decimal price = SafeValue.SafeDecimal(dt.Rows[j]["Price"]);
                        string  loc   = SafeValue.SafeString(dt.Rows[j]["Location"]);
                        int     detId = SafeValue.SafeInt(dt.Rows[j]["Id"], 0);
                        TransferToDo(value, sku, lotNo, newQty, price, loc, "", detId, loc);
                    }
                    variable = doNo;
                }

                e.Result = "Success";
                btn_Sch_Click(null, null);
            }
            else
            {
                //e.Result = "Please keyin select product";
            }
        }
    }