Ejemplo n.º 1
0
    public void InsertHeaderDetail()
    {
        DataSet dsCustomer = new DataSet();
        DataSet dtCustomer = (DataSet)Session["CustomerDetail"];

        #region Insert into SOHeader Table

        string _tableName  = "SOHeader";
        string _columnName = "[CusttypeName],[OrderType],[OrderTypeDsc],SubType,[PriceCd]," +
                             "[BillToCustNo],[SellToCustNo],[SellToCustName]," +
                             "[OrderDt],[ShipLoc],[ShipLocName],[UsageLoc],[UsageLocName]," +
                             "[ReasonCd],[ReasonCdName],[OrderFreightCd],[OrderFreightName],[OrderPriorityCd]," +
                             "[OrderPriName],[OrderExpdCd],[OrderExpdCdName],[SalesRepNo],[SalesRepName],CustSvcRepNo,CustSvcRepName," +
                             "[OrderCarrier],[OrderCarName] ,[CustoType],[BranchReqDt],[CustReqDt],SchShipDt,OrderTermsCd,[OrderTermsName]," +
                             "[BillToCustName],[BillToAddress1],[BillToAddress2],[BillToCity],[BillToState],[BillToZip],[BillToCountry],[BillToContactName],[BillToContactPhoneNo]," +
                             "[SellToAddress1],[SellToAddress2],[SellToCity],[SellToState],[SellToZip],[SellToCountry],[SellToContactName],[SellToContactPhoneNo],[SellToContactID],[ShipToName],[ShipToAddress1]," +
                             "[ShipToAddress2],[City],[State],[Zip],[PhoneNo],[FaxNo],[Country],[ContactName],[ContactPhoneNo],[ShipToContactID],[EntryDt],[EntryID]";


        DateTime dtShipDate = DateTime.Today.AddDays(10);

        string orderType = ((dtCustomer.Tables[0].Rows[0]["TypeofOrder"].ToString().Trim() == "") ? "01" : dtCustomer.Tables[0].Rows[0]["TypeofOrder"].ToString().Trim());
        string carrierCd = ((dtCustomer.Tables[0].Rows[0]["Shipping Agent Code"].ToString().Trim() == "") ? "01" : ((custDet.GetTablesName(dtCustomer.Tables[0].Rows[0]["Shipping Agent Code"].ToString().Trim(), "CAR") == "") ? "01" : dtCustomer.Tables[0].Rows[0]["Shipping Agent Code"].ToString().Trim()));

        string    freightCd    = ((dtCustomer.Tables[0].Rows[0]["Freight Code"].ToString().Trim() == "") ? "10" : dtCustomer.Tables[0].Rows[0]["Freight Code"].ToString().Trim());
        string    expediteCd   = ((dtCustomer.Tables[0].Rows[0]["ExpediteCd"].ToString().Trim() == "") ? "AR" : dtCustomer.Tables[0].Rows[0]["ExpediteCd"].ToString().Trim());
        string    priorityCd   = ((dtCustomer.Tables[0].Rows[0]["Priority"].ToString().Trim() == "") ? "N" : ((custDet.GetTablesName(dtCustomer.Tables[0].Rows[0]["Priority"].ToString().Trim(), "PRI") == "") ? "N" : dtCustomer.Tables[0].Rows[0]["Priority"].ToString().Trim()));
        string    reasonCd     = ((dtCustomer.Tables[0].Rows[0]["ReasonCd"].ToString().Trim() == "") ? "SO" : dtCustomer.Tables[0].Rows[0]["ReasonCd"].ToString().Trim());
        string    orderTermsCd = dtCustomer.Tables[0].Rows[0]["TradeTermCd"].ToString().Trim();
        DataTable dtTerm       = custDet.GetTermDescription(dtCustomer.Tables[0].Rows[0]["TradeTermCd"].ToString().Trim(), "TRM");
        if (dtTerm != null)
        {
            termDesc = dtTerm.Rows[0]["Dsc"].ToString();
            colorCd  = dtTerm.Rows[0]["ColorCd"].ToString().ToUpper();
        }
        string _columnValue = "'" + dtCustomer.Tables[0].Rows[0]["CustCd"].ToString().Trim() + "','" + orderType + "','" + custDet.GetListName(orderType, "SOEOrderTypes") + "'," +
                              "'" + custDet.GetSubType(orderType, "SOEOrderTypes") + "'," +
                              "'" + dtCustomer.Tables[0].Rows[0]["Customer Price Code"].ToString().Trim() + "'," +
                              "'" + dtCustomer.Tables[0].Rows[0]["fBillToNo"].ToString().Trim() + "'," +
                              "'" + dtCustomer.Tables[0].Rows[0]["No_"].ToString().Trim() + "'," +
                              "'" + dtCustomer.Tables[0].Rows[0]["Name"].ToString().Trim().Replace("'", "''") + "'," +
                              "'" + DateTime.Now.ToString() + "'," +
                              "'" + dtCustomer.Tables[0].Rows[0]["Shipping Location"].ToString().Trim() + "'," +
                              "'" + custDet.GetLocationName(dtCustomer.Tables[0].Rows[0]["Shipping Location"].ToString().Trim()) + "'," +
                              "'" + ((dtCustomer.Tables[0].Rows[0]["Usage Location"].ToString().Trim() == "") ? dtCustomer.Tables[0].Rows[0]["Shipping Location"].ToString().Trim() : dtCustomer.Tables[0].Rows[0]["Usage Location"].ToString().Trim()) + "'," +
                              "'" + ((dtCustomer.Tables[0].Rows[0]["Usage Location"].ToString().Trim() == "") ? custDet.GetLocationName(dtCustomer.Tables[0].Rows[0]["Shipping Location"].ToString().Trim()) : custDet.GetLocationName(dtCustomer.Tables[0].Rows[0]["Usage Location"].ToString().Trim())) + "'," +
                              "'" + reasonCd + "'," +
                              "'" + custDet.GetTablesName(reasonCd, "REAS") + "'," +
                              "'" + freightCd.Trim() + "'," +
                              "'" + custDet.GetTablesName(freightCd.Trim(), "FGHT") + "'," +
                              "'" + priorityCd + "'," +
                              "'" + custDet.GetTablesName(priorityCd.Trim(), "PRI") + "'," +
                              "'" + expediteCd + "'," +
                              "'" + custDet.GetTablesName(expediteCd, "EXPD") + "'," +
                              "'" + dtCustomer.Tables[0].Rows[0]["Salesperson Code"].ToString().Trim() + "'," +
                              "'" + dtCustomer.Tables[0].Rows[0]["RepName"].ToString().Trim() + "'," +
                              "'" + dtCustomer.Tables[0].Rows[0]["SupportRepNo"].ToString().Trim() + "'," +
                              "'" + dtCustomer.Tables[0].Rows[0]["SupportRepName"].ToString().Trim().Replace("'", "''") + "'," +
                              "'" + carrierCd + "'," +
                              "'" + custDet.GetTablesName(carrierCd.Trim(), "CAR") + "'," +
                              "'" + dtCustomer.Tables[0].Rows[0]["CustCd"].ToString().Trim() + "'," +
                              "'" + DateTime.Now.ToString() + "'," +
                              "'" + DateTime.Now.AddDays(1).ToString() + "'," +
                              "'" + DateTime.Now.ToString() + "'," +
                              "'" + orderTermsCd + "'," +
                              "'" + termDesc + "'";


        string billtodetail = "";
        if (dtCustomer.Tables[2].Rows.Count > 0)
        {
            //[BillToCustName],[BillToAddress1],[BillToAddress2],[BillToAddress3],[BillToCity],[BillToState],[BillToZip],[BillToCountry],[BillToContactName],[BillToContactPhoneNo]" +
            billtodetail = ",'" + dtCustomer.Tables[2].Rows[0]["Name"].ToString().Trim().Replace("'", "''") + "','" +
                           dtCustomer.Tables[2].Rows[0]["Address"].ToString().Trim().Replace("'", "''") + "','" +
                           dtCustomer.Tables[2].Rows[0]["Address 2"].ToString().Trim().Replace("'", "''") + "','" +
                           dtCustomer.Tables[2].Rows[0]["City"].ToString().Trim().Replace("'", "''") + "','" +
                           dtCustomer.Tables[2].Rows[0]["State"].ToString().Trim() + "','" +
                           dtCustomer.Tables[2].Rows[0]["Post Code"].ToString().Trim() + "','" +
                           dtCustomer.Tables[2].Rows[0]["Country"].ToString().Trim() + "','" +
                           dtCustomer.Tables[2].Rows[0]["Contact"].ToString().Trim().Replace("'", "''") + "','" +
                           dtCustomer.Tables[2].Rows[0]["CPhone"].ToString().Trim() + "'";
        }
        else
        {
            billtodetail = ",'','','','','','','','',''";
        }
        string selltodetail = "";
        if (dtCustomer.Tables[1].Rows.Count > 0)
        {
            //[BillToCustName],[BillToAddress1],[BillToAddress2],[BillToAddress3],[BillToCity],[BillToState],[BillToZip],[BillToCountry],[BillToContactName],[BillToContactPhoneNo]" +
            selltodetail = ",'" + dtCustomer.Tables[1].Rows[0]["Address"].ToString().Trim().Replace("'", "''") + "','" +
                           dtCustomer.Tables[1].Rows[0]["Address 2"].ToString().Trim().Replace("'", "''") + "','" +
                           dtCustomer.Tables[1].Rows[0]["City"].ToString().Trim().Replace("'", "''") + "','" +
                           dtCustomer.Tables[1].Rows[0]["State"].ToString().Trim() + "','" +
                           dtCustomer.Tables[1].Rows[0]["Post Code"].ToString().Trim() + "','" +
                           dtCustomer.Tables[1].Rows[0]["Country"].ToString().Trim() + "','" +
                           dtCustomer.Tables[1].Rows[0]["Contact"].ToString().Trim().Replace("'", "''") + "','" +
                           dtCustomer.Tables[1].Rows[0]["CPhone"].ToString().Trim() + "','" +
                           dtCustomer.Tables[1].Rows[0]["ContactID"].ToString().Trim() + "'";
        }
        else
        {
            selltodetail = ",'','','','','','','','',''";
        }
        string shiptodetail = "";
        if (dtCustomer.Tables[3].Rows.Count > 0)
        {
            //[City],[State],[Zip],[PhoneNo],[FaxNo],[Country],[ContactName],[ContactPhoneNo]
            shiptodetail = ",'" + dtCustomer.Tables[3].Rows[0]["Name"].ToString().Trim().Replace("'", "''") + "','" +
                           dtCustomer.Tables[3].Rows[0]["Address"].ToString().Trim().Replace("'", "''") + "','" +
                           dtCustomer.Tables[3].Rows[0]["Address 2"].ToString().Trim().Replace("'", "''") + "','" +
                           dtCustomer.Tables[3].Rows[0]["City"].ToString().Trim().Replace("'", "''") + "','" +
                           dtCustomer.Tables[3].Rows[0]["State"].ToString().Trim() + "','" +
                           dtCustomer.Tables[3].Rows[0]["Post Code"].ToString().Trim() + "','" +
                           dtCustomer.Tables[3].Rows[0]["Phone No_"].ToString().Trim() + "','" +
                           dtCustomer.Tables[3].Rows[0]["Fax No_"].ToString().Trim() + "','" +
                           dtCustomer.Tables[3].Rows[0]["Country"].ToString().Trim() + "','" +
                           dtCustomer.Tables[3].Rows[0]["Contact"].ToString().Trim().Replace("'", "''") + "','" +
                           dtCustomer.Tables[3].Rows[0]["CPhone"].ToString().Trim() + "','" +
                           dtCustomer.Tables[3].Rows[0]["ContactID"].ToString().Trim() + "'";
        }
        else
        {
            shiptodetail = ",'','','','','','','','','','','',''";
        }
        _columnValue = _columnValue + billtodetail + selltodetail + shiptodetail + ",'" + DateTime.Now.ToString() + "','" +
                       Session["UserName"].ToString() + "'";
        txtSONumber.Text = orderEntry.GetIdentityAfterInsert(_tableName, _columnName, _columnValue);

        SOOrderID = txtSONumber.Text;
        Session["OrderTableName"]  = "SOHeader";
        Session["DetailTableName"] = "SODetail";
        //Lock
        orderEntry.ReleaseLock();
        orderEntry.SetLock(SOOrderID);

        orderEntry.UpdateQuote("SoHeader", "fSOHeaderID=" + txtSONumber.Text + ",OrderNo=" + txtSONumber.Text + ",SubType=50", "pSoHeaderId=" + txtSONumber.Text);
        Session["LineItemNumber"] = "0";
        DataSet dsHeader = orderEntry.ExecuteERPSelectQuery("SOHeader", " * ", "pSOHeaderID=" + txtSONumber.Text.Trim());
        Session["HeaderDetail"] = dsHeader.Tables[0];
        #endregion

        ScriptManager.RegisterClientScriptBlock(txtSONumber, typeof(TextBox), "", "document.getElementById('" + txtSONumber.ClientID + "').focus();", true);
    }