示例#1
0
    protected void grid_contact_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
        string partyId = Request.QueryString["partyId"].ToString();

        e.NewValues["PartyId"]    = partyId;
        e.NewValues["PartyName"]  = EzshipHelper.GetPartyName(partyId);
        e.NewValues["IsDefault"]  = SafeValue.SafeBool(e.NewValues["IsDefault"], true);
        e.NewValues["Department"] = SafeValue.SafeString(e.NewValues["Department"]);
    }
示例#2
0
    protected void grid_contact_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
        ASPxPageControl pageControl = this.grid.FindEditFormTemplateControl("pageControl") as ASPxPageControl;
        ASPxTextBox     txtPartyId  = pageControl.FindControl("txtPartyId") as ASPxTextBox;
        ASPxTextBox     txtName     = pageControl.FindControl("txtName") as ASPxTextBox;

        e.NewValues["PartyId"]   = txtPartyId.Text;
        e.NewValues["PartyName"] = txtName.Text;
        e.NewValues["IsDefault"] = SafeValue.SafeBool(e.NewValues["IsDefault"], true);
    }
示例#3
0
    protected void grid_det_HtmlEditFormCreated(object sender, ASPxGridViewEditFormEventArgs e)
    {
        ASPxGridView grid = sender as ASPxGridView;

        if (grid.EditingRowVisibleIndex > -1)
        {
            #region
            bool isDaily = SafeValue.SafeBool(grid.GetRowValues(grid.EditingRowVisibleIndex, new string[] { "IsDaily" }), false);
            if (isDaily)
            {
                ASPxSpinEdit dailyNo = grid.FindEditRowCellTemplateControl(null, "spin_det_DailyNo") as ASPxSpinEdit;
                dailyNo.ClientEnabled = false;
            }
            #endregion
        }
    }
示例#4
0
 protected void grid_det_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
 {
     e.NewValues["IsFixed"]   = SafeValue.SafeBool(e.NewValues["IsFixed"], false);
     e.NewValues["IsYearly"]  = SafeValue.SafeBool(e.NewValues["IsYearly"], false);
     e.NewValues["IsMonthly"] = SafeValue.SafeBool(e.NewValues["IsMonthly"], false);
     e.NewValues["IsWeekly"]  = SafeValue.SafeBool(e.NewValues["IsWeekly"], false);
     e.NewValues["IsDaily"]   = SafeValue.SafeBool(e.NewValues["IsDaily"], false);
     //e.NewValues["Price1"] = SafeValue.SafeDecimal(e.NewValues["Price1"], 0);
     //e.NewValues["Price2"] = SafeValue.SafeDecimal(e.NewValues["Price2"], 0);
     //e.NewValues["Price3"] = SafeValue.SafeDecimal(e.NewValues["Price3"], 0);
     e.NewValues["DailyNo"]      = SafeValue.SafeInt(e.NewValues["DailyNo"], 1);
     e.NewValues["ProductCode"]  = SafeValue.SafeString(e.NewValues["ProductCode"]);
     e.NewValues["ProductClass"] = SafeValue.SafeString(e.NewValues["ProductClass"]);
     e.NewValues["HandlingFee"]  = SafeValue.SafeDecimal(e.NewValues["HandlingFee"], 0);
     e.NewValues["StorageFee"]   = SafeValue.SafeDecimal(e.NewValues["StorageFee"], 0);
 }
示例#5
0
    protected void grid_contact_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    {
        string partyId = Request.QueryString["partyId"].ToString();

        e.NewValues["PartyId"]    = partyId;
        e.NewValues["PartyName"]  = EzshipHelper.GetPartyName(partyId);
        e.NewValues["IsDefault"]  = SafeValue.SafeBool(e.NewValues["IsDefault"], true);
        e.NewValues["Name"]       = SafeValue.SafeString(e.NewValues["Name"]);
        e.NewValues["Tel"]        = SafeValue.SafeString(e.NewValues["Tel"]);
        e.NewValues["Fax"]        = SafeValue.SafeString(e.NewValues["Fax"]);
        e.NewValues["Address"]    = SafeValue.SafeString(e.NewValues["Address"]);
        e.NewValues["Email"]      = SafeValue.SafeString(e.NewValues["Email"]);
        e.NewValues["Mobile"]     = SafeValue.SafeString(e.NewValues["Mobile"]);
        e.NewValues["Remark"]     = SafeValue.SafeString(e.NewValues["Remark"]);
        e.NewValues["Department"] = SafeValue.SafeString(e.NewValues["Department"]);
    }
示例#6
0
    protected void grid_contact_RowUpdated(object sender, DevExpress.Web.Data.ASPxDataUpdatedEventArgs e)
    {
        string partyId   = SafeValue.SafeString(e.NewValues["PartyId"]);
        string id        = SafeValue.SafeString(e.Keys["Id"]);
        bool   isDefault = SafeValue.SafeBool(e.NewValues["IsDefault"], true);

        if (isDefault == true)
        {
            string sql = string.Format(@"update ref_contact set IsDefault=0 where PartyId='{0}' and Id!={1}", partyId, id);
            ConnectSql_mb.ExecuteNonQuery(sql);
        }
        else
        {
            string sql = string.Format(@"update ref_contact set IsDefault=1 where PartyId='{0}' and Id=(select top 1 Id from ref_contact where PartyId='{0}')", partyId);
            ConnectSql_mb.ExecuteNonQuery(sql);
        }
    }
示例#7
0
    protected void grid_contact_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    {
        ASPxPageControl pageControl = this.grid.FindEditFormTemplateControl("pageControl") as ASPxPageControl;
        ASPxTextBox     txtPartyId  = pageControl.FindControl("txtPartyId") as ASPxTextBox;
        ASPxTextBox     txtName     = pageControl.FindControl("txtName") as ASPxTextBox;

        e.NewValues["PartyId"]   = txtPartyId.Text;
        e.NewValues["PartyName"] = txtName.Text;
        e.NewValues["IsDefault"] = SafeValue.SafeBool(e.NewValues["IsDefault"], true);
        e.NewValues["Name"]      = SafeValue.SafeString(e.NewValues["Name"]);
        e.NewValues["Tel"]       = SafeValue.SafeString(e.NewValues["Tel"]);
        e.NewValues["Fax"]       = SafeValue.SafeString(e.NewValues["Fax"]);
        e.NewValues["Address"]   = SafeValue.SafeString(e.NewValues["Address"]);
        e.NewValues["Email"]     = SafeValue.SafeString(e.NewValues["Email"]);
        e.NewValues["Mobile"]    = SafeValue.SafeString(e.NewValues["Mobile"]);
        e.NewValues["Remark"]    = SafeValue.SafeString(e.NewValues["Remark"]);
    }
示例#8
0
    protected void grid_contact_RowInserted(object sender, DevExpress.Web.Data.ASPxDataInsertedEventArgs e)
    {
        ASPxGridView grd       = (sender as ASPxGridView) as ASPxGridView;
        string       partyId   = SafeValue.SafeString(e.NewValues["PartyId"]);
        string       sql       = string.Format(@"select top 1 Id from ref_contact where PartyId='{0}' order by Id desc", partyId);
        string       id        = SafeValue.SafeString(ConnectSql_mb.ExecuteScalar(sql), "0");
        bool         isDefault = SafeValue.SafeBool(e.NewValues["IsDefault"], true);

        if (isDefault == true)
        {
            sql = string.Format(@"update ref_contact set IsDefault=0 where PartyId='{0}' and Id!={1}", partyId, id);
            ConnectSql_mb.ExecuteNonQuery(sql);
        }
        else
        {
            sql = string.Format(@"update ref_contact set IsDefault=1 where PartyId='{0}' and Id=(select top 1 Id from ref_contact where PartyId='{0}')", partyId);
            ConnectSql_mb.ExecuteNonQuery(sql);
        }
    }
示例#9
0
 protected void gridPersonDet3_HtmlEditFormCreated(object sender, ASPxGridViewEditFormEventArgs e)
 {
     if (this.grid.EditingRowVisibleIndex > -1)
     {
         ASPxGridView grd          = sender as ASPxGridView;
         ASPxCheckBox isPayroll    = grd.FindEditFormTemplateControl("ckb_IsPayroll") as ASPxCheckBox;
         bool         oldIsPayroll = SafeValue.SafeBool(grid.GetRowValues(this.grid.EditingRowVisibleIndex, new string[] { "IsPayroll" }), false);
         if (isPayroll != null)
         {
             if (oldIsPayroll)
             {
                 isPayroll.Checked = true;
             }
             else
             {
                 isPayroll.Checked = false;
             }
         }
     }
 }
