Example #1
0
    private void GetsaleCount()
    {
        DataTable ds = new DataTable();

        try
        {
            ds = ClsCheck.Get_sales_apr_pending_count();

            wrk_SO_check.Text = ds.Rows[0]["count"].ToString();
        }
        catch (Exception ex)
        {
        }
    }
    public void AddNewGridRow1()
    {
        BtnInvoiceSave0.Visible = true;
        double SubTotal = 0; double POSubTotal = 0;

        double Total = 0;

        foreach (GridViewRow row in GvwPurchaseInvocie.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                if (((TextBox)row.Cells[3].FindControl("TxtInQuantity")).Text == "")
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('please Enter Invoice Quantity.');</script>", false);
                    return;
                }
                string    HidCatagory0 = ((HiddenField)row.Cells[3].FindControl("HidCatagory0")).Value;
                string    HidProduct0  = ((HiddenField)row.Cells[3].FindControl("HidProduct0")).Value;
                DataTable DT           = ClsCheck.Get_PurchaseCheck(TxtPoNo.Text.Trim(), Convert.ToInt32(HidProduct0), Convert.ToInt32(HidCatagory0));
                int       POQUANTITY   = Convert.ToInt32(((Label)row.Cells[2].FindControl("LblPendingQuantity")).Text);
                double    POPrice      = Convert.ToDouble(((Label)row.Cells[2].FindControl("LblPrice")).Text);
                // int POQUANTITY = Convert.ToInt32(DT.Rows[0]["PO_QUANTITY"].ToString());
                // int PURCHASEIN = Convert.ToInt32(DT.Rows[0]["PURCHASE_INVOICE"].ToString());
                int TxtInQuantity1 = Convert.ToInt32(((TextBox)row.Cells[3].FindControl("TxtInQuantity")).Text);

                if (POQUANTITY < TxtInQuantity1)
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Invoice Quantity is greater than Purchase Quantity..');</script>", false);
                    return;
                }

                string PoNo       = TxtPoNo.Text;
                int    CategoryId = Convert.ToInt32(((HiddenField)row.FindControl("HidCatagory0")).Value);
                int    ProductId  = Convert.ToInt32(((HiddenField)row.FindControl("HidProduct0")).Value);
                Int32  Quantity   = Convert.ToInt32(((TextBox)row.Cells[2].FindControl("TxtInQuantity")).Text);
                double totalprice = Convert.ToDouble(((TextBox)row.Cells[2].FindControl("TxtInPrice")).Text);

                // int lblSubTot = Convert.ToInt32(((TextBox)GvwPurchaseInvocie.FooterRow.FindControl("TxtInQuantity")).Text) * Convert.ToInt32(((TextBox)GvwPurchaseInvocie.FooterRow.FindControl("TxtInPrice")).Text);
                int    TxtInQuantity = Convert.ToInt32(((TextBox)row.FindControl("TxtInQuantity")).Text);
                double TxtInPrice    = Convert.ToDouble(((TextBox)row.FindControl("TxtInPrice")).Text);

                double TotalPrice = POQUANTITY * Convert.ToDouble(POPrice);

                Label lblPototalPrice = (Label)row.FindControl("LblPOTotalPrice");
                lblPototalPrice.Text = Convert.ToString(TotalPrice.ToString("0.00"));

                double lblSubTot = TxtInQuantity * Convert.ToDouble(TxtInPrice);

                TextBox TxtInTotalPrice = (TextBox)row.FindControl("TxtInTotalPrice");
                TxtInTotalPrice.Text = Convert.ToString(lblSubTot.ToString("0.00"));

                // int lblSubTot = Convert.ToInt32(((TextBox)row.FindControl("TxtInQuantity")).Text) * Convert.ToInt32(((TextBox)row.FindControl("TxtInPrice")).Text);

                DataTable DTTaxRate = new DataTable();
                DTTaxRate = ClsPurchaseInvoice.GetInvoiceTaxRateBaseValue(PoNo, CategoryId, ProductId);
                // Label lblSubTot = (Label)GvwPurchaseOrder.FooterRow.FindControl("LblfttotalPrice");
                double TaxValue = 0; double POTaxValue = 0;
                if (DTTaxRate.Rows.Count > 0)
                {
                    for (int i = 0; i <= DTTaxRate.Rows.Count - 1; i++)
                    {
                        double POSubTotalbaseVal = Convert.ToDouble(TotalPrice) * Convert.ToDouble(DTTaxRate.Rows[i][2].ToString()) / 100;

                        double SubTotonBaseVal = Convert.ToDouble(lblSubTot) * Convert.ToDouble(DTTaxRate.Rows[i][2].ToString()) / 100;

                        POTaxValue = POTaxValue + (POSubTotalbaseVal * Convert.ToDouble(DTTaxRate.Rows[i][1].ToString()) / 100);

                        TaxValue = TaxValue + (SubTotonBaseVal * Convert.ToDouble(DTTaxRate.Rows[i][1].ToString()) / 100);
                    }
                }

                POTotalAmount = Convert.ToDouble(TotalPrice) + POTaxValue;
                TotalAmount   = Convert.ToDouble(lblSubTot) + TaxValue;

                // double tax = Convert.ToDouble(((TextBox)row.Cells[2].FindControl("txttaxid")).Text);
                // Total = (((Convert.ToDouble(totalprice * Quantity)) * tax) / 100) + (((Convert.ToDouble(totalprice * Quantity))));
                TextBox TxtInvTax = (TextBox)row.FindControl("txttaxid");
                TxtInvTax.Text = Convert.ToString(TaxValue.ToString("0.00"));

                Label Lbltaxid = (Label)row.FindControl("Lbltaxid");
                Lbltaxid.Text = Convert.ToString(POTaxValue.ToString("0.00"));

                Label LbltotalAmount = (Label)row.FindControl("LbltotalAmount");
                LbltotalAmount.Text = POTotalAmount.ToString("0.00");

                Label lbl = (Label)(row.Cells[2].FindControl("LblInvocietotalPrice"));
                lbl.Text   = TotalAmount.ToString("0.00");
                POSubTotal = POSubTotal + POTotalAmount;
                SubTotal   = SubTotal + TotalAmount;
            }
        }
        // TxtInTotalAmount.Text = Math.Floor(POSubTotal + .49).ToString("0.00");
        TxtInTotalAmount.Text = Convert.ToDouble(POSubTotal).ToString("0.00");
        // Txt_SubTotal.Text = Math.Floor(SubTotal + .49).ToString("0.00");
        Txt_SubTotal.Text = Convert.ToDouble(SubTotal).ToString("0.00");
    }
    protected void BtnInvoiceSave_Click(object sender, EventArgs e)
    {
        try
        {
            ClsPurchaseInvoice objclsinvc = new ClsPurchaseInvoice();
            if (Txt_InvoiceNo.Text != string.Empty && Txt_InvoiceDate.Text != string.Empty)
            {
                foreach (GridViewRow row in GvwPurchaseInvocie.Rows)
                {
                    if (((TextBox)row.Cells[3].FindControl("TxtInQuantity")).Text == "")
                    {
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('please Enter Invoice Quantity.');</script>", false);
                        return;
                    }
                    double TxtInPriceUpdate      = Convert.ToDouble(((TextBox)row.FindControl("TxtInPrice")).Text);
                    double TxtInTotalPriceUpdate = Convert.ToDouble(((TextBox)row.FindControl("TxtInTotalPrice")).Text);
                    Int32  TxtInQuantityUpdate   = Convert.ToInt32(((TextBox)row.Cells[3].FindControl("TxtInQuantity")).Text);
                    double Sum    = Convert.ToDouble((TxtInPriceUpdate * TxtInQuantityUpdate).ToString("0.00"));
                    double prvSum = Convert.ToDouble(TxtInTotalPriceUpdate.ToString("0.00"));
                    if (Sum != prvSum)
                    {
                        this.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", "<script type=text/javascript>alert('Please click on Update Button..')</script>");
                        Button BtnAdd = (Button)GvwPurchaseInvocie.FooterRow.FindControl("BtnAdd");
                        BtnAdd.Focus();
                        return;
                    }
                }
                //Check point
                //--t_purchase order detail and t_purchareinvoicedetail
                //string pono = TxtPoNo.Text;
                foreach (GridViewRow row in GvwPurchaseInvocie.Rows)
                {
                    if (row.RowType == DataControlRowType.DataRow)
                    {
                        string    HidCatagory0 = ((HiddenField)row.Cells[3].FindControl("HidCatagory0")).Value;
                        string    HidProduct0  = ((HiddenField)row.Cells[3].FindControl("HidProduct0")).Value;
                        DataTable DT           = ClsCheck.Get_PurchaseCheck(TxtGRNNum.Text.Trim(), Convert.ToInt32(HidProduct0), Convert.ToInt32(HidCatagory0));
                        int       POQUANTITY   = Convert.ToInt32(((Label)row.Cells[2].FindControl("LblQuantity")).Text);

                        //int POQUANTITY = Convert.ToInt32(DT.Rows[0]["PO_QUANTITY"].ToString());
                        //int PURCHASEIN = Convert.ToInt32(DT.Rows[0]["PURCHASE_INVOICE"].ToString());
                        int TxtInQuantity = Convert.ToInt32(((TextBox)row.Cells[3].FindControl("TxtInQuantity")).Text);

                        if (POQUANTITY < TxtInQuantity)
                        {
                            ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Invoice Quantity is greater than Purchase Quantity..');</script>", false);
                            return;
                        }
                    }
                }

                string   asd       = hidDetails_ID.Value;
                DateTime PODATE    = Convert.ToDateTime(TxtPoDate.Text);
                string   GRNnumber = TxtGRNNum.Text;

                int      invoiceid;
                DateTime invoicedate = DateTime.Now;
                string   invoiceno = ""; string totalAmount = "";
                invoicedate = Convert.ToDateTime(Txt_InvoiceDate.Text.Trim());
                invoiceno   = Txt_InvoiceNo.Text.Trim();
                totalAmount = Txt_SubTotal.Text.Trim();


                //taxid = Convert.ToInt32(DrpTaxType.SelectedItem.Value);
                result2 = ClsPurchaseInvoice.InsertPurchaseGRNInvoice(out invoiceid, Convert.ToInt32(asd), GRNnumber, PODATE,
                                                                      invoiceno, invoicedate, Convert.ToDouble(totalAmount), Convert.ToInt32(Session["Id"]), "");
                if (result2)
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('invoice Saved Successfully...');</script>", false);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('invoice Insertion Failed...');</script>", false);
                }


                foreach (GridViewRow row in GvwPurchaseInvocie.Rows)
                {
                    if (row.RowType == DataControlRowType.DataRow)
                    {
                        string LblSlno       = ((Label)row.Cells[0].FindControl("LblSlno")).Text;
                        Int64  HidPODetId    = Convert.ToInt32(((HiddenField)row.Cells[2].FindControl("HdfPODETID")).Value);
                        string lblCatagory   = ((Label)row.Cells[1].FindControl("lblCatagory")).Text;
                        Int32  HidCatagory0  = Convert.ToInt32(((HiddenField)row.Cells[2].FindControl("HidCatagory0")).Value);
                        string LblProduct    = ((Label)row.Cells[3].FindControl("LblProduct")).Text;
                        Int32  HidProduct0   = Convert.ToInt32(((HiddenField)row.Cells[4].FindControl("HidProduct0")).Value);
                        Int32  LblQuantity   = Convert.ToInt32(((Label)row.Cells[3].FindControl("LblQuantity")).Text);
                        double LblPrice      = Convert.ToDouble(((Label)row.Cells[3].FindControl("LblPrice")).Text);
                        double POTaxPrice    = Convert.ToDouble(((Label)row.Cells[3].FindControl("Lbltaxid")).Text);
                        double pototalamount = Convert.ToDouble(((Label)row.Cells[3].FindControl("LbltotalAmount")).Text);

                        string TxtInQuantity      = ((TextBox)row.Cells[3].FindControl("TxtInQuantity")).Text;
                        string TxtInPrice         = ((TextBox)row.Cells[4].FindControl("TxtInPrice")).Text;
                        double invoicetotalamount = Convert.ToDouble(((Label)row.Cells[3].FindControl("LblInvocietotalPrice")).Text);
                        string InvoiceTaxPrice    = ((TextBox)row.Cells[3].FindControl("txttaxid")).Text;

                        string loaction     = Txt_shippingAdress.Text.Trim();
                        string MainLocation = TxtPoLocation.Text;

                        result1 = ClsPurchaseInvoice.InsertPurchaseGRNInvoicedetails(invoiceid, Convert.ToInt32(asd), HidCatagory0, HidProduct0,
                                                                                     LblQuantity, LblPrice, POTaxPrice, pototalamount,
                                                                                     Convert.ToInt32(TxtInQuantity), Convert.ToDouble(TxtInPrice), InvoiceTaxPrice, invoicetotalamount, Convert.ToInt32(Session["Id"].ToString()), loaction, LblProduct, invoicedate, MainLocation, Convert.ToInt32(Session["int_LocationId"]), HidPODetId);
                    }
                }

                Txt_InvoiceNo.Text   = "";
                Txt_InvoiceDate.Text = "";
                Txt_SubTotal.Text    = "0.00";

                TxtInTotalAmount.Text = "0.00";
                GetSalesManager();
                Panel1.Visible = false; Panel2.Visible = true; tbldate.Visible = true;
            }
            else
            {
                if (Txt_InvoiceNo.Text == "")
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Please Enter Invoice Number.');</script>", false);
                    Txt_InvoiceNo.Focus();
                    return;
                }
                if (Txt_InvoiceDate.Text == "")
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Please Select Invoice Date.');</script>", false);
                    Txt_InvoiceDate.Focus();
                    return;
                }
                //if (Txt_InvoiceDate.Text != "")
                //{
                //    DateTime PODate = Convert.ToDateTime(TxtPoDate.Text);
                //    DateTime PO_date = Convert.ToDateTime(PODate.ToString("dd/MM/yyyy"));
                //    DateTime InvoiceDate = Convert.ToDateTime(Txt_InvoiceDate.Text);
                //    DateTime Invoice_Date = Convert.ToDateTime(InvoiceDate.ToString("dd/MM/yyyy"));
                //    if (PO_date > Invoice_Date)
                //    {
                //        ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Invoice Date Should be Greater Than PO Date.');</script>", false);
                //        TxtPoDate.Focus();
                //        return;
                //    }
                //}
                //if (TxtLorryRcptNum.Text == "")
                //{
                //    ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Please Enter Lorry receipt number.');</script>", false);
                //    TxtLorryRcptNum.Focus();
                //    return;

                //}
                // ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Please Fill Invoice Number and Invoice Date...');</script>", false);
            }
        }
        catch (Exception ex)
        {
        }
    }
