Пример #1
0
    protected void btnAdd_FPS_Click(object sender, EventArgs e)
    {
        try
        {
            float Issued_Quant = CheckNull(txtquant.Text);
            if (ddlcomdty.SelectedItem.Text == "-Select-" || ddlscheme.SelectedItem.Text == "-Select-" || ddl_fps_name.SelectedItem.Text == "--Select--")
            {
                Page.RegisterClientScriptBlock("asdsad", "<script language=javascript > alert('Please select Commodity/Scheme');</script>");
            }
            else if (Issued_Quant == 0)
            {
                Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Quantity Should not be Zero ....'); </script> ");
            }
            else if (ddlsarrival.SelectedItem.Text == "--Select--" || ddlgodown.SelectedItem.Text == "--Select--")
            {
                Page.RegisterClientScriptBlock("myscript", "<script language=javascript > alert('Select Stock Issued from or Dispatch Godown...');</script>");
            }
            else if (txtbqty.Text == "" || txtcurbags.Text == "")
            {
                Page.RegisterClientScriptBlock("myscript", "<script language=javascript > alert('Balance Quantity is Less than Issued Stock of Commodity...');</script>");
            }
            else
            {
                string temp = "NNN";
                dt = (DataTable)Session["dt"];
                int row = 0;
                if (dt.Rows.Count > 0)
                {
                    while (row < dt.Rows.Count)
                    {
                        if (dt.Rows[row][0].ToString() == ddl_fps_name.SelectedItem.Value && dt.Rows[row][2].ToString() == ddlcomdty.SelectedItem.Value && dt.Rows[row][4].ToString() == ddlscheme.SelectedItem.Value)
                        {
                            temp = "YYY";
                            break;
                        }
                        row = row + 1;
                    }
                }
                if (temp == "YYY")
                {
                    Page.RegisterClientScriptBlock("asdsad", "<script language=javascript > alert('Quantity to be selected FPS/Commodity/Scheme Already Issued ...');</script>");
                    Label1.Text      = "Quantity to be selected FPS/Commodity/Scheme Already Issued";
                    Label1.ForeColor = System.Drawing.Color.Red;
                }
                else
                {
                    if (Convert.ToDecimal(txtquant.Text) > Convert.ToDecimal(txtbqty.Text) && Convert.ToInt32(txtbagno.Text) > Convert.ToInt32(txtcurbags.Text))
                    {
                        Page.RegisterClientScriptBlock("myscript", "<script language=javascript > alert('Quantity to Issue can not be greater than Balance Stock of Commodity...');</script>");
                        txtquant.Text = "";
                        txtquant.Focus();
                    }

                    else
                    {
                        pnl_Grid.Visible = true;
                        tr1.Visible      = true;
                        Gv_FPS_Details.Columns[1].Visible = false;
                        dt = (DataTable)Session["dt"];
                        dt.Rows.Add(ddl_fps_name.SelectedItem.Value, ddl_fps_name.SelectedItem.Text, ddlcomdty.SelectedItem.Value, ddlcomdty.SelectedItem.Text, ddlscheme.SelectedItem.Value, ddlscheme.SelectedItem.Text, txtbagno.Text, txtquant.Text);
                        Gv_FPS_Details.DataSource = dt;
                        Gv_FPS_Details.DataBind();
                        Session["dt"] = dt;
                        txtbagno.Text = "";
                        txtquant.Text = "";
                        txtbagno.Focus();
                        int rcount = 0;
                        while (rcount < dt.Rows.Count)
                        {
                            rcount = rcount + 1;
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Page.RegisterClientScriptBlock("myscript", "<script language=javascript > alert('Please Try Again...');</script>");
        }
    }
Пример #2
0
    protected void btnsave_Click(object sender, EventArgs e)
    {
        try
        {
            DateTime my1       = Convert.ToDateTime(getDate_MDY(DaintyDate1.Text));
            string   month     = my1.Month.ToString();
            string   year      = my1.Year.ToString();
            string   Chalan_no = txttrukcno.Text.Trim().ToString();
            Session["doforprint"] = Chalan_no;
            string opid  = Session["OperatorId"].ToString();
            string state = Session["State_Id"].ToString();

            mobj1 = new MoveChallan(ComObj);
            string Bookno       = txtbookno.Text.Trim().ToString();
            string saral_no     = txt_Saral.Text.Trim().ToString();
            string BuiltyNo     = txtBuiltyno.Text.Trim().ToString();
            string BuiltyDate   = getDate_MDY(txtbuiltydate.Text);
            string dispatchdate = getDate_MDY(DaintyDate1.Text);

            string commodity_id = ddlcomdty.SelectedValue;
            string Scheme_id    = ddlscheme.SelectedValue;

            Stock_Source = ddlsarrival.SelectedValue;
            string Issued_Godown = ddlgodown.SelectedValue;

            Godown_From = ddlgodown.SelectedValue;
            Session["Dispatch_godown"] = Godown_From;
            string District_From = lbldist.Text;
            string Depot_From    = lbldepo.Text;

            string Issued_Dist  = ddldistrict.SelectedValue;
            string Issued_Depot = ddlissuecenter.SelectedValue;
            string Issued_Block = ddl_block.SelectedValue;
            string Issued_FPS   = ddl_fps_name.SelectedValue;

            int   Issued_Bags  = CheckNullInt(txtbagno.Text);
            float Issued_Quant = CheckNull(txtquant.Text);
            float Bal_Quant    = CheckNull(txtbqty.Text);

            string Transporter = ddltransporter.SelectedValue;
            string Drivername  = txt_Driver.Text.Trim().ToString();
            string mudate      = "";
            string mdstatus    = "N";
            string remark      = txtremark.Text.ToString();
            string ip          = Request.ServerVariables["REMOTE_ADDR"].ToString();

            string notrans  = "N";
            string qreychal = "select Challan_No from dbo.tbl_TruckChalan_FPS where Depot_Id='" + issueid + "' and Dist_ID='" + distid + "' and Challan_No='" + Chalan_no + "'";
            cmd = new SqlCommand(qreychal, con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet        ds = new DataSet();
            da.Fill(ds, "tbl_TruckChalan_FPS");
            if (ds.Tables[0].Rows.Count == 0)
            {
                dt = (DataTable)Session["dt"];
                int countrw = dt.Rows.Count;
                if (countrw > 0)
                {
                    if (Bal_Quant < Issued_Quant)
                    {
                        Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('You Have Insufficieant Balance ....'); </script> ");
                    }
                    else
                    {
                        while (i < countrw)
                        {
                            int    trnscnt = 0;
                            string docount = "";
                            string strqr   = "select max(convert(int,right(Dispatch_id,len(Dispatch_id)-len(Year)-len(Dist_ID)-len(Challan_No)-3))) as rwcount  from dbo.tbl_TruckChalan_FPS where Challan_No='" + Chalan_no + "' and Dist_ID='" + distid + "'";
                            if (con.State == ConnectionState.Closed)
                            {
                                con.Open();
                            }
                            cmd.CommandText = strqr;
                            cmd.Connection  = con;
                            dr = cmd.ExecuteReader();
                            while (dr.Read())
                            {
                                docount = dr["rwcount"].ToString();
                            }
                            dr.Close();
                            if (CheckNullInt(docount) < 0)
                            {
                                docount = "0";
                            }
                            if (docount != "")
                            {
                                trnscnt = CheckNullInt(docount);
                            }
                            trnscnt = trnscnt + 1;
                            transid = year + "-" + distid.ToString() + "-" + Chalan_no.ToString() + "-" + (trnscnt).ToString();

                            string time = (ddlhour.SelectedItem.Text.ToString() + ":" + ddlminute.SelectedItem.Text.ToString() + ":" + ddlampm.SelectedItem.Text.ToString());
                            string qry  = "insert into dbo.tbl_TruckChalan_FPS(Dispatch_id,State_Id,Dist_ID,Depot_Id,Book_No,Saral_NO,Challan_No,Challan_Date,Builty_No,Builty_Date,Dispatch_Godown,Sendto_District,Sendto_Depot,sendto_Block,sendto_FPS,Commodity,Scheme,Bags,Qty_send,Truck_no,Transporter,Driver_Name,Dispatch_Time,Remarks,IsDeposit,Month,Year,Created_date,Updated_Date,IP_Address,Source,OperatorID,NoTransaction) values('" + transid + "','" + state + "','" + distid + "','" + issueid + "','" + Bookno + "','" + saral_no + "','" + Chalan_no + "','" + dispatchdate + "','" + BuiltyNo + "','" + dispatchdate + "','" + Godown_From + "','" + Issued_Dist + "','" + Issued_Depot + "'," + Issued_Block + "," + dt.Rows[i][0] + ",'" + dt.Rows[i][2] + "','" + dt.Rows[i][4] + "','" + dt.Rows[i][6] + "','" + dt.Rows[i][7] + "','" + txttruckno.Text.Trim() + "','" + Transporter + "','" + Drivername + "','" + time + "','" + remark + "','" + mdstatus + "'," + month + "," + year + ",getdate(),'" + mudate + "','" + ip + "','" + Stock_Source + "','" + opid + "','" + notrans + "')";

                            cmd = new SqlCommand(qry, con);
                            int req = cmd.ExecuteNonQuery();
                            //i = i + 1;
                            con.Close();
                            try
                            {
                                if (ddlcomdty.SelectedItem.Text == "--Select--" || ddlscheme.SelectedItem.Text == "--Select--" || ddlgodown.SelectedItem.Text == "--Select--" || ddlsarrival.SelectedItem.Text == "--Select--" || ddltransporter.SelectedItem.Text == "--Select--" || ddldistrict.SelectedItem.Text == "--Select--" || ddlissuecenter.SelectedItem.Text == "--Select--")
                                {
                                    Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Please Select Commodity/Scheme/Dispatch Godown/Source/Transporter/Issue Center....'); </script> ");
                                }
                                else
                                {
                                    if (con.State == ConnectionState.Closed)
                                    {
                                        con.Open();
                                    }
                                    float  buqty     = CheckNull(txtbqty.Text);
                                    string msaletype = "Other Depot";
                                    string mstate    = "23";
                                    string mupdate   = "";
                                    string mddate    = "";
                                    string query     = "Update dbo.issue_opening_balance set Current_Balance=Current_Balance-" + dt.Rows[i][7] + ",Current_Bags=Current_Bags-" + dt.Rows[i][6] + " where District_Id='" + distid + "'and Depotid='" + issueid + "'and Commodity_Id='" + dt.Rows[i][2] + "'and Scheme_Id='" + dt.Rows[i][4] + "' and Godown='" + Godown_From + "'and Source='" + Stock_Source + "'";
                                    cmd.CommandText = query;
                                    cmd.Connection  = con;
                                    string qreySale = "insert into dbo.SCSC_Sale_Details(State_Id,District_Id,Depotid,Commodity_Id,Scheme_Id,Sale_Type,Quantity,Month,Year,CreatedDate,UpdatedDate,DeletedDate) values('" + mstate + "','" + distid + "','" + issueid + "','" + dt.Rows[i][2] + "','" + dt.Rows[i][4] + "','" + msaletype + "'," + dt.Rows[i][7] + "," + month + "," + year + ",getdate(),'" + mupdate + "','" + mddate + "'" + ")";
                                    try
                                    {
                                        cmd.ExecuteNonQuery();
                                        cmd.CommandText = qreySale;
                                        int count = cmd.ExecuteNonQuery();
                                        con.Close();
                                        if (count >= 1)
                                        {
                                            string qrystock = "select Sum(Qty_send) as Qty from dbo.tbl_TruckChalan_FPS where Commodity ='" + dt.Rows[i][2] + "' and Scheme='" + dt.Rows[i][4] + "' and Dist_ID='" + distid + "'and Depot_Id='" + issueid + "'and Month=" + month + "and Year=" + year;
                                            mobj = new MoveChallan(ComObj);
                                            DataSet dsstock = mobj.selectAny(qrystock);

                                            if (dsstock.Tables[0].Rows.Count == 0)
                                            {
                                            }
                                            else
                                            {
                                                DataRow drop       = dsstock.Tables[0].Rows[0];
                                                float   msod       = CheckNull(drop["Qty"].ToString());
                                                string  qryinsopen = "select * from dbo.tbl_Stock_Registor where Commodity_Id ='" + dt.Rows[i][2] + "' and Scheme_Id='" + dt.Rows[i][4] + "' and DistrictId ='" + distid + "'and DepotID='" + issueid + "'and Month=" + month + "and Year=" + year;
                                                mobj = new MoveChallan(ComObj);
                                                DataSet dsopen = mobj.selectAny(qryinsopen);

                                                if (dsopen.Tables[0].Rows.Count == 0)
                                                {
                                                    string qrysr = "select * from dbo.tbl_Stock_Registor where Commodity_Id ='" + dt.Rows[i][2] + "' and Scheme_Id='" + dt.Rows[i][4] + "' and DistrictId ='" + distid + "'and DepotID='" + sid + "'and Month=" + month + "and Year=" + year;
                                                    mobj = new MoveChallan(ComObj);
                                                    DataSet dssr = mobj.selectAny(qrysr);

                                                    if (dssr.Tables[0].Rows.Count == 0)
                                                    {
                                                        string chkopenss = "Select Sum(Current_Balance) as Current_Balance   from dbo.issue_opening_balance where District_Id='" + distid + "'and Depotid='" + sid + "'and Commodity_Id='" + dt.Rows[i][2] + "' and Scheme_Id='" + dt.Rows[i][4] + "'";
                                                        mobj = new MoveChallan(ComObj);
                                                        DataSet dsqry = mobj.selectAny(chkopenss);
                                                        if (dsqry == null)
                                                        {
                                                        }

                                                        else
                                                        {
                                                            DataRow drss    = dsqry.Tables[0].Rows[0];
                                                            float   sropen  = CheckNull(drss["Current_Balance"].ToString());
                                                            string  qryinsr = "insert into dbo.tbl_Stock_Registor(DistrictId,DepotID,Commodity_ID,Scheme_ID,Opening_Balance,Recieved_Procure,Recieved_Otherg,Recieved_FCI,Received_OtherSch,Recieved_Other_Src,Received_RailHead,Received_CMR,Received_Levy,Sale_Do,Sale_otherg,Transfer_OtherSch,Month,Year,Remarks) Values('" + distid + "','" + sid + "','" + dt.Rows[i][2] + "','" + dt.Rows[i][4] + "'," + sropen + "," + 0 + "," + 0 + "," + 0 + "," + 0 + "," + 0 + "," + 0 + "," + 0 + "," + 0 + "," + CheckNull(txtbqty.Text) + "," + 0 + "," + 0 + "," + month + "," + year + ",'')";
                                                            cmd.CommandText = qryinsr;
                                                            if (con.State == ConnectionState.Closed)
                                                            {
                                                                con.Open();
                                                            }
                                                            cmd.ExecuteNonQuery();
                                                            con.Close();
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    string qryinsU = "update dbo.tbl_Stock_Registor set Sale_otherg=" + msod + " where Commodity_Id ='" + dt.Rows[i][2] + "'and Scheme_Id='" + dt.Rows[i][4] + "' and DistrictId='" + distid + "'and DepotID='" + issueid + "'and Month=" + month + "and Year=" + year;
                                                    cmd.CommandText = qryinsU;
                                                    if (con.State == ConnectionState.Closed)
                                                    {
                                                        con.Open();
                                                    }
                                                    cmd.ExecuteNonQuery();
                                                    con.Close();
                                                }
                                            }
                                        }
                                        try
                                        {
                                            //string ip = Request.ServerVariables["REMOTE_ADDR"].ToString();
                                            //string state = Session["State_Id"].ToString();
                                            DateTime datetime = Convert.ToDateTime(getDate_MDY(DaintyDate1.Text));
                                            //string time = (ddlhour.SelectedItem.Text.ToString() + ":" + ddlminute.SelectedItem.Text.ToString() + ":" + ddlampm.SelectedItem.Text.ToString());
                                            string qryupdate = "insert into dbo.SCSC_Truck_challan_Trans_Log(State_Id,Dist_ID,Depot_Id,TO_Number,Challan_Date,Dispatch_Godown,Sendto_District,Sendto_IC,Commodity,Scheme,Bags,Qty_send,Challan_No,Truck_no,Transporter,Dispatch_Time,Remarks,Dispatch_id,Month,Year,Updated_Date,IP_Address,Source,Operation) values('" + state + "','" + distid + "','" + issueid + "','" + txt_Saral.Text.Trim() + "','" + getDate_MDY(DaintyDate1.Text) + "','" + ddlgodown.SelectedValue + "','" + ddldistrict.SelectedValue + "','" + ddlissuecenter.SelectedValue + "','" + dt.Rows[i][2] + "','" + dt.Rows[i][4] + "'," + dt.Rows[i][6] + "," + dt.Rows[i][7] + ",'" + txttrukcno.Text.Trim() + "','" + txttruckno.Text + "','" + ddltransporter.SelectedValue + "','" + time + "','" + txtremark.Text + "','" + Issued_Godown + "'," + datetime.Month.ToString() + "," + datetime.Year.ToString() + ",getdate(),'" + ip + "','" + Stock_Source + "','I')";
                                            if (con.State == ConnectionState.Closed)
                                            {
                                                con.Open();
                                            }
                                            cmd.CommandText = qryupdate;
                                            cmd.Connection  = con;
                                            cmd.ExecuteNonQuery();
                                        }
                                        catch (Exception)
                                        {
                                        }

                                        UpdateReceipt();
                                    }
                                    catch (Exception ex)
                                    {
                                        Label1.Text = ex.Message;
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                            }
                            i = i + 1;
                        }

                        Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Data Inserted Successfully....'); </script> ");
                        btnsave.Enabled      = false;
                        lnkPrintPage.Visible = true;

                        txt_Driver.Text           = "";
                        txt_Saral.Text            = "";
                        txtBuiltyno.Text          = "";
                        Gv_FPS_Details.DataSource = null;
                        Gv_FPS_Details.DataBind();
                        tr1.Visible                  = false;
                        pnl_Grid.Visible             = false;
                        txttrukcno.Text              = "";
                        txtremark.Text               = "";
                        txttruckno.Text              = "";
                        txtbookno.Text               = "";
                        txtbqty.Text                 = "";
                        txtcurbags.Text              = "";
                        ddlcomdty.SelectedIndex      = -1;
                        ddlscheme.SelectedIndex      = -1;
                        ddlissuecenter.SelectedIndex = -1;
                        ddlgodown.SelectedIndex      = -1;
                    }
                }
                else
                {
                    Page.RegisterClientScriptBlock("asdsad", "<script language=javascript > alert('Please enter FPS details');</script>");
                }
            }
            else
            {
                Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Challan Number Exist....'); </script> ");
            }
        }
        catch (Exception ex)
        {
            Page.RegisterClientScriptBlock("myscript", "<script language=javascript > alert('Please Try Again...');</script>");
        }
        finally
        {
            con.Close();
            ComObj.CloseConnection();
        }
    }