示例#10
0
    protected void grid_det_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
        ASPxGridView    grid        = (sender as ASPxGridView) as ASPxGridView;
        ASPxPageControl pageControl = this.grid.FindEditFormTemplateControl("pageControl") as ASPxPageControl;
        ASPxTextBox     txt_RefNo   = pageControl.FindControl("txt_RefNo") as ASPxTextBox;

        e.NewValues["ContractNo"]   = SafeValue.SafeString(txt_RefNo.Text);
        e.NewValues["IsFixed"]      = SafeValue.SafeBool(e.NewValues["IsFixed"], false);
        e.NewValues["IsYearly"]     = SafeValue.SafeBool(e.NewValues["IsYearly"], false);
        e.NewValues["IsMonthly"]    = SafeValue.SafeBool(e.NewValues["IsMonthly"], false);
        e.NewValues["IsWeekly"]     = SafeValue.SafeBool(e.NewValues["IsWeekly"], false);
        e.NewValues["IsDaily"]      = SafeValue.SafeBool(e.NewValues["IsDaily"], false);
        e.NewValues["ProductCode"]  = SafeValue.SafeString(e.NewValues["ProductCode"]);
        e.NewValues["ProductClass"] = SafeValue.SafeString(e.NewValues["ProductClass"]);
        e.NewValues["DailyNo"]      = SafeValue.SafeInt(e.NewValues["DailyNo"], 1);
        //e.NewValues["Price1"] = SafeValue.SafeDecimal(e.NewValues["Price1"], 0);
        //e.NewValues["Price2"] = SafeValue.SafeDecimal(e.NewValues["Price2"], 0);
        //e.NewValues["Price3"] = SafeValue.SafeDecimal(e.NewValues["Price3"], 0);
        e.NewValues["HandlingFee"] = SafeValue.SafeDecimal(e.NewValues["HandlingFee"], 0);
        e.NewValues["StorageFee"]  = SafeValue.SafeDecimal(e.NewValues["StorageFee"], 0);
    }
示例#11
0
    protected void AddOrUpdate()
    {
        try
        {
            ASPxTextBox txt_SequenceId       = this.ASPxGridView1.FindEditFormTemplateControl("txt_SequenceId") as ASPxTextBox;
            ASPxTextBox txtPartyId           = this.ASPxGridView1.FindEditFormTemplateControl("txtPartyId") as ASPxTextBox;
            ASPxTextBox txtCode              = this.ASPxGridView1.FindEditFormTemplateControl("txtCode") as ASPxTextBox;
            ASPxLabel   lblMess              = this.ASPxGridView1.FindEditFormTemplateControl("lblMessage") as ASPxLabel;
            string      sequenceId           = SafeValue.SafeString(txt_SequenceId.Text, "");
            string      partyId              = SafeValue.SafeString(txtPartyId.Text, "");
            Wilson.ORMapper.OPathQuery query = new Wilson.ORMapper.OPathQuery(typeof(XXParty), "SequenceId='" + sequenceId + "'");
            XXParty party  = C2.Manager.ORManager.GetObject(query) as XXParty;
            bool    action = false;
            bool    autoNo = false;
            if (party == null)
            {
                action = true;
                party  = new XXParty();
                if (partyId.Length == 0 || partyId == "NEW")
                {
                    partyId = C2Setup.GetNextNo("BusinessParty");
                    autoNo  = true;
                }
                else
                {
                    partyId = partyId.Replace(" ", "_");
                    string sql = string.Format("select count(PartyId) from XXParty where PartyId='{0}'", partyId);
                    int    cnt = SafeValue.SafeInt(C2.Manager.ORManager.ExecuteScalar(sql), 0);
                    if (cnt > 0)
                    {
                        throw new Exception(string.Format("Duplicate PartyId!"));
                        return;
                    }
                }
                party.PartyId = partyId;
            }
            party.Code = txtCode.Text;
            ASPxTextBox txtName = this.ASPxGridView1.FindEditFormTemplateControl("txtName") as ASPxTextBox;
            string      name    = txtName.Text.Trim();
            if (txtName.Text == "")
            {
                throw new Exception("Full Name not be null!!!");
                return;
            }
            party.Name = name;
            ASPxLabel lblStatus = this.ASPxGridView1.FindEditFormTemplateControl("lblStatus") as ASPxLabel;
            party.Status = "USE";
            ASPxCheckBox Customer = this.ASPxGridView1.FindEditFormTemplateControl("Customer") as ASPxCheckBox;
            ASPxCheckBox Vendor   = this.ASPxGridView1.FindEditFormTemplateControl("Vendor") as ASPxCheckBox;
            ASPxCheckBox Agent    = this.ASPxGridView1.FindEditFormTemplateControl("Agent") as ASPxCheckBox;
            party.IsCustomer = SafeValue.SafeBool(Customer.Checked, false);

            party.IsVendor = SafeValue.SafeBool(Vendor.Checked, false);
            party.IsAgent  = SafeValue.SafeBool(Agent.Checked, false);
            ASPxMemo memoAddress = this.ASPxGridView1.FindEditFormTemplateControl("txtAddress") as ASPxMemo;
            party.Address = memoAddress.Text;
            ASPxTextBox crNo = this.ASPxGridView1.FindEditFormTemplateControl("txtCrNo") as ASPxTextBox;
            party.CrNo = crNo.Text;
            ASPxTextBox txtTel1 = this.ASPxGridView1.FindEditFormTemplateControl("txtTel1") as ASPxTextBox;
            party.Tel1 = txtTel1.Text;
            ASPxTextBox txtFax1 = this.ASPxGridView1.FindEditFormTemplateControl("txtFax1") as ASPxTextBox;
            party.Fax1 = txtFax1.Text;
            ASPxTextBox txtTel2 = this.ASPxGridView1.FindEditFormTemplateControl("txtTel2") as ASPxTextBox;
            party.Tel2 = txtTel2.Text;
            ASPxTextBox txtFax2 = this.ASPxGridView1.FindEditFormTemplateControl("txtFax2") as ASPxTextBox;
            party.Fax2 = txtFax2.Text;
            ASPxTextBox txtContact1 = this.ASPxGridView1.FindEditFormTemplateControl("txtContact1") as ASPxTextBox;
            party.Contact1 = txtContact1.Text;
            ASPxTextBox txtContact2 = this.ASPxGridView1.FindEditFormTemplateControl("txtContact2") as ASPxTextBox;
            party.Contact2 = txtContact2.Text;
            ASPxTextBox txtEmail1 = this.ASPxGridView1.FindEditFormTemplateControl("txtEmail1") as ASPxTextBox;
            party.Email1 = txtEmail1.Text;
            ASPxTextBox txtEmail2 = this.ASPxGridView1.FindEditFormTemplateControl("txtEmail2") as ASPxTextBox;
            party.Email2 = txtEmail2.Text;
            ASPxTextBox txt_ZipCode = this.ASPxGridView1.FindEditFormTemplateControl("txt_ZipCode") as ASPxTextBox;
            party.ZipCode = txt_ZipCode.Text;
            ASPxComboBox cbCountry = this.ASPxGridView1.FindEditFormTemplateControl("cbCountry") as ASPxComboBox;
            party.CountryId = SafeValue.SafeString(cbCountry.Value);
            ASPxComboBox cbCity = this.ASPxGridView1.FindEditFormTemplateControl("cbCity") as ASPxComboBox;
            party.City = SafeValue.SafeString(cbCity.Value);
            ASPxComboBox cbPort = this.ASPxGridView1.FindEditFormTemplateControl("cbPort") as ASPxComboBox;
            party.PortId = SafeValue.SafeString(cbPort.Value);
            ASPxComboBox cbTerm = this.ASPxGridView1.FindEditFormTemplateControl("cbTerm") as ASPxComboBox;
            party.TermId = SafeValue.SafeString(cbTerm.Value);
            ASPxComboBox cbGroup = this.ASPxGridView1.FindEditFormTemplateControl("cbGroup") as ASPxComboBox;
            party.GroupId = SafeValue.SafeString(cbGroup.Value);
            ASPxMemo memoRemark = this.ASPxGridView1.FindEditFormTemplateControl("memoRemark") as ASPxMemo;
            party.Remark = memoRemark.Text;

            ASPxSpinEdit spin_WarningAmt = this.ASPxGridView1.FindEditFormTemplateControl("spin_WarningAmt") as ASPxSpinEdit;
            party.WarningAmt = SafeValue.SafeDecimal(spin_WarningAmt.Value);
            ASPxSpinEdit spin_WarningQty = this.ASPxGridView1.FindEditFormTemplateControl("spin_WarningQty") as ASPxSpinEdit;
            party.WarningQty = SafeValue.SafeInt(spin_WarningQty.Value, 0);
            ASPxSpinEdit spin_BlockAmt = this.ASPxGridView1.FindEditFormTemplateControl("spin_BlockAmt") as ASPxSpinEdit;
            party.BlockAmt = SafeValue.SafeDecimal(spin_BlockAmt.Value);
            ASPxSpinEdit spin_BlockQty = this.ASPxGridView1.FindEditFormTemplateControl("spin_BlockQty") as ASPxSpinEdit;
            party.BlockQty = SafeValue.SafeInt(spin_BlockQty.Value, 0);

            //ASPxButtonEdit txt_ParentId =this.ASPxGridView1.FindEditFormTemplateControl("txt_ParentId") as ASPxButtonEdit;
            //party.ParentId = txt_ParentId.Text;
            //ASPxTextBox txt_ParentName =this.ASPxGridView1.FindEditFormTemplateControl("txt_ParentName") as ASPxTextBox;
            //party.ParentName = txt_ParentName.Text;
            if (action)
            {
                party.CreateBy       = HttpContext.Current.User.Identity.Name;
                party.CreateDateTime = DateTime.Now;
                if (autoNo)
                {
                    C2Setup.SetNextNo("BusinessParty", partyId);
                }
                Manager.ORManager.StartTracking(party, Wilson.ORMapper.InitialState.Inserted);
                Manager.ORManager.PersistChanges(party);

                txtPartyId.Text = partyId.ToString();
                XXPartyAcc acc = new XXPartyAcc();
                acc.ApCode     = System.Configuration.ConfigurationManager.AppSettings["LocalArCode"];
                acc.ArCode     = System.Configuration.ConfigurationManager.AppSettings["LocalApCode"];
                acc.CurrencyId = System.Configuration.ConfigurationManager.AppSettings["Currency"];
                acc.PartyId    = party.PartyId;
                Manager.ORManager.StartTracking(acc, Wilson.ORMapper.InitialState.Inserted);
                Manager.ORManager.PersistChanges(acc);
            }
            else
            {
                party.UpdateBy       = HttpContext.Current.User.Identity.Name;
                party.UpdateDateTime = DateTime.Now;
                Manager.ORManager.StartTracking(party, Wilson.ORMapper.InitialState.Updated);
                Manager.ORManager.PersistChanges(party);
            }
            Session["NameWhere"]            = "PartyId='" + party.PartyId + "'";
            this.dsXXParty.FilterExpression = Session["NameWhere"].ToString();
            if (this.ASPxGridView1.GetRow(0) != null)
            {
                this.ASPxGridView1.StartEdit(0);
            }
        }
        catch (Exception ex) { throw new Exception(ex.Message); }
    }