Example #4
0
        private void buttonXOneKeyCoding_Click(object sender, EventArgs e)
        {
            bool   isContainNullCoding        = false;
            string temPath                    = @"D:\temp";
            string nameWithExtentionBuffer    = null;
            string nameWithExtentionIndentity = null;

            //判断输出路径是否合法
            try
            {
                if (!System.IO.Directory.Exists(temPath))
                {
                    Directory.CreateDirectory(temPath);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("路径无效!");
            }
            try
            {
                isContainNullCoding = ClsCheck.CheckNullField(pdicLayer[this.comboBoxExOriLayer.SelectedItem.ToString()], "ENTIID");
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("没有选择源图层,请选择源图层");
            }
            //首先对源图层A的编码进行空值检查
            if (!isContainNullCoding)
            {
                //对源图层进行缓冲区分析生成缓冲区图层B
                ClsBuffer pBuffer = new ClsBuffer();
                nameWithExtentionBuffer = pBuffer.ReturnshpPath(pdicLayer[this.comboBoxExOriLayer.SelectedItem.ToString()].Name);
                temPath = temPath + "\\" + nameWithExtentionBuffer;
                pBuffer.ReturnBufferFeatureClass(pdicLayer[this.comboBoxExOriLayer.Text] as IFeatureLayer, temPath, double.Parse(this.textBoxX1.Text.ToString()), this.comboBoxExDistance.SelectedItem.ToString());
                if (!pdic.ContainsKey(nameWithExtentionBuffer.Substring(0, nameWithExtentionBuffer.LastIndexOf("."))))
                {
                    pdic.Add(nameWithExtentionBuffer.Substring(0, nameWithExtentionBuffer.LastIndexOf(".")), temPath);
                }
                if (!pdicFeatureClass.ContainsKey(nameWithExtentionBuffer.Substring(0, nameWithExtentionBuffer.LastIndexOf("."))))
                {
                    pdicFeatureClass.Add(nameWithExtentionBuffer.Substring(0, nameWithExtentionBuffer.LastIndexOf(".")), ClsCommon.ReadFeatureClass(temPath));
                }

                //让缓冲区图层B和待匹配编码图层C作标识叠加分析得到图层D
                ClsIndentity pIndentity = new ClsIndentity();
                nameWithExtentionIndentity = pIndentity.ReturnshpPath(pdicLayer[this.comboBoxExMatLayer.SelectedItem.ToString()].Name);
                temPath = @"D:\temp";
                temPath = temPath + "\\" + nameWithExtentionIndentity;

                pIndentity.ReturnIndentityFeatureClass((pdicLayer[this.comboBoxExMatLayer.Text] as IFeatureLayer).FeatureClass, pdicFeatureClass[nameWithExtentionBuffer.Substring(0, nameWithExtentionBuffer.LastIndexOf("."))], temPath);
                pdic.Add(nameWithExtentionIndentity.Substring(0, nameWithExtentionIndentity.LastIndexOf(".")), temPath);
                pdicFeatureClass.Add(nameWithExtentionIndentity.Substring(0, nameWithExtentionIndentity.LastIndexOf(".")), ClsCommon.ReadFeatureClass(temPath));
                //遍历D图层字段,找到图层D和图层C的对应关系,也就是图层B和图层A的对应关系,从而找到A和B几何匹配成功的要素
                GetMatchedOID(pdicFeatureClass[nameWithExtentionIndentity.Substring(0, nameWithExtentionIndentity.LastIndexOf("."))], "ORIG_FID", "FID");
                //不进行属性检查就编码
                ClsCoding pCode = new ClsCoding();
                GetMatchedOIDENTIID(pdicLayer[this.comboBoxExOriLayer.Text] as IFeatureLayer, pdicOid, "ENTIID");
                pCode.PointCoding(pdicLayer[this.comboBoxExMatLayer.Text] as IFeatureLayer, pdicOid, pdiOri, "ENTIID");
                //对匹配成功的要素进行属性匹配,只要有一条属性匹配成功,那么就认为是同一个地理实体,把图层A的地理编码赋值给同名要素

                //遍历B图层,对没有匹配成功的字段进行编码
                pCode.PointCodingRest(pdicLayer[this.comboBoxExMatLayer.Text] as IFeatureLayer, pdiOri, "ENTIID");
            }
            else
            {
                MessageBox.Show("源图层编码含有空值,请重新编码后,再进行匹配操作!");
            }
            MessageBox.Show("点实体编码成功!");
        }
    protected void BtnInvoiceSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (Txt_InvoiceDate.Text != "" && Txt_InvoiceNo.Text != "")
            {
                //Check point
                //--t_purchase order detail and t_purchareinvoicedetail
                //string pono = TxtPoNo.Text;
                foreach (GridViewRow row in GvwPurchaseInvocie.Rows)
                {
                    if (row.RowType == DataControlRowType.DataRow)
                    {
                        string    HidProduct0   = ((HiddenField)row.Cells[3].FindControl("HidProduct0")).Value;
                        DataTable DT            = ClsCheck.Get_SalesCheck(TxtPoNo.Text.Trim(), Convert.ToInt32(HidProduct0));
                        int       POQUANTITY    = Convert.ToInt32(DT.Rows[0]["SO_QUANTITY"].ToString());
                        int       PURCHASEIN    = Convert.ToInt32(DT.Rows[0]["SALES_INVOICE"].ToString());
                        int       TxtInQuantity = Convert.ToInt32(((TextBox)row.Cells[3].FindControl("TxtInQuantity")).Text);
                        if (POQUANTITY < PURCHASEIN + TxtInQuantity)
                        {
                            this.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", "<script type=text/javascript>alert('Check Invoice Quantity')</script>");
                            return;
                        }
                    }
                }


                string   asd      = hidDetails_ID.Value;
                DateTime PODATE   = Convert.ToDateTime(TxtPoDate.Text);
                string   ponumber = TxtPoNo.Text;

                int      invoiceid;
                DateTime invoicedate = DateTime.Now;
                string   invoiceno = ""; string totalAmount = "";
                invoicedate = Convert.ToDateTime(Txt_InvoiceDate.Text.Trim());
                invoiceno   = Txt_InvoiceNo.Text.Trim();

                totalAmount = Txt_SubTotal.Text.Trim();
                //taxid = Convert.ToInt32(DrpTaxType.SelectedItem.Value);
                result2 = ClsSalesRegister.InsertSalesInvoice(out invoiceid, Convert.ToInt32(asd), ponumber, PODATE,
                                                              invoiceno, invoicedate, Convert.ToDouble(totalAmount), Convert.ToInt32(Session["Id"]));
                if (result2)
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('invoice Saved Successfully...');</script>", false);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('invoice Insertion Failed...');</script>", false);
                }


                foreach (GridViewRow row in GvwPurchaseInvocie.Rows)
                {
                    if (row.RowType == DataControlRowType.DataRow)
                    {
                        string LblSlno       = ((Label)row.Cells[0].FindControl("LblSlno")).Text;
                        string lblCatagory   = ((Label)row.Cells[1].FindControl("lblCatagory")).Text;
                        Int32  HidCatagory0  = Convert.ToInt32(((HiddenField)row.Cells[2].FindControl("HidCatagory0")).Value);
                        string LblProduct    = ((Label)row.Cells[3].FindControl("LblProduct")).Text;
                        Int32  HidProduct0   = Convert.ToInt32(((HiddenField)row.Cells[4].FindControl("HidProduct0")).Value);
                        Int32  LblQuantity   = Convert.ToInt32(((Label)row.Cells[3].FindControl("LblQuantity")).Text);
                        double LblPrice      = Convert.ToDouble(((Label)row.Cells[3].FindControl("LblPrice")).Text);
                        double POTaxPrice    = Convert.ToDouble(((Label)row.Cells[3].FindControl("Lbltaxid")).Text);
                        double pototalamount = Convert.ToDouble(((Label)row.Cells[3].FindControl("LbltotalAmount")).Text);

                        string TxtInQuantity      = ((TextBox)row.Cells[3].FindControl("TxtInQuantity")).Text;
                        string TxtInPrice         = ((TextBox)row.Cells[4].FindControl("TxtInPrice")).Text;
                        double invoicetotalamount = Convert.ToDouble(((Label)row.Cells[3].FindControl("LblInvocietotalPrice")).Text);
                        string InvoiceTaxPrice    = ((TextBox)row.Cells[3].FindControl("txttaxid")).Text;

                        string loaction = TxtSoLocation.Text.Trim();

                        result1 = ClsSalesRegister.InsertSalesInvoicedetails(invoiceid, Convert.ToInt32(asd), HidCatagory0, HidProduct0,
                                                                             LblQuantity, LblPrice, POTaxPrice, pototalamount,
                                                                             Convert.ToInt32(TxtInQuantity), Convert.ToDouble(TxtInPrice), InvoiceTaxPrice, invoicetotalamount, Convert.ToInt32(Session["Id"].ToString()), loaction, LblProduct, invoicedate);
                    }
                }



                Txt_InvoiceNo.Text   = "";
                Txt_InvoiceDate.Text = "";
                Txt_SubTotal.Text    = "0.00";

                TxtInTotalAmount.Text = "0.00";
                GetSalesManager();
                Panel1.Visible = false; Panel2.Visible = true;
            }
        }
        catch (Exception ex)
        {
        }
    }
    protected void BtnGRNSave_Click(object sender, EventArgs e)
    {
        try
        {
            ClsPurchaseInvoice objclsinvc = new ClsPurchaseInvoice();
            if (Txt_InvoiceDate.Text != string.Empty && TxtLorryRcptNum.Text != string.Empty)
            {
                foreach (GridViewRow row in GvwPurchaseInvocie.Rows)
                {
                    if (((TextBox)row.FindControl("TxtInQuantity")).Text == "")
                    {
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Please Enter GRN Quantity.');</script>", false);
                        return;
                    }
                    if (((TextBox)row.FindControl("TxtInQuantity")).Text != "0")
                    {
                        if (((TextBox)row.FindControl("txtSupRefNo")).Text == "")
                        {
                            ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Please Enter Supplier Reference Number.');</script>", false);
                            return;
                        }
                        else if (((TextBox)row.FindControl("txtSupRefDate")).Text == "")
                        {
                            ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Please Select Supplier Reference Date.');</script>", false);
                            return;
                        }
                    }
                    //else if (Txt_InvoiceDate.Text != "")
                    // {
                    DateTime GRNDate = Convert.ToDateTime(Txt_InvoiceDate.Text);

                    string TxtSupRefDate = ((TextBox)row.FindControl("txtSupRefDate")).Text;
                    if (TxtSupRefDate.ToString() != string.Empty || TxtSupRefDate.ToString() != "")
                    {
                        DateTime SupRefDate = Convert.ToDateTime(TxtSupRefDate);

                        if (SupRefDate > GRNDate)
                        {
                            // lblshowmsg.Text = "Supper reference date can't be greater than GRN date.";
                            ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Supper reference date can not be greater than GRN date.');</script>", false);
                            //ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Supper reference date can't be greater than GRN date.');</script>", false);
                            ((TextBox)row.FindControl("txtSupRefDate")).Focus();
                            return;
                        }
                    }

                    //}
                    double TxtInPriceUpdate      = Convert.ToDouble(((TextBox)row.FindControl("TxtInPrice")).Text);
                    double TxtInTotalPriceUpdate = Convert.ToDouble(((TextBox)row.FindControl("TxtInTotalPrice")).Text);
                    Int32  TxtInQuantityUpdate   = Convert.ToInt32(((TextBox)row.Cells[3].FindControl("TxtInQuantity")).Text);
                    double Sum    = Convert.ToDouble((TxtInPriceUpdate * TxtInQuantityUpdate).ToString("0.00"));
                    double prvSum = Convert.ToDouble(TxtInTotalPriceUpdate.ToString("0.00"));
                    if (Sum != prvSum)
                    {
                        this.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", "<script type=text/javascript>alert('Please click on Update Button..')</script>");
                        Button BtnAdd = (Button)GvwPurchaseInvocie.FooterRow.FindControl("BtnAdd");
                        BtnAdd.Focus();
                        return;
                    }
                }
                //Check point
                //--t_purchase order detail and t_purchareinvoicedetail
                //string pono = TxtPoNo.Text;
                foreach (GridViewRow row in GvwPurchaseInvocie.Rows)
                {
                    if (row.RowType == DataControlRowType.DataRow)
                    {
                        string    HidCatagory0 = ((HiddenField)row.Cells[3].FindControl("HidCatagory0")).Value;
                        string    HidProduct0  = ((HiddenField)row.Cells[3].FindControl("HidProduct0")).Value;
                        DataTable DT           = ClsCheck.Get_PurchaseCheck(TxtPoNo.Text.Trim(), Convert.ToInt32(HidProduct0), Convert.ToInt32(HidCatagory0));
                        int       POQUANTITY   = Convert.ToInt32(((Label)row.Cells[2].FindControl("LblQuantity")).Text);

                        //int POQUANTITY = Convert.ToInt32(DT.Rows[0]["PO_QUANTITY"].ToString());
                        //int PURCHASEIN = Convert.ToInt32(DT.Rows[0]["PURCHASE_INVOICE"].ToString());
                        int TxtInQuantity = Convert.ToInt32(((TextBox)row.Cells[3].FindControl("TxtInQuantity")).Text);

                        if (POQUANTITY < TxtInQuantity)
                        {
                            ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('GRN Quantity is greater than Purchase Quantity..');</script>", false);
                            return;
                        }
                    }
                }

                string POId = hidDetails_ID.Value;
                // string POId = ddlPONo.SelectedValue;
                DateTime PODATE   = Convert.ToDateTime(TxtPoDate.Text);
                string   ponumber = TxtPoNo.Text;

                int      GRNid;
                DateTime GRNdate     = DateTime.Now;
                string   totalAmount = "";
                GRNdate = Convert.ToDateTime(Txt_InvoiceDate.Text.Trim());
                //invoiceno = Txt_InvoiceNo.Text.Trim();
                totalAmount = Txt_SubTotal.Text.Trim();
                //showing alert if grn value is 0
                if (Txt_SubTotal.Text == "0" || Txt_SubTotal.Text == "0.0" || Txt_SubTotal.Text == "0.00")
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('GRN Total  Amount can not be 0...');</script>", false);
                    return;
                }

                //taxid = Convert.ToInt32(DrpTaxType.SelectedItem.Value);
                result2 = ClsGoodsReceiptNote.InsertPurchaseGRN(out GRNid, Convert.ToInt32(POId), ponumber, PODATE,
                                                                GRNdate, Convert.ToDouble(totalAmount), Convert.ToInt32(Session["Id"]), TxtLorryRcptNum.Text.Trim(), txtVehicleNum.Text.Trim(), txtAWBNum.Text.Trim());
                if (result2)
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('GRN Saved Successfully...');</script>", false);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('GRN Insertion Failed...');</script>", false);
                }

                DataTable dtGRN = new DataTable();
                dtGRN.Columns.Add("State", typeof(string));
                dtGRN.Columns.Add("Location", typeof(string));
                dtGRN.Columns.Add("Category", typeof(string));
                dtGRN.Columns.Add("Product", typeof(string));
                dtGRN.Columns.Add("RecvdQuantity", typeof(string));

                foreach (GridViewRow row in GvwPurchaseInvocie.Rows)
                {
                    if (row.RowType == DataControlRowType.DataRow)
                    {
                        string LblSlno       = ((Label)row.Cells[0].FindControl("LblSlno")).Text;
                        Int64  HidPODetId    = Convert.ToInt32(((HiddenField)row.Cells[2].FindControl("HdfPODETID")).Value);
                        string lblCatagory   = ((Label)row.Cells[1].FindControl("lblCatagory")).Text;
                        Int32  HidCatagory0  = Convert.ToInt32(((HiddenField)row.Cells[2].FindControl("HidCatagory0")).Value);
                        string LblProduct    = ((Label)row.Cells[3].FindControl("LblProduct")).Text;
                        Int32  HidProduct0   = Convert.ToInt32(((HiddenField)row.Cells[4].FindControl("HidProduct0")).Value);
                        Int32  LblQuantity   = Convert.ToInt32(((Label)row.Cells[3].FindControl("LblQuantity")).Text);
                        double LblPrice      = Convert.ToDouble(((Label)row.Cells[3].FindControl("LblPrice")).Text);
                        double POTaxPrice    = Convert.ToDouble(((Label)row.Cells[3].FindControl("Lbltaxid")).Text);
                        double pototalamount = Convert.ToDouble(((Label)row.Cells[3].FindControl("LbltotalAmount")).Text);

                        string TxtInQuantity      = ((TextBox)row.Cells[3].FindControl("TxtInQuantity")).Text;
                        string TxtInPrice         = ((TextBox)row.Cells[4].FindControl("TxtInPrice")).Text;
                        double invoicetotalamount = Convert.ToDouble(((Label)row.Cells[3].FindControl("LblInvocietotalPrice")).Text);
                        string InvoiceTaxPrice    = ((TextBox)row.Cells[3].FindControl("txttaxid")).Text;

                        string loaction     = TxtShippingAddress.Text.Trim();
                        string MainLocation = TxtPoLocation.Text;
                        //added by sita for getting supplier ref number and date as per the new changes.

                        string SupRefNo = ((TextBox)row.FindControl("txtSupRefNo")).Text;
                        // ((TextBox)row.Cells[3].FindControl("txtSupRefNo")).Text;
                        string   TxtSupRefDate = ((TextBox)row.FindControl("txtSupRefDate")).Text;
                        DateTime SupRefDate    = System.DateTime.Now;
                        if (TxtSupRefDate.ToString() != string.Empty)
                        {
                            SupRefDate = Convert.ToDateTime(TxtSupRefDate);
                        }
                        //((TextBox)row.Cells[3].FindControl("txtSupRefDate")).Text;
                        if (TxtInQuantity != "0")
                        {
                            result1 = ClsGoodsReceiptNote.Insert_Po_GRN_Details(GRNid, Convert.ToInt32(POId), HidCatagory0, HidProduct0,
                                                                                LblQuantity, LblPrice, POTaxPrice, pototalamount, Convert.ToInt32(TxtInQuantity), Convert.ToDouble(TxtInPrice),
                                                                                InvoiceTaxPrice, invoicetotalamount, Convert.ToInt32(Session["Id"].ToString()), loaction, LblProduct, GRNdate, MainLocation,
                                                                                Convert.ToInt32(Session["int_LocationId"]), HidPODetId, SupRefNo, SupRefDate);

                            DataRow drGRN = dtGRN.NewRow();
                            drGRN["State"]         = TxtPoSupplierState.Text;
                            drGRN["Location"]      = TxtPoLocation.Text;
                            drGRN["Category"]      = lblCatagory;
                            drGRN["Product"]       = LblProduct;
                            drGRN["RecvdQuantity"] = TxtInQuantity;
                            dtGRN.Rows.Add(drGRN);
                        }
                    }
                }
                if (dtGRN.Rows.Count > 0)
                {
                    ClsSalesOrder objclsSo       = new ClsSalesOrder();
                    int           SentMailResult = objclsSo.Send_Mail_GRN_RecivedQuantity_Details(dtGRN);
                }

                // Txt_InvoiceNo.Text = "";
                Txt_InvoiceDate.Text  = "";
                Txt_SubTotal.Text     = "0.00";
                txtAWBNum.Text        = "";
                TxtInTotalAmount.Text = "0.00";
                GetGeneratePoDetails();
                Panel1.Visible = false; Panel2.Visible = true; tbldate.Visible = true;
            }
            else
            {
                //if (Txt_InvoiceNo.Text == "")
                //{
                //    ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Please Enter Invoice Number.');</script>", false);
                //    Txt_InvoiceNo.Focus();
                //    return;

                //}
                if (Txt_InvoiceDate.Text == "")
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Please Select GRN Date.');</script>", false);
                    Txt_InvoiceDate.Focus();
                    return;
                }

                //if (Txt_InvoiceDate.Text != "")
                //{
                //    DateTime PODate = Convert.ToDateTime(TxtPoDate.Text);
                //    DateTime PO_date = Convert.ToDateTime(PODate.ToString("dd/MM/yyyy"));
                //    DateTime InvoiceDate = Convert.ToDateTime(Txt_InvoiceDate.Text);
                //    DateTime Invoice_Date = Convert.ToDateTime(InvoiceDate.ToString("dd/MM/yyyy"));
                //    if (PO_date > Invoice_Date)
                //    {
                //        ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Invoice Date Should be Greater Than PO Date.');</script>", false);
                //        TxtPoDate.Focus();
                //        return;
                //    }
                //}
                if (TxtLorryRcptNum.Text == "")
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Please Enter Lorry receipt number.');</script>", false);
                    TxtLorryRcptNum.Focus();
                    return;
                }
                // ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Please Fill Invoice Number and Invoice Date...');</script>", false);
            }
        }
        catch (Exception ex)
        {
        }
    }