Пример #1
0
        private void getSODetails()
        {
            if (txtSearchInput.Text.Trim() != "")
            {
                var ds = SO_Header.RetrieveData(oCon, txtSearchInput.Text, false);
                txtSONumber.Text = ds[0].SO_Number;

                var dsCustomer = Customer_Details.RetrieveData(oCon, ds[0].idCustomer, "");
                txtCustomerCode.Text = dsCustomer[0].Customer_Code;
                txtReseller.Text     = dsCustomer[0].Company_Name;
            }
            else
            {
                HttpContext.Current.Response.Write("<script>alert(" + ControlChars.Quote + "Please enter SO Number to search" + ControlChars.Quote + ");</script>");
            }
        }
        protected void grvSOInvoiceList_SelectedIndexChanged(object sender, EventArgs e)
        {
            Session["Mode"]       = "View";
            btnBack.Visible       = true;
            btnSave.Visible       = true;
            InvoicePanel.Visible  = false;
            pnlAllDetails.Visible = true;
            //btnPrint.Visible = true;
            tblSearch.Visible      = false;
            grossamt.Visible       = true;
            outputvat.Visible      = true;
            netamt.Visible         = true;
            pnlOrderReqlbl.Visible = true;
            chckTaxExempt.Enabled  = false;

            GridViewRow row = grvSOInvoiceList.SelectedRow;

            Session["idSOHeader"] = row.Cells[0].Text.Trim();

            var soheader = SO_Header.RetrieveData(oCon, row.Cells[1].Text.Trim(), false);

            Session["idCustomer"] = soheader[0].idCustomer;
            lblSONumber.Text      = soheader[0].SO_Number;
            txtOrderDate_.Text    = soheader[0].Order_Date.ToShortDateString();
            txtDueDate.Text       = soheader[0].Due_Date.ToShortDateString();
            txtDueDate_.Text      = soheader[0].Due_Date.ToShortDateString();
            ddSite.SelectedValue  = soheader[0].idSite.ToString();
            txtSite.Text          = ddSite.SelectedItem.Text;

            double output_vat = double.Parse(soheader[0].Tax_Amount.ToString());

            if (output_vat == 0.00)
            {
                chckTaxExempt.Checked = true;
            }
            else
            {
                chckTaxExempt.Checked = false;
            }

            SO_Creation model    = new SO_Creation();
            string      salesman = model.GetSalesmanByID(int.Parse(soheader[0].Salesman), oCon);

            txtSalesman.Text  = salesman;
            txtCustPONum.Text = soheader[0].Customer_PO;
            double freight_chrgs = double.Parse(soheader[0].Freight_Charges.ToString());

            txtFreightCharges.Text = freight_chrgs.ToString("n", CultureInfo.GetCultureInfo("en-US"));
            double other_chrgs = double.Parse(soheader[0].Other_Charges.ToString());

            txtOtherCharges.Text = other_chrgs.ToString("n", CultureInfo.GetCultureInfo("en-US"));
            double gross_amt = double.Parse(soheader[0].Gross_Amount.ToString());

            txtGrossAmt.Text = gross_amt.ToString("n", CultureInfo.GetCultureInfo("en-US"));
            double net_amt = double.Parse(soheader[0].Net_Amount.ToString());

            txtNetAmt.Text      = net_amt.ToString("n", CultureInfo.GetCultureInfo("en-US"));;
            txtOutputVat.Text   = output_vat.ToString("n", CultureInfo.GetCultureInfo("en-US"));
            txtRemarks.Text     = Server.HtmlDecode(soheader[0].Remarks);
            txtCurrency.Text    = soheader[0].currency_code;
            txtEndUser.Text     = soheader[0].End_User;
            txtEndUserCity.Text = soheader[0].End_User_City;
            txtStockStatus.Text = soheader[0].Stock_Status;
            Session["SOStatus"] = soheader[0].SO_Status;
            txtSpecialConc.Text = soheader[0].Special_Concession;

            var customerdetails = Customer_Details.RetrieveData(oCon, soheader[0].idCustomer, "");

            txtCustomerCode.Text        = customerdetails[0].Customer_Code;
            Session["CompanyName"]      = customerdetails[0].Company_Name;
            txtCustomerName.Text        = customerdetails[0].Company_Name;
            txtCreditTerm.Text          = customerdetails[0].credit_term;
            Session["Address1"]         = customerdetails[0].Address1;
            Session["Address2"]         = customerdetails[0].Address2;
            Session["Address3"]         = customerdetails[0].Address3;
            Session["Address4"]         = customerdetails[0].Address4;
            Session["AddressShipping1"] = customerdetails[0].AddressShipping1;
            Session["AddressShipping2"] = customerdetails[0].AddressShipping2;
            Session["AddressShipping3"] = customerdetails[0].AddressShipping3;
            Session["AddressShipping4"] = customerdetails[0].AddressShipping4;

            if (row.Cells[2].Text.Trim() != "" && row.Cells[2].Text.Trim() != "&nbsp;")
            {
                txtInvoiceDate.TextMode = TextBoxMode.SingleLine;
                var invoicedetails = Invoice.RetrieveData(oCon, row.Cells[2].Text, row.Cells[1].Text);
                txtInvoiceNumber.Text     = invoicedetails[0].Invoice_Number;
                txtInvoiceDate.Text       = invoicedetails[0].Invoice_Date.ToShortDateString();
                txtDelDate.Text           = invoicedetails[0].Del_Date.ToShortDateString();
                txtInvoiceAmount.Text     = invoicedetails[0].Amount.ToString();
                txtDRNumber.Text          = invoicedetails[0].DR_Number;
                txtORNumber.Text          = invoicedetails[0].OR_Number;
                txtInvoiceNumber.ReadOnly = true;
                txtInvoiceDate.ReadOnly   = true;
                txtInvoiceAmount.ReadOnly = true;
                txtDRNumber.ReadOnly      = true;
                btnSave.Visible           = false;
            }
            else
            {
                txtInvoiceNumber.Text     = "";
                txtInvoiceDate.Text       = "";
                txtInvoiceAmount.Text     = "";
                txtDRNumber.Text          = "";
                txtInvoiceDate.TextMode   = TextBoxMode.Date;
                txtInvoiceNumber.ReadOnly = false;
                txtInvoiceDate.ReadOnly   = false;
                txtInvoiceAmount.ReadOnly = false;
                txtDRNumber.ReadOnly      = false;
                btnSave.Visible           = true;
            }

            GetSavedItems();

            txtCustomerCode.Visible    = true;
            ddSalesman.Visible         = false;
            txtOrderDate.ReadOnly      = true;
            txtCustPONum.ReadOnly      = true;
            txtFreightCharges.ReadOnly = true;
            txtOtherCharges.ReadOnly   = true;
            txtOrderDate_.Visible      = true;
            txtOrderDate.Visible       = false;
            txtDueDate.Visible         = false;
            txtDueDate.ReadOnly        = true;
            txtDueDate_.Visible        = true;
            txtDueDate_.ReadOnly       = true;
            txtEndUser.ReadOnly        = true;
            txtEndUserCity.ReadOnly    = true;
            txtCreditTerm.Visible      = true;
            txtCurrency.Visible        = true;
            txtSalesman.Visible        = true;
            txtStockStatus.Visible     = true;
            txtOrderDate_.ReadOnly     = true;
            txtCreditTerm.ReadOnly     = true;
            txtCustomerCode.ReadOnly   = true;
            txtSite.ReadOnly           = true;
            txtCurrency.ReadOnly       = true;
            txtSalesman.ReadOnly       = true;
            txtStockStatus.ReadOnly    = true;
            txtRemarks.ReadOnly        = true;
            txtSpecialConc.ReadOnly    = true;
            lblSONumber.Visible        = true;
            lblSONumber_.Visible       = true;
            ddSite.Visible             = false;
            txtSite.Visible            = true;
            //gvItems.Enabled = false;

            lblOrderDate.Visible = true;
            lblOrderDate.Text    = "Order Date (dd/mm/yyyy)";
            lblDueDate.Text      = "Due Date (dd/mm/yyyy)";
        }
        public byte[] SOUpload(string soNumber)
        {
            Microsoft.Reporting.WebForms.ReportViewer viewer = new ReportViewer();
            viewer.ProcessingMode = ProcessingMode.Local;

            viewer.LocalReport.ReportPath = Server.MapPath(@"~\Resources\LSISalesOrder.rdlc");
            //viewer.LocalReport.ReportPath = "SalesOrder.rdlc";

            List <SO_Header_Model> soheadermodel = SO_Header.RetrieveData(connection, soNumber, false);

            string strSONumber      = soNumber;
            string strOrderDate     = soheadermodel[0].Order_Date.ToShortDateString();
            string strDueDate       = soheadermodel[0].Due_Date.ToShortDateString();
            string strCustomerPOnum = soheadermodel[0].Customer_PO;

            string strSalesman = soheadermodel[0].Salesman;

            string strCreditTerm   = soheadermodel[0].credit_term;
            string strOtherCharges = soheadermodel[0].Other_Charges.ToString();

            decimal grossamount   = soheadermodel[0].Gross_Amount;
            decimal finaldiscount = soheadermodel[0].Final_Discount;
            decimal netamount     = grossamount - soheadermodel[0].Freight_Charges - soheadermodel[0].Other_Charges;
            decimal taxamount     = grossamount * Convert.ToDecimal(1 - (1 / 1.12));

            decimal strGrossAmount   = grossamount;
            decimal strFinalDiscount = finaldiscount;
            decimal strCharges       = soheadermodel[0].Freight_Charges + soheadermodel[0].Other_Charges;
            decimal strNetAmount     = netamount;
            string  strRemarks       = soheadermodel[0].Remarks;

            List <Customer_Details_Model> customerDetails = Customer_Details.RetrieveData(connection, soheadermodel[0].idCustomer, "");

            string strCustomerCode = customerDetails[0].Customer_Code;
            string strAddress1     = customerDetails[0].Address1;
            string strAddress2     = customerDetails[0].Address2;
            string strAddress3     = customerDetails[0].Address3;
            string strAddress4     = customerDetails[0].Address4;

            string  strCompanyName  = customerDetails[0].Company_Name;
            decimal strOutputVat    = taxamount;
            decimal strTaxableSales = Convert.ToDecimal(netamount) / Convert.ToDecimal(1.12);
            string  strShipAddress1 = customerDetails[0].AddressShipping1;
            string  strShipAddress2 = customerDetails[0].AddressShipping2;
            string  strShipAddress3 = customerDetails[0].AddressShipping3;
            string  strShipAddress4 = customerDetails[0].AddressShipping4;

            var lDataAdd = SO_Detail.RetrieveDataForSOCreation(connection, soheadermodel[0].idSOHeader);

            if (strAddress1 == "&nbsp;")
            {
                strAddress1 = " ";
            }
            if (strAddress2 == "&nbsp;")
            {
                strAddress2 = " ";
            }
            if (strAddress3 == "&nbsp;")
            {
                strAddress3 = " ";
            }
            if (strAddress4 == "&nbsp;")
            {
                strAddress4 = " ";
            }
            if (strShipAddress1 == "&nbsp;")
            {
                strShipAddress1 = " ";
            }
            if (strShipAddress2 == "&nbsp;")
            {
                strShipAddress2 = " ";
            }
            if (strShipAddress3 == "&nbsp;")
            {
                strShipAddress3 = " ";
            }

            ReportParameter p1  = new ReportParameter("Order_Date", strOrderDate);
            ReportParameter p2  = new ReportParameter("Due_Date", strDueDate);
            ReportParameter p3  = new ReportParameter("Customer_PO", strCustomerPOnum);
            ReportParameter p4  = new ReportParameter("Salesman", strSalesman);
            ReportParameter p5  = new ReportParameter("credit_term", strCreditTerm);
            ReportParameter p6  = new ReportParameter("SO_Number", strSONumber);
            ReportParameter p7  = new ReportParameter("Gross_Amount", strGrossAmount.ToString("n", CultureInfo.GetCultureInfo("en-US")));
            ReportParameter p8  = new ReportParameter("Final_Discount", strFinalDiscount.ToString("n", CultureInfo.GetCultureInfo("en-US")));
            ReportParameter p9  = new ReportParameter("Charges", strCharges.ToString("n", CultureInfo.GetCultureInfo("en-US")));
            ReportParameter p10 = new ReportParameter("Net_Amount", strNetAmount.ToString("n", CultureInfo.GetCultureInfo("en-US")));
            ReportParameter p11 = new ReportParameter("Customer_Code", strCustomerCode);
            ReportParameter p12 = new ReportParameter("Address1", strAddress1);
            ReportParameter p13 = new ReportParameter("Address2", strAddress2);
            ReportParameter p14 = new ReportParameter("Address3", strAddress3);
            ReportParameter p15 = new ReportParameter("Address4", strAddress4);
            ReportParameter p16 = new ReportParameter("Remarks", strRemarks);
            ReportParameter p17 = new ReportParameter("Company_Name", strCompanyName);
            ReportParameter p18 = new ReportParameter("Output_Vat", strOutputVat.ToString("n", CultureInfo.GetCultureInfo("en-US")));
            ReportParameter p19 = new ReportParameter("Taxable_Sales", strTaxableSales.ToString("n", CultureInfo.GetCultureInfo("en-US")));
            ReportParameter p20 = new ReportParameter("AddressShipping1", strShipAddress1);
            ReportParameter p21 = new ReportParameter("AddressShipping2", strShipAddress2);
            ReportParameter p22 = new ReportParameter("AddressShipping3", strShipAddress3);

            viewer.LocalReport.SetParameters(new ReportParameter[] { p1, p2, p3, p4, p5, p6, p7,
                                                                     p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22 });


            ReportDataSource repDataSource1 = new ReportDataSource("DataSet1", lDataAdd);

            viewer.LocalReport.DataSources.Clear();
            viewer.LocalReport.DataSources.Add(repDataSource1);

            byte[] bytes = viewer.LocalReport.Render("PDF");

            DeleteFile(soheadermodel[0].idSOHeader);

            // insert data
            string     strQuery = "INSERT INTO a_SO_Attachment" + "(idSOHeader, FileName, content_type, data)" + " values (@idSOHeader, @FileName, @content_type, @data)";
            SqlCommand cmd      = new SqlCommand(strQuery);

            cmd.Parameters.Add("@idSOHeader", SqlDbType.VarChar).Value = soheadermodel[0].idSOHeader;

            cmd.Parameters.Add("@FileName", SqlDbType.VarChar).Value     = strSONumber;
            cmd.Parameters.Add("@content_type", SqlDbType.VarChar).Value = "text/html";
            cmd.Parameters.Add("@data", SqlDbType.Binary).Value          = bytes;

            InsertUpdateData(cmd);

            return(bytes);
        }