示例#12
0
    public static DataSet DsImpTs_Pre(string orderNo, string userName)
    {
        DataTable mast    = InitTsMastDataTable();
        DataTable details = InitTsDetailDataTable();

        string    sql_Order = string.Format("select Vessel,Voyage,CarrierBkgNo,EtaDate,ClientContact,ClientRefNo,Pol,PartyId,AdditionalRemark,CreateBy,IssuedBy from ctm_job where JobNo='{0}'", orderNo);
        DataTable tab_Order = Helper.Sql.List(sql_Order);

        if (tab_Order.Rows.Count == 1)
        {
            DataRow row_Order = tab_Order.Rows[0];
            #region tally sheet
            DataRow row = mast.NewRow();
            row["JobOrderNo"] = orderNo;
            row["VesselNo"]   = row_Order["Vessel"];
            row["BookingNo"]  = row_Order["CarrierBkgNo"];
            row["VoyNo"]      = row_Order["Voyage"];


            row["Eta"]      = SafeValue.SafeDateStr(row_Order["EtaDate"]);
            row["ByWho"]    = row_Order["ClientContact"];
            row["ImpRefNo"] = row_Order["ClientRefNo"];
            string sql = "select name from XXPort where Code='" + SafeValue.SafeString(row_Order["Pol"], "") + "'";
            row["PortLoad"]  = SafeValue.SafeString(row_Order["Pol"], ""); //SafeValue.SafeString(Helper.Sql.One(sql), "");
            sql              = "select name from xxparty where partyid='" + row_Order["PartyId"] + "'";
            row["CustName"]  = row_Order["PartyId"];                       //SafeValue.SafeString(Helper.Sql.One(sql), "");
            row["Condition"] = row_Order["AdditionalRemark"];
            row["UserData1"] = row_Order["CreateBy"];
            row["IssueBy"]   = row_Order["IssuedBy"];
            row["UserName"]  = userName;
            mast.Rows.Add(row);

            string    sql_JobDet = string.Format(@"select DoNo,CargoType,ContNo,SealNo,IsDg,BookingNo,HblNo,Marking2
,Qty,UomCode,PackTypeOrig,Volume,Weight,QtyOrig,VolumeOrig,WeightOrig, POD
,Remark1,DgClass,Desc2 from job_house where JobNo='{0}' order by ContNo,LineId,IsDg,DoNo", orderNo);
            DataTable tab_Det    = Helper.Sql.List(sql_JobDet);
            int       g0         = 0;
            int       g1         = 0;
            int       g2         = 0;
            int       p          = 0;
            string    lastContNo = "";

            bool lastDg = false;
            for (int i = 0; i < tab_Det.Rows.Count; i++)
            {
                DataRow row_Det = tab_Det.Rows[i];
                DataRow row1    = details.NewRow();
                string  dnNo    = row_Det["DoNo"].ToString();
                string  jobType = "";
                string  contNo  = row_Det["ContNo"].ToString();
                string  sealNo  = row_Det["SealNo"].ToString();
                bool    isDg    = SafeValue.SafeBool(row_Det["IsDg"], false);
                string  dgClass = row_Det["DgClass"].ToString();
                string  expBkgN = row_Det["BookingNo"].ToString();
                string  hblN    = row_Det["HblNo"].ToString();
                string  mkg     = row_Det["Marking2"].ToString();
                string  rmk     = row_Det["Remark1"].ToString();
                string  desc2   = row_Det["Desc2"].ToString();
                string  pod     = "";

                //int tally1 = SafeValue.SafeInt(row_Det["Tally1"], 0);
                //int tally2 = SafeValue.SafeInt(row_Det["Tally2"], 0);
                //int tally3 = SafeValue.SafeInt(row_Det["Tally3"], 0);
                //int tally4 = SafeValue.SafeInt(row_Det["Tally4"], 0);
                //int tally21 = SafeValue.SafeInt(row_Det["Tally21"], 0);
                //int tally22 = SafeValue.SafeInt(row_Det["Tally22"], 0);
                //int tally23 = SafeValue.SafeInt(row_Det["Tally23"], 0);
                //int tally24 = SafeValue.SafeInt(row_Det["Tally24"], 0);
                //int tally31 = SafeValue.SafeInt(row_Det["Tally31"], 0);
                //int tally32 = SafeValue.SafeInt(row_Det["Tally32"], 0);
                //int tally33 = SafeValue.SafeInt(row_Det["Tally33"], 0);
                //int tally34 = SafeValue.SafeInt(row_Det["Tally34"], 0);
                //int tally41 = SafeValue.SafeInt(row_Det["Tally41"], 0);
                //int tally42 = SafeValue.SafeInt(row_Det["Tally42"], 0);
                //int tally43 = SafeValue.SafeInt(row_Det["Tally43"], 0);
                //int tally44 = SafeValue.SafeInt(row_Det["Tally44"], 0);
                //int tally51 = SafeValue.SafeInt(row_Det["Tally51"], 0);
                //int tally52 = SafeValue.SafeInt(row_Det["Tally52"], 0);
                //int tally53 = SafeValue.SafeInt(row_Det["Tally53"], 0);
                //int tally54 = SafeValue.SafeInt(row_Det["Tally54"], 0);
                //int tally61 = SafeValue.SafeInt(row_Det["Tally61"], 0);
                //int tally62 = SafeValue.SafeInt(row_Det["Tally62"], 0);
                //int tally63 = SafeValue.SafeInt(row_Det["Tally63"], 0);
                //int tally64 = SafeValue.SafeInt(row_Det["Tally64"], 0);

                int     qty      = SafeValue.SafeInt(row_Det["Qty"], 0);
                decimal wt       = SafeValue.SafeDecimal(row_Det["Weight"], 0);
                decimal m3       = SafeValue.SafeDecimal(row_Det["Volume"], 0);
                string  pkgType  = SafeValue.SafeString(row_Det["UomCode"], "");
                string  pkgType2 = SafeValue.SafeString(row_Det["PackTypeOrig"], "");
                int     qtyOrig  = SafeValue.SafeInt(row_Det["QtyOrig"], 0);
                decimal wtOrig   = SafeValue.SafeDecimal(row_Det["WeightOrig"], 0);
                decimal m3Orig   = SafeValue.SafeDecimal(row_Det["VolumeOrig"], 0);

                if ((contNo == lastContNo & isDg == lastDg) || lastContNo == "")
                {
                    g2++;
                }
                else
                {
                    g0++;
                    g1 = 1;
                    g2 = 1;
                    p  = 0;
                }
                lastContNo         = contNo;
                lastDg             = isDg;
                row1["JobOrderNo"] = orderNo;
                p++;
                row1["LineN"] = p;

                row1["PrintGroup"]    = string.Format("C{0:00}{1:00}", g0, g1);
                row1["PrintSesseion"] = string.Format("C{0:00}", g0);
                if (g2 % 6 == 0)
                {
                    g1++;
                }
                row1["ContNo"] = contNo;
                row1["SealNo"] = sealNo;
                //string sql_cont = string.Format("select ContNo,SealNo,Ft20,Ft40,Ft45,FtType,scheduleDate,ScheduleTime,ActualDate,ActualTime,TallyClerk,FlDriver from xwjobcont where JobOrder='{0}' and ContNo='{1}'", orderNo, contNo);
                //DataTable tab_cont = Helper.Sql.List(sql_cont);
                //if (tab_cont.Rows.Count > 0)
                //{
                //    row1["SealNo"] = SafeValue.SafeString(tab_cont.Rows[0]["SealNo"], "");
                //    row1["FtType"] = SafeValue.SafeString(tab_cont.Rows[0]["FtType"], "");
                //    row1["SchDate"] = SafeValue.SafeDateStr(tab_cont.Rows[0]["ScheduleDate"]);
                //    row1["ComplDate"] = SafeValue.SafeDateStr(tab_cont.Rows[0]["ActualDate"]);
                //    string time = SafeValue.SafeString(tab_cont.Rows[0]["ScheduleTime"], "");
                //    string time1 = SafeValue.SafeString(tab_cont.Rows[0]["ActualTime"], "");
                //    if (time.Trim().Length > 0)
                //    {
                //        row1["SchTime"] = time;
                //    }
                //    if (time1.Trim().Length > 0)
                //        row1["ComplTime"] = time1;
                //    string size = "";
                //    if (SafeValue.SafeInt(tab_cont.Rows[0]["Ft20"], 0) > 0)
                //        size = "20";
                //    else if (SafeValue.SafeInt(tab_cont.Rows[0]["Ft40"], 0) > 0)
                //        size = "40";
                //    else if (SafeValue.SafeInt(tab_cont.Rows[0]["Ft45"], 0) > 0)
                //        size = "45";
                //    row1["Size"] = size;
                //    row1["TallyClerk"] = SafeValue.SafeString(tab_cont.Rows[0]["TallyClerk"], "");
                //    row1["Driver"] = SafeValue.SafeString(tab_cont.Rows[0]["FlDriver"], "");
                //}
                row1["DnNO"]       = dnNo.Trim();
                row1["ExpBkgN"]    = expBkgN;
                row1["HblN"]       = hblN;
                row1["TotMarking"] = mkg;

                //row1["Tally1"] = tally1.ToString("#");
                //row1["Tally2"] = tally2.ToString("#");
                //row1["Tally3"] = tally3.ToString("#");
                //row1["Tally4"] = tally4.ToString("#");
                //row1["Tally21"] = tally21.ToString("#");
                //row1["Tally22"] = tally22.ToString("#");
                //row1["Tally23"] = tally23.ToString("#");
                //row1["Tally24"] = tally24.ToString("#");
                //row1["Tally31"] = tally31.ToString("#");
                //row1["Tally32"] = tally32.ToString("#");
                //row1["Tally33"] = tally33.ToString("#");
                //row1["Tally34"] = tally34.ToString("#");
                //row1["Tally41"] = tally41.ToString("#");
                //row1["Tally42"] = tally42.ToString("#");
                //row1["Tally43"] = tally43.ToString("#");
                //row1["Tally44"] = tally44.ToString("#");
                //row1["Tally51"] = tally51.ToString("#");
                //row1["Tally52"] = tally52.ToString("#");
                //row1["Tally53"] = tally53.ToString("#");
                //row1["Tally54"] = tally54.ToString("#");
                //row1["Tally61"] = tally61.ToString("#");
                //row1["Tally62"] = tally62.ToString("#");
                //row1["Tally63"] = tally63.ToString("#");
                //row1["Tally64"] = tally64.ToString("#");
                row1["TotQty"]       = qty.ToString("#");
                row1["PackType"]     = pkgType;
                row1["PackTypeOrig"] = pkgType2;
                row1["M3"]           = m3.ToString("#,##0.000");
                row1["Weight"]       = wt.ToString("#,##0.000");


                row1["OrigQty"]    = qtyOrig.ToString("#");
                row1["OrigM3"]     = m3Orig.ToString("#,##0.000");
                row1["OrigWeight"] = wtOrig.ToString("#,##0.000");
                if (qtyOrig != qty)
                {
                    row1["DiffQty"] = qty - qtyOrig;
                }
                if (m3Orig != m3)
                {
                    row1["DiffM3"] = m3 - m3Orig;
                }
                if (wtOrig != wt)
                {
                    row1["DiffWeight"] = wt - wtOrig;
                }

                row1["TotRemark"]   = rmk;
                row1["LocalRemark"] = "";


                if (isDg)
                {
                    if (dgClass.Trim().Length < 1)
                    {
                        row1["DgClass"] = "DG Cargo";
                    }
                    else
                    {
                        row1["DgClass"] = "DG Class:\n" + dgClass;
                    }
                }
                //row1["TotDesc"] = desc2.Trim();
                row1["POD"] = pod;
                if (jobType.ToUpper() == "T")
                {
                    if (desc2.Trim().Length > 23)
                    {
                        row1["TotDesc"] = desc2.Trim().Substring(desc2.Trim().Length - 23).Trim().Replace("\n", "") + "\n" + rmk.Trim();
                    }
                    else
                    {
                        row1["TotDesc"] = desc2.Trim() + "\n" + rmk.Trim();
                    }

                    // row1["TotDesc"] += "\n\nM3:" + SafeValue.SafeDecimal(row_Det["M3"], 0).ToString("0.000");
                }
                else
                {
                    row1["TotDesc"] = rmk;
                }
                details.Rows.Add(row1);
            }
            #endregion
        }
        DataSet set = new DataSet();
        set.Tables.Add(mast);
        set.Tables.Add(details);
        set.Relations.Add("", mast.Columns["JobOrderNo"], details.Columns["JobOrderNo"]);

        return(set);
    }
示例#13
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);
    }
