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>");
            }
        }
Example #2
0
        private void getInventoryHistory()
        {
            var ds = Trans_History.RetrieveDataInquiry(oCon, txtSearchInput.Text);

            grvInventoryHistory.DataSource = ds;
            grvInventoryHistory.DataBind();

            for (int x = 0; x <= ds.Rows.Count - 1; x++)
            {
                string transcode = ds.Rows[x][1].ToString();
                if (transcode == "SLE")
                {
                    string picknumber = ds.Rows[x][5].ToString();

                    int idCustomer = Trans_History.GetCustomerID(oCon, picknumber);

                    var cd = Customer_Details.RetrieveData(oCon, idCustomer, "");

                    gvCustomerDetail.DataSource = cd;
                    gvCustomerDetail.DataBind();
                }
            }
        }
        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)";
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string              SLRNumber = "";
            HttpRequest         q         = Request;
            NameValueCollection n         = q.QueryString;

            if (n.HasKeys())
            {
                if (n.GetKey(0) != "")
                {
                    SLRNumber = n.Get(0);
                }
                //string SLRNumber = Session["SLRNumber"].ToString();
                if (SLRNumber != "")
                {
                    var lData = Sales_Return.RetreiveDataForPrinting(oCon, SLRNumber);

                    string DocNumber     = "";
                    string RefNum        = "";
                    string isReplacement = "";
                    string Site          = "";
                    string TransDate     = "";
                    string Address1      = "";
                    string Address2      = "";
                    string Address3      = "";
                    string Address4      = "";
                    string SupplierName  = "";
                    string Remarks       = "";

                    var listData = Return_Header.RetrieveData(oCon, "", SLRNumber);
                    RefNum        = listData[0].Document_Number;
                    isReplacement = listData[0].isReplacement;
                    DocNumber     = listData[0].Auth_Number;
                    TransDate     = listData[0].Date_Returned.ToShortDateString();
                    Remarks       = listData[0].Remarks;

                    var listSite = Site_Loc.RetrieveData(oCon, listData[0].Site);
                    Site = listSite.Rows[0][2].ToString();

                    var reselleraddress = Customer_Details.RetrieveData(oCon, 0, listData[0].Customer_Code);
                    SupplierName = reselleraddress[0].Company_Name;
                    Address1     = reselleraddress[0].Address1;
                    Address2     = reselleraddress[0].Address2;
                    Address3     = reselleraddress[0].Address3;
                    Address4     = reselleraddress[0].Address4;

                    Microsoft.Reporting.WebForms.ReportViewer viewer = new ReportViewer();
                    viewer.ProcessingMode         = Microsoft.Reporting.WebForms.ProcessingMode.Local;
                    viewer.LocalReport.ReportPath = Server.MapPath(@"~\Resources\SalesReturn.rdlc");

                    if (Address1 == "")
                    {
                        Address1 = "N/A";
                    }
                    if (Address2 == "")
                    {
                        Address2 = "N/A";
                    }
                    if (Address3 == "")
                    {
                        Address3 = "N/A";
                    }
                    if (Address4 == "")
                    {
                        Address4 = "N/A";
                    }
                    if (SupplierName == "")
                    {
                        SupplierName = "N/A";
                    }
                    if (Remarks == "")
                    {
                        Remarks = "N/A";
                    }

                    ReportParameter p1  = new ReportParameter("DocNumber", DocNumber);
                    ReportParameter p2  = new ReportParameter("RefNum", RefNum);
                    ReportParameter p3  = new ReportParameter("isReplacement", isReplacement);
                    ReportParameter p4  = new ReportParameter("Site", Site);
                    ReportParameter p5  = new ReportParameter("TransDate", TransDate);
                    ReportParameter p6  = new ReportParameter("Address1", Address1);
                    ReportParameter p7  = new ReportParameter("Address2", Address2);
                    ReportParameter p8  = new ReportParameter("Address3", Address3);
                    ReportParameter p9  = new ReportParameter("Address4", Address4);
                    ReportParameter p10 = new ReportParameter("SupplierName", SupplierName);
                    ReportParameter p11 = new ReportParameter("Remarks", Remarks);
                    ReportParameter p12 = new ReportParameter("SLRNumber", SLRNumber);

                    ReportDataSource repDataSource = new ReportDataSource("DataSet1", lData);

                    viewer.LocalReport.SetParameters(new ReportParameter[] { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12 });

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

                    Warning[] warnings;
                    string[]  streamIds;
                    string    mimeType  = string.Empty;
                    string    encoding  = string.Empty;
                    string    extension = "pdf";

                    try
                    {
                        byte[] bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
                        Response.Buffer = true;
                        Response.Clear();
                        Response.ContentType = mimeType;
                        Response.AddHeader("content-disposition", "attachment; filename= " + SLRNumber + "." + extension);
                        Response.OutputStream.Write(bytes, 0, bytes.Length); // create the file
                        Response.Flush();                                    // send it to the client to download
                        Response.End();
                    }
                    catch
                    {
                        HttpContext.Current.Response.Write("<script>alert(" + ControlChars.Quote + "Download not successful!" + ControlChars.Quote + ");</script>");
                    }
                    finally
                    {
                    }

                    //Microsoft.Reporting.WebForms.Warning[] warnings = null;
                    //string[] streamids = null;
                    //string mimeType = null;
                    //string encoding = null;
                    //string extension = null;
                    //string deviceInfo;
                    //byte[] bytes;
                    //Microsoft.Reporting.WebForms.LocalReport lr = new Microsoft.Reporting.WebForms.LocalReport();

                    //Warning[] warnings;
                    //string[] streamIds;
                    //string mimeType = string.Empty;
                    //string encoding = string.Empty;
                    //string extension = "pdf";


                    //// byte[] bytes = viewer.LocalReport.Render("Excel", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
                    //// Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
                    //// System.Web.HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    //Response.Buffer = true;
                    //Response.Clear();
                    //Response.ContentType = mimeType;
                    //Response.AddHeader("content-disposition", "attachment; filename= " + SLRNumber + "." + extension);
                    //Response.OutputStream.Write(bytes, 0, bytes.Length); // create the file
                    //Response.Flush(); // send it to the client to download
                    //Response.End();
                }
            }
        }
        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);
        }