示例#14
0
    public static XmlDocument Export_order(string orderNo, string orderType)
    {
        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.LoadXml("<?xml version=\"1.0\" encoding=\"GB2312\"?><Order></Order>");
        XmlNode xmlNode = null;

        string element  = "Order";
        string sql_mast = string.Format(@"Select Id,RelaId,DoNo,DoType,DoDate,PoNo,PoDate,PartyName as PartyName,PartyPostalCode as PartyPostal,PartyCity,PartyCountry,PartyAdd as PartyAddress,
CustomerReference as CustomsRef,CustomerDate as RefDate,PoNo,PoDate,PartyInvNo,PartyInvDate,PermitNo,PermitApprovalDate,TptMode,PalletizedInd,EquipNo,Personnel,
CollectFrom as PickFrom,DeliveryTo as DeliveryTo,Remark1,Remark2,Priority,ExpectedDate,DoStatus,
Vessel,Voyage,Obl as OceanBl,Hbl as HouseBl,Pol,Pod,Eta,Etd,EtaDest,Carrier,Vehicle,Coo,
AgentName as Agent,AgentTel,AgentContact,AgentAdd as AgentAddress,AgentZip,AgentCity,AgentCountry,
NotifyName as Notify,NotifyTel,NotifyContact,NotifyAdd as NotifyAddress,NotifyZip,NotifyCity,NotifyCountry,
ConsigneeName Cnee,ConsigneeTel CneeTel,ConsigneeContact CneeContact,ConsigneeAdd CneeAddress,ConsigneeZip as CneeZip,ConsigneeCity as CneeCity,ConsigneeCountry as CneeCountry,PermitBy,OtherPermit,ModelType from Wh_Do  WHERE (DoNo = '{0}' ) and DoType='{1}'", orderNo, orderType);
        string sql_job  = string.Format(@"select Id,RelaId,BatchNo,CustomsLot,LotNo,ProductCode Sku,Des1 Des,Qty1 PackQty,Qty2 WholeQty,Qty3 LooseQty,Qty4 Expected,Qty5 Transit,QtyPackWhole,QtyWholeLoose,QtyLooseBase,Uom1 PackUom,Uom2 WholeUom,Uom3 LooseUom,Uom4 BaseUom,Price,Att1,Att2,Att3,Att4,Att5,Att6,Att7,Att8,Att9,Att10 from wh_DoDet WHERE (DoNo = '{0}' ) and DoType='{1}'", orderNo, orderType);
        string sql_job1 = string.Format(@"select Id,RelaId,Product,Location,ProcessStatus,LotNo,BatchNo,CustomsLot,Des1 Des,Qty1 PackQty,Qty2 WholeQty,Qty3 LooseQty,QtyPackWhole,QtyWholeLoose,QtyLooseBase,Uom1 PackUom,Uom2 WholeUom,Uom3 LooseUom,Uom4 BaseUom,Att1,Att2,Att3,Att4,Att5,Att6,Att7,Att8,Att9,Att10 from wh_DoDet2 WHERE (DoNo = '{0}' ) and DoType='{1}'", orderNo, orderType);
        string sql_job2 = string.Format(@"select Id,RelaId,ContainerNo,ContainerType,SealNo,Weight,M3,Qty,PkgType from Wh_DoDet3 WHERE (DoNo = '{0}' ) and DoType='{1}'", orderNo, orderType);

        xmlDoc.LoadXml("<?xml version=\"1.0\" encoding=\"GB2312\"?><Order></Order>");
        xmlNode = xmlDoc.SelectSingleNode("Order");
        DataTable mast     = ConnectSql.GetDataSet(sql_mast).Tables[0];
        DataTable tab_mark = ConnectSql.GetDataSet(sql_job).Tables[0];
        DataTable tab_job1 = ConnectSql.GetDataSet(sql_job1).Tables[0];
        DataTable tab_job2 = ConnectSql.GetDataSet(sql_job2).Tables[0];

        if (mast.Rows.Count != 1 || tab_mark.Rows.Count == 0)
        {
            return(null);
        }
        XmlElement item = null;

        for (int j = 0; j < mast.Rows.Count; j++)
        {
            item = xmlNode as XmlElement;//xmlDoc.CreateElement("" + element + "");
            item.SetAttribute("Id", mast.Rows[j]["Id"].ToString());
            item.SetAttribute("RelaId", mast.Rows[j]["RelaId"].ToString());
            item.SetAttribute("OrderNo", mast.Rows[j]["DoNo"].ToString());
            item.SetAttribute("OrderType", mast.Rows[j]["DoType"].ToString());
            item.SetAttribute("OrderDate", SafeValue.SafeDate(mast.Rows[j]["DoDate"], DateTime.Today).ToString("yyyy-MM-dd"));
            item.SetAttribute("PoNo", mast.Rows[j]["PoNo"].ToString());
            item.SetAttribute("PoDate", SafeValue.SafeDate(mast.Rows[j]["PoDate"], DateTime.Today).ToString("yyyy-MM-dd"));
            item.SetAttribute("Type", mast.Rows[j]["Priority"].ToString());
            item.SetAttribute("ExpectedDate", SafeValue.SafeDate(mast.Rows[j]["ExpectedDate"], DateTime.Today).ToString("yyyy-MM-dd"));
            item.SetAttribute("DoStatus", mast.Rows[j]["DoStatus"].ToString());
            //from company to warehouse
            if (System.Configuration.ConfigurationManager.AppSettings["WhService_ToStock"].Length > 0)
            {
                string partyId   = System.Configuration.ConfigurationManager.AppSettings["PartyIdInStock"];
                string partyName = System.Configuration.ConfigurationManager.AppSettings["CompanyName"];
                //partyName += "\n" + System.Configuration.ConfigurationManager.AppSettings["CompanyAddress1"];
                //partyName += "\n" + System.Configuration.ConfigurationManager.AppSettings["CompanyAddress2"];
                //partyName += "\n" + System.Configuration.ConfigurationManager.AppSettings["CompanyAddress3"];
                item.SetAttribute("PartyId", partyId);
                item.SetAttribute("Party", partyName);
                item.SetAttribute("PartyAddress", mast.Rows[j]["PartyName"].ToString() + "\n" + mast.Rows[j]["PartyAddress"].ToString());
            }
            else// from warehouse to company
            {
                item.SetAttribute("PartyId", "");
                item.SetAttribute("Party", "");
                item.SetAttribute("PartyAddress", "");
            }
            //item.SetAttribute("Party", mast.Rows[j]["PartyName"].ToString());
            //item.SetAttribute("PartyPostal", mast.Rows[j]["PartyPostal"].ToString());
            //item.SetAttribute("PartyCity", mast.Rows[j]["PartyCity"].ToString());
            //item.SetAttribute("PartyCountry", mast.Rows[j]["PartyCountry"].ToString());
            //item.SetAttribute("PartyAddress", mast.Rows[j]["PartyAddress"].ToString());



            item.SetAttribute("PickFrom", mast.Rows[j]["PickFrom"].ToString());
            item.SetAttribute("DeliveryTo", mast.Rows[j]["DeliveryTo"].ToString());
            item.SetAttribute("Remark1", mast.Rows[j]["Remark1"].ToString());
            item.SetAttribute("Remark2", mast.Rows[j]["Remark2"].ToString());
            item.SetAttribute("CustomsRef", mast.Rows[j]["CustomsRef"].ToString());
            item.SetAttribute("RefDate", SafeValue.SafeDate(mast.Rows[j]["RefDate"], DateTime.Today).ToString("yyyy-MM-dd"));
            item.SetAttribute("PoNo", mast.Rows[j]["PoNo"].ToString());
            item.SetAttribute("PoDate", SafeValue.SafeDate(mast.Rows[j]["PoDate"], DateTime.Today).ToString("yyyy-MM-dd"));
            item.SetAttribute("PartyInvNo", mast.Rows[j]["PartyInvNo"].ToString());
            item.SetAttribute("PartyInvDate", SafeValue.SafeDate(mast.Rows[j]["PartyInvDate"], DateTime.Today).ToString("yyyy-MM-dd"));
            item.SetAttribute("PermitNo", mast.Rows[j]["PermitNo"].ToString());
            item.SetAttribute("PermitApprovalDate", SafeValue.SafeDate(mast.Rows[j]["PermitApprovalDate"], DateTime.Today).ToString("yyyy-MM-dd"));
            item.SetAttribute("PermitBy", mast.Rows[j]["PermitBy"].ToString());
            item.SetAttribute("OtherPermit", mast.Rows[j]["OtherPermit"].ToString());
            item.SetAttribute("ModelType", mast.Rows[j]["ModelType"].ToString());

            item.SetAttribute("TptMode", mast.Rows[j]["TptMode"].ToString());
            item.SetAttribute("PalletizedInd", SafeValue.SafeBool(mast.Rows[j]["PalletizedInd"], true).ToString());
            item.SetAttribute("EquipNo", mast.Rows[j]["EquipNo"].ToString());
            item.SetAttribute("Personnel", mast.Rows[j]["Personnel"].ToString());
            #region shipment info
            item.SetAttribute("Vessel", SafeValue.SafeString(mast.Rows[j]["Vessel"]));
            item.SetAttribute("Voyage", SafeValue.SafeString(mast.Rows[j]["Voyage"]));
            item.SetAttribute("OceanBl", SafeValue.SafeString(mast.Rows[j]["OceanBl"]));
            item.SetAttribute("HouseBl", SafeValue.SafeString(mast.Rows[j]["HouseBl"]));
            item.SetAttribute("Pol", SafeValue.SafeString(mast.Rows[j]["Pol"]));
            item.SetAttribute("Pod", SafeValue.SafeString(mast.Rows[j]["Pod"]));
            item.SetAttribute("Eta", SafeValue.SafeDate(mast.Rows[j]["Eta"], DateTime.Today).ToString("yyyy-MM-dd"));
            item.SetAttribute("Etd", SafeValue.SafeDate(mast.Rows[j]["Etd"], DateTime.Today).ToString("yyyy-MM-dd"));
            item.SetAttribute("EtaDest", SafeValue.SafeDate(mast.Rows[j]["EtaDest"], DateTime.Today).ToString("yyyy-MM-dd"));
            item.SetAttribute("Carrier", SafeValue.SafeString(mast.Rows[j]["Carrier"]));
            item.SetAttribute("Vehicle", SafeValue.SafeString(mast.Rows[j]["Vehicle"]));
            item.SetAttribute("Coo", SafeValue.SafeString(mast.Rows[j]["Coo"]));
            #endregion
            #region party
            //party-agent
            item.SetAttribute("Agent", SafeValue.SafeString(mast.Rows[j]["Agent"]));
            item.SetAttribute("AgentContact", SafeValue.SafeString(mast.Rows[j]["AgentContact"]));
            item.SetAttribute("AgentTel", SafeValue.SafeString(mast.Rows[j]["AgentTel"]));
            item.SetAttribute("AgentAddress", SafeValue.SafeString(mast.Rows[j]["AgentAddress"]));
            item.SetAttribute("AgentZip", SafeValue.SafeString(mast.Rows[j]["AgentZip"]));
            item.SetAttribute("AgentCity", SafeValue.SafeString(mast.Rows[j]["AgentCity"]));
            item.SetAttribute("AgentCountry", SafeValue.SafeString(mast.Rows[j]["AgentCountry"]));
            //party-notify party
            item.SetAttribute("Notify", SafeValue.SafeString(mast.Rows[j]["Notify"]));
            item.SetAttribute("NotifyContact", SafeValue.SafeString(mast.Rows[j]["NotifyContact"]));
            item.SetAttribute("NotifyTel", SafeValue.SafeString(mast.Rows[j]["NotifyTel"]));
            item.SetAttribute("NotifyAddress", SafeValue.SafeString(mast.Rows[j]["NotifyAddress"]));
            item.SetAttribute("NotifyZip", SafeValue.SafeString(mast.Rows[j]["NotifyZip"]));
            item.SetAttribute("NotifyCity", SafeValue.SafeString(mast.Rows[j]["NotifyCity"]));
            item.SetAttribute("NotifyCountry", SafeValue.SafeString(mast.Rows[j]["NotifyCountry"]));
            //party-consignee
            item.SetAttribute("Cnee", SafeValue.SafeString(mast.Rows[j]["Cnee"]));
            item.SetAttribute("CneeContact", SafeValue.SafeString(mast.Rows[j]["CneeContact"]));
            item.SetAttribute("CneeTel", SafeValue.SafeString(mast.Rows[j]["CneeTel"]));
            item.SetAttribute("CneeAddress", SafeValue.SafeString(mast.Rows[j]["CneeAddress"]));
            item.SetAttribute("CneeZip", SafeValue.SafeString(mast.Rows[j]["CneeZip"]));
            item.SetAttribute("CneeCity", SafeValue.SafeString(mast.Rows[j]["CneeCity"]));
            item.SetAttribute("CneeCountry", SafeValue.SafeString(mast.Rows[j]["CneeCountry"]));
            #endregion
            #region Sku

            for (int k = 0; k < tab_mark.Rows.Count; k++)
            {
                XmlElement cont = xmlDoc.CreateElement("Sku");
                cont.SetAttribute("Id", SafeValue.SafeString(tab_mark.Rows[k]["Id"]));
                cont.SetAttribute("LotNo", SafeValue.SafeString(tab_mark.Rows[k]["LotNo"]));
                cont.SetAttribute("Sku", SafeValue.SafeString(tab_mark.Rows[k]["Sku"]));
                cont.SetAttribute("Des", SafeValue.SafeString(tab_mark.Rows[k]["Des"]));
                cont.SetAttribute("CustomsLot", SafeValue.SafeString(tab_mark.Rows[k]["CustomsLot"]));
                cont.SetAttribute("BatchNo", SafeValue.SafeString(tab_mark.Rows[k]["BatchNo"]));
                cont.SetAttribute("Expected", SafeValue.SafeString(tab_mark.Rows[k]["Expected"]));
                cont.SetAttribute("Transit", SafeValue.SafeString(tab_mark.Rows[k]["Transit"]));
                cont.SetAttribute("PackQty", SafeValue.SafeString(tab_mark.Rows[k]["PackQty"]));
                cont.SetAttribute("WholeQty", SafeValue.SafeString(tab_mark.Rows[k]["WholeQty"]));
                cont.SetAttribute("LooseQty", SafeValue.SafeString(tab_mark.Rows[k]["LooseQty"]));
                cont.SetAttribute("QtyPackWhole", SafeValue.SafeString(tab_mark.Rows[k]["QtyPackWhole"]));
                cont.SetAttribute("QtyWholeLoose", SafeValue.SafeString(tab_mark.Rows[k]["QtyWholeLoose"]));
                cont.SetAttribute("QtyLooseBase", SafeValue.SafeString(tab_mark.Rows[k]["QtyLooseBase"]));
                cont.SetAttribute("PackUom", SafeValue.SafeString(tab_mark.Rows[k]["PackUom"]));
                cont.SetAttribute("WholeUom", SafeValue.SafeString(tab_mark.Rows[k]["WholeUom"]));
                cont.SetAttribute("LooseUom", SafeValue.SafeString(tab_mark.Rows[k]["LooseUom"]));
                cont.SetAttribute("BaseUom", SafeValue.SafeString(tab_mark.Rows[k]["BaseUom"]));
                cont.SetAttribute("Price", SafeValue.SafeString(tab_mark.Rows[k]["Price"]));
                cont.SetAttribute("Att1", SafeValue.SafeString(tab_mark.Rows[k]["Att1"]));
                cont.SetAttribute("Att2", SafeValue.SafeString(tab_mark.Rows[k]["Att2"]));
                cont.SetAttribute("Att3", SafeValue.SafeString(tab_mark.Rows[k]["Att3"]));
                cont.SetAttribute("Att4", SafeValue.SafeString(tab_mark.Rows[k]["Att4"]));
                cont.SetAttribute("Att5", SafeValue.SafeString(tab_mark.Rows[k]["Att5"]));
                cont.SetAttribute("Att6", SafeValue.SafeString(tab_mark.Rows[k]["Att6"]));
                cont.SetAttribute("Att7", SafeValue.SafeString(tab_mark.Rows[k]["Att7"]));
                cont.SetAttribute("Att8", SafeValue.SafeString(tab_mark.Rows[k]["Att8"]));
                cont.SetAttribute("Att9", SafeValue.SafeString(tab_mark.Rows[k]["Att9"]));
                cont.SetAttribute("Att10", SafeValue.SafeString(tab_mark.Rows[k]["Att10"]));
                item.AppendChild(cont);
            }
            #endregion
            #region PutAway
            for (int a = 0; a < tab_job1.Rows.Count; a++)
            {
                XmlElement cont = xmlDoc.CreateElement("PutAway");
                cont.SetAttribute("Id", SafeValue.SafeString(tab_job1.Rows[a]["Id"]));
                cont.SetAttribute("LotNo", SafeValue.SafeString(tab_job1.Rows[a]["LotNo"]));
                cont.SetAttribute("Product", SafeValue.SafeString(tab_job1.Rows[a]["Product"]));
                cont.SetAttribute("Des", SafeValue.SafeString(tab_job1.Rows[a]["Des"]));
                cont.SetAttribute("PackQty", SafeValue.SafeString(tab_job1.Rows[a]["PackQty"]));
                cont.SetAttribute("WholeQty", SafeValue.SafeString(tab_job1.Rows[a]["WholeQty"]));
                cont.SetAttribute("LooseQty", SafeValue.SafeString(tab_job1.Rows[a]["LooseQty"]));
                cont.SetAttribute("QtyPackWhole", SafeValue.SafeString(tab_mark.Rows[a]["QtyPackWhole"]));
                cont.SetAttribute("QtyWholeLoose", SafeValue.SafeString(tab_mark.Rows[a]["QtyWholeLoose"]));
                cont.SetAttribute("QtyLooseBase", SafeValue.SafeString(tab_mark.Rows[a]["QtyLooseBase"]));
                cont.SetAttribute("PackUom", SafeValue.SafeString(tab_mark.Rows[a]["PackUom"]));
                cont.SetAttribute("WholeUom", SafeValue.SafeString(tab_mark.Rows[a]["WholeUom"]));
                cont.SetAttribute("LooseUom", SafeValue.SafeString(tab_mark.Rows[a]["LooseUom"]));
                cont.SetAttribute("BaseUom", SafeValue.SafeString(tab_mark.Rows[a]["BaseUom"]));
                cont.SetAttribute("Location", SafeValue.SafeString(tab_job1.Rows[a]["Location"]));
                cont.SetAttribute("ProcessStatus", SafeValue.SafeString(tab_job1.Rows[a]["ProcessStatus"]));
                cont.SetAttribute("CustomsLot", SafeValue.SafeString(tab_job1.Rows[a]["CustomsLot"]));
                cont.SetAttribute("BatchNo", SafeValue.SafeString(tab_job1.Rows[a]["BatchNo"]));
                cont.SetAttribute("Att1", SafeValue.SafeString(tab_job1.Rows[a]["Att1"]));
                cont.SetAttribute("Att2", SafeValue.SafeString(tab_job1.Rows[a]["Att2"]));
                cont.SetAttribute("Att3", SafeValue.SafeString(tab_job1.Rows[a]["Att3"]));
                cont.SetAttribute("Att4", SafeValue.SafeString(tab_job1.Rows[a]["Att4"]));
                cont.SetAttribute("Att5", SafeValue.SafeString(tab_job1.Rows[a]["Att5"]));
                cont.SetAttribute("Att6", SafeValue.SafeString(tab_job1.Rows[a]["Att6"]));
                cont.SetAttribute("Att7", SafeValue.SafeString(tab_job1.Rows[a]["Att7"]));
                cont.SetAttribute("Att8", SafeValue.SafeString(tab_job1.Rows[a]["Att8"]));
                cont.SetAttribute("Att9", SafeValue.SafeString(tab_job1.Rows[a]["Att9"]));
                cont.SetAttribute("Att10", SafeValue.SafeString(tab_job1.Rows[a]["Att10"]));
                item.AppendChild(cont);
            }
            #endregion
            #region Container
            for (int a = 0; a < tab_job2.Rows.Count; a++)
            {
                XmlElement cont = xmlDoc.CreateElement("Container");
                cont.SetAttribute("Id", SafeValue.SafeString(tab_job2.Rows[a]["Id"]));
                cont.SetAttribute("ContainerNo", SafeValue.SafeString(tab_job2.Rows[a]["ContainerNo"]));
                cont.SetAttribute("ContainerType", SafeValue.SafeString(tab_job2.Rows[a]["ContainerType"]));
                cont.SetAttribute("SealNo", SafeValue.SafeString(tab_job2.Rows[a]["SealNo"]));
                cont.SetAttribute("Weight", SafeValue.SafeString(tab_job2.Rows[a]["Weight"]));
                cont.SetAttribute("M3", SafeValue.SafeString(tab_job2.Rows[a]["M3"]));
                cont.SetAttribute("Qty", SafeValue.SafeString(tab_job2.Rows[a]["Qty"]));
                cont.SetAttribute("PkgType", SafeValue.SafeString(tab_job2.Rows[a]["PkgType"]));
                item.AppendChild(cont);
            }
            #endregion
            //xmlNode.AppendChild(item);
        }

        return(xmlDoc);
    }
    /// <summary>
    /// if dotype=in, then calc lastschqty and preqty
    /// if dotype=out , calc preqty
    /// don't calc the transfer data(which dono='').
    /// for do in
    /// if isSch= N , only get lastSchQty
    /// if isSch=Y , need LastSchQty and qty-preQty
    /// for do out
    /// only get the qty-preqty
    ///
    /// update create invoice,
    /// update preqty=qty,lastschqty=inqty-outqty where dotype=in and dono!=''
    /// update preqty=qty,lastschqty=0 where dotype=out and dono!=''
    /// </summary>

    protected void btn_CreateIV_Click1(object sender, EventArgs e)
    {
        //1: issch=false , the qty=qty1   n=schdate-dodate
        //2:issch=true, qty=lastschqty    n=currentschdate-lastschdate
        //3:issch=true, qty=qty-preqty    n=schdate-dodate

        string sql = @"select * from (select mast.DoNo,mast.DoDate,mast.DoType,mast.PartyId,mast.Quotation as ContractNo,det.Product as Sku,det.LotNo
,Case when isnull(det.isSch,0)=0 then isnull(det.Qty1,0)  else isnull(det.Qty1,0)-isnull(det.PreQty1,0) end  as Qty1
,Case when isnull(det.isSch,0)=0 then isnull(det.Qty2,0)  else isnull(det.Qty2,0)-isnull(det.PreQty2,0) end  as Qty2
,Case when isnull(det.isSch,0)=0 then isnull(det.Qty3,0)  else isnull(det.Qty3,0)-isnull(det.PreQty3,0) end  as Qty3

,Case when isnull(det.isSch,0)=1 and det.DoType='IN' then isnull(det.LastSchQty1,0)  else 0 end  as LastSchQty1
,Case when isnull(det.isSch,0)=1 and det.DoType='IN' then isnull(det.LastSchQty2,0)  else 0 end  as LastSchQty2
,Case when isnull(det.isSch,0)=1 and det.DoType='IN' then isnull(det.LastSchQty3,0)  else 0 end  as LastSchQty3
,det.IsSch,det.LastSchDate,ref.ArCode,ref.Description
 from wh_dodet2 det 
inner join wh_do mast on mast.DoNo=det.DoNo and mast.DoType=det.Dotype
inner join ref_product ref on ref.Code=det.Product
where mast.StatusCode!='CNL' and len(isnull(det.DoNo,''))>0
) as tab where (Qty1+Qty2+Qty3>0 or LastSchQty1+LastSchQty2+LastSchQty3>0)
order by PartyId,DoDate,DoNo";
        //one customer only have one invoice
        DataTable tab         = ConnectSql.GetTab(sql);
        string    lastPartyId = "";
        int       lastInvId   = 0;
        string    lastInvNo   = "";

        for (int i = 0; i < tab.Rows.Count; i++)
        {
            string   sku         = SafeValue.SafeString(tab.Rows[i]["Sku"]);
            string   lotNo       = SafeValue.SafeString(tab.Rows[i]["LotNo"]);
            string   contractNo  = SafeValue.SafeString(tab.Rows[i]["ContractNo"]);
            DateTime doDate      = SafeValue.SafeDate(tab.Rows[i]["DoDate"], DateTime.Today);
            string   partyId     = SafeValue.SafeString(tab.Rows[i]["PartyId"]);
            int      qty1        = SafeValue.SafeInt(tab.Rows[i]["Qty1"], 0);
            int      qty2        = SafeValue.SafeInt(tab.Rows[i]["Qty2"], 0);
            int      qty3        = SafeValue.SafeInt(tab.Rows[i]["Qty3"], 0);
            bool     isSch       = SafeValue.SafeBool(tab.Rows[i]["IsSch"], false);
            DateTime lastSchDate = SafeValue.SafeDate(tab.Rows[i]["LastSchDate"], DateTime.Today);
            int      LastSchQty1 = SafeValue.SafeInt(tab.Rows[i]["LastSchQty1"], 0);
            int      LastSchQty2 = SafeValue.SafeInt(tab.Rows[i]["LastSchQty2"], 0);
            int      LastSchQty3 = SafeValue.SafeInt(tab.Rows[i]["LastSchQty3"], 0);
            string   doType      = SafeValue.SafeString(tab.Rows[i]["DoType"]).ToUpper();
            string   arCode      = SafeValue.SafeString(tab.Rows[i]["ArCode"]);
            string   des         = SafeValue.SafeString(tab.Rows[i]["Description"]);
            //DateTime peroidDate = SafeValue.SafeDate(tab.Rows[i]["PeroidDate"], DateTime.Today);
            //string refNo = SafeValue.SafeString(tab.Rows[i]["DoNo"]);
            //int detId = SafeValue.SafeInt(tab.Rows[i]["detId"], 0);
            //int preQty = SafeValue.SafeInt(tab.Rows[i]["PreQty"], 0);
            //int lastSchQty = SafeValue.SafeInt(tab.Rows[i]["LastSchQty"], 0);
            //string IsSch = SafeValue.SafeString(tab.Rows[i]["IsSch"]);
            decimal   price1    = 0;
            decimal   price2    = 0;
            decimal   price3    = 0;
            int       dailyNo   = 0;
            bool      isFixed   = false;
            bool      isYearly  = false;
            bool      isMonthly = false;
            bool      isWeekly  = false;
            bool      isDaily   = false;
            DateTime  dt        = DateTime.Today;
            DataTable tab1      = new DataTable();
            if (doType == "IN")
            {
                tab1 = GetContractByNo(contractNo, sku);
            }
            else//out get contractno, by sku,lotno>>dotype=in, doNo>>PO no>> get ContractNo
            {
                string conNo = string.Format(@"select Quotation from wh_do mast 
inner join Wh_DoDet2 det on det.DoNo=mast.DoNo and det.DoType=mast.DoType 
 where det.DoType='in' and det.Product='{0}' and det.LotNo='{1}' and len(det.DoNo)>0", sku, lotNo);

                tab1 = GetContractByNo(SafeValue.SafeString(C2.Manager.ORManager.ExecuteScalar(conNo)), sku);
            }
            int n     = 0;
            int n_sch = 0;
            for (int j = 0; j < tab1.Rows.Count; j++)
            {
                isFixed   = SafeValue.SafeBool(tab1.Rows[j]["IsFixed"], true);
                isYearly  = SafeValue.SafeBool(tab1.Rows[j]["IsYearly"], true);
                isMonthly = SafeValue.SafeBool(tab1.Rows[j]["IsMonthly"], true);
                isWeekly  = SafeValue.SafeBool(tab1.Rows[j]["IsWeekly"], true);
                isDaily   = SafeValue.SafeBool(tab1.Rows[j]["IsDaily"], true);
                #region get sch and price
                if (isYearly)
                {
                    TimeSpan span = dt - doDate;
                    if (dt.ToString("MM-dd") == "01-01")
                    {
                        n = SafeValue.SafeInt(dt.Year - doDate.Year, 0);
                        if (isSch)
                        {
                            n_sch = SafeValue.SafeInt(dt.Year - lastSchDate.Year, 0);
                        }
                        price1 = SafeValue.SafeDecimal(tab1.Rows[j]["Price1"]);
                        price2 = SafeValue.SafeDecimal(tab1.Rows[j]["Price2"]);
                        price3 = SafeValue.SafeDecimal(tab1.Rows[j]["Price3"]);
                    }
                    else
                    {
                        continue;
                    }
                }
                else if (isMonthly)
                {
                    if (dt.ToString("dd") == "01")
                    {
                        price1 = SafeValue.SafeDecimal(tab1.Rows[j]["Price1"]);
                        price2 = SafeValue.SafeDecimal(tab1.Rows[j]["Price2"]);
                        price3 = SafeValue.SafeDecimal(tab1.Rows[j]["Price3"]);
                        int year = dt.Year;
                        n = (dt.Year - doDate.Year) * 12 + dt.Month - doDate.Month;
                        if (isSch)
                        {
                            n_sch = (dt.Year - lastSchDate.Year) * 12 + dt.Month - lastSchDate.Month;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                else if (isWeekly)
                {
                    if (dt.DayOfWeek == DayOfWeek.Monday)
                    {
                        price1 = SafeValue.SafeDecimal(tab1.Rows[j]["Price1"]);
                        price2 = SafeValue.SafeDecimal(tab1.Rows[j]["Price2"]);
                        price3 = SafeValue.SafeDecimal(tab1.Rows[j]["Price3"]);

                        TimeSpan day = GetMondayByDate(dt) - GetMondayByDate(doDate);
                        n = SafeValue.SafeInt(day.TotalDays / 7, 0);
                        if (isSch)
                        {
                            day   = GetMondayByDate(dt) - GetMondayByDate(lastSchDate);
                            n_sch = SafeValue.SafeInt(day.TotalDays / 7, 0);
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                else if (isDaily)
                {
                    dailyNo = SafeValue.SafeInt(tab1.Rows[j]["DailyNo"], 1);
                    if (dailyNo == 0)
                    {
                        dailyNo = 1;
                    }

                    TimeSpan day = dt.Date - doDate.Date;
                    if (day.Days % dailyNo == 0)
                    {
                        price1 = SafeValue.SafeDecimal(tab1.Rows[j]["Price1"]);
                        price2 = SafeValue.SafeDecimal(tab1.Rows[j]["Price2"]);
                        price3 = SafeValue.SafeDecimal(tab1.Rows[j]["Price3"]);
                        n      = SafeValue.SafeInt(day.TotalDays / dailyNo, 0);
                        if (isSch)
                        {
                            day   = dt.Date - lastSchDate.Date;
                            n_sch = SafeValue.SafeInt(day.TotalDays / dailyNo, 0);
                        }
                    }
                    else
                    {
                        continue;
                    }
                }

                #endregion

                XAArInvoice iv       = null;
                string      mastType = "WH";
                if (lastInvId == 0 || lastPartyId != partyId) //is the frist invoice or is next party then generate new invoice
                {
                    if (lastInvId > 0)                        //update last invoice ,set linelocamat, and mast.docamt/locamt/balanceamt
                    {
                        UpdateMaster(lastInvId);
                    }
                    #region generate invoice
                    iv = new XAArInvoice();
                    string counterType = "AR-IV";

                    iv.DocType     = "IV";
                    iv.DocDate     = dt;
                    lastInvNo      = C2Setup.GetNextNo(iv.DocType, counterType, iv.DocDate);
                    iv.DocNo       = lastInvNo;
                    iv.PartyTo     = partyId;
                    iv.CurrencyId  = System.Configuration.ConfigurationManager.AppSettings["Currency"];
                    iv.ExRate      = 1;
                    iv.AcCode      = EzshipHelper.GetAccApCode(iv.PartyTo, iv.CurrencyId);
                    iv.AcSource    = "DB";
                    iv.Description = "";
                    iv.Term        = "CASH";

                    string[] currentPeriod = EzshipHelper.GetAccPeriod(iv.DocDate);
                    iv.AcYear   = SafeValue.SafeInt(currentPeriod[1], iv.DocDate.Year);
                    iv.AcPeriod = SafeValue.SafeInt(currentPeriod[0], iv.DocDate.Month);

                    iv.MastRefNo   = "";
                    iv.JobRefNo    = "";
                    iv.MastType    = mastType;
                    iv.DocAmt      = 0;
                    iv.LocAmt      = 0;
                    iv.BalanceAmt  = 0;
                    iv.CancelDate  = new DateTime(1900, 1, 1);
                    iv.CancelInd   = "N";
                    iv.DocDueDate  = dt;
                    iv.ExportInd   = "N";
                    iv.SpecialNote = "";
                    iv.UserId      = EzshipHelper.GetUserName();
                    iv.EntryDate   = DateTime.Now;

                    C2.Manager.ORManager.StartTracking(iv, Wilson.ORMapper.InitialState.Inserted);
                    C2.Manager.ORManager.PersistChanges(iv);
                    C2Setup.SetNextNo(iv.DocType, counterType, lastInvNo, iv.DocDate);
                    lastInvId = iv.SequenceId;
                    #endregion
                }
                if (doType == "OUT") // form modify the qty
                {
                    qty1        = -qty1;
                    qty2        = -qty2;
                    qty3        = -qty3;
                    LastSchQty1 = 0;
                    LastSchQty2 = 0;
                    LastSchQty3 = 0;
                }
                lastPartyId = partyId;
                #region create det
                if (isFixed)// only do one time
                {
                    int cnt = SafeValue.SafeInt(ConnectSql.ExecuteScalar(string.Format("select count(*) from XAArInvoiceDet where DocId='{0}' and ChgDes1 like 'SKU {1}%,'", lastInvId, sku)), 0);
                    if (cnt == 0)//sku balQty>0
                    {
                        int count = SafeValue.SafeInt(C2.Manager.ORManager.ExecuteScalar(string.Format("select sum(case when DoType='in' then Qty1 else -qty1 end) as cnt from wh_dodet2 where Product='{0}'", sku)), 0);
                        InsertInv_det(lastInvId, lastInvNo, mastType, 1, price1 + price2 + price3, sku, arCode, des, lotNo);
                    }
                }
                else
                {
                    if (qty1 * n + LastSchQty1 * n_sch != 0)
                    {
                        InsertInv_det(lastInvId, lastInvNo, mastType, qty1 * n + LastSchQty1 * n_sch, price1, sku, arCode, des, lotNo);
                    }
                    if (qty2 * n + LastSchQty2 * n_sch != 0)
                    {
                        InsertInv_det(lastInvId, lastInvNo, mastType, qty2 * n + LastSchQty2 * n_sch, price2, sku, arCode, des, lotNo);
                    }
                    if (qty3 * n + LastSchQty3 * n_sch != 0)
                    {
                        InsertInv_det(lastInvId, lastInvNo, mastType, qty3 * n + LastSchQty3 * n_sch, price3, sku, arCode, des, lotNo);
                    }
                }
                #endregion
                UpdateDoDet(sku, lotNo, doType);
            }
        }
    }