protected void btnSave_Click(object sender, EventArgs e)
    {
        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }

        if (ddlracknumber.SelectedValue == "0" || ddlracknumber.SelectedItem.Text == "--Select--")
        {
            Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Please Select Rack Number ....'); </script> ");
            return;
        }

        if (ddlIssuecenter.SelectedValue == "0" || ddlIssuecenter.SelectedItem.Text == "--Select--")
        {
            Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Please Select Issue Center ....'); </script> ");
            return;
        }



        if (txtRecdQty.Text == "")
        {
            Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Please Enter Receiving Quantity ....'); </script> ");
            return;
        }

        if (txtRecdBags.Text == "")
        {
            Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Please Enter Receiving Bags ....'); </script> ");
            return;
        }

        if (DaintyDate1.Text == "")
        {
            Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Please Enter Receiving Date ....'); </script> ");
            return;
        }

        if (ddlchallan.SelectedValue == "0" || ddlchallan.SelectedItem.Text == "--Select--")
        {
            Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Please Select Challan Number ....'); </script> ");
            return;
        }

        double sendqty  = Convert.ToDouble(txtsendQty.Text);
        Int32  sendbags = Convert.ToInt32(txtsendbags.Text);

        Int32  recdbags = Convert.ToInt32(txtRecdBags.Text);
        double recdQty  = Convert.ToDouble(txtRecdQty.Text);


        if (recdQty > sendqty || recdbags > sendbags)
        {
            Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Received Bags or Quantity will not more than Sending Bags or Quantity ....'); </script> ");
            return;
        }

        string racknum = ddlracknumber.SelectedItem.Text;
        string sendIC  = ddlIssuecenter.SelectedValue;
        string challan = ddlchallan.SelectedItem.Text;

        string std = getDate_MDY(DaintyDate1.Text);

        //DateTime std = DateTime.Parse(getDate_MDY(DaintyDate1.Text));

        string ip   = Request.ServerVariables["REMOTE_ADDR"].ToString();
        string opid = Session["OperatorIDDM"].ToString();

        GetFirstfour = result = "";
        length       = 0;

        GetFirstfour = ddlchallan.SelectedItem.ToString();
        length       = GetFirstfour.Length;
        if (length > 4)
        {
            result = GetFirstfour.Substring(0, 4);
        }

        if (result == "MORK")
        {
            string Update = "";
            distid = Session["dist_id"].ToString();
            try
            {
                Update = "BEGIN TRY; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED BEGIN TRANSACTION " +
                         "Update DeliveryChallan_MO Set IsReceived='Y',RSDRecd_Qty='" + txtRecdQty.Text + "',RSDRecd_Bags='" + txtRecdBags.Text + "',RSDRecd_Date='" + std + "',RSDCreatedDate=GETDATE() where FrmDist='" + distid + "' and DC_MO='" + ddlchallan.SelectedItem.ToString() + "' and Rack_No='" + ddlracknumber.SelectedItem.ToString() + "' and CropYear='" + lblcropyear.Text + "' and Issued_Date='" + hdfChallanDate.Value + "';";

                Update += "Insert into QtyReceived_RackDispatchPoint (Racknumber ,sendingDist ,sendingIssueCenter ,TruckChallan ,CropYear ,sendBags ,SendQty ,RecdBags ,RecdQty ,RecdDate ,IP_Address ,Created_date ,OperatorID,Commodity,RecDist,IsReceived) values('" + racknum + "','" + distid + "','" + sendIC + "','" + challan + "','" + lblcropyear.Text + "','" + txtsendbags.Text + "','" + txtsendQty.Text + "','" + txtRecdBags.Text + "','" + txtRecdQty.Text + "','" + std + "','" + ip + "',getdate(),'" + opid + "','" + hdfComdty.Value + "','" + hdfRecDist.Value + "','N');";

                Update += "COMMIT end TRY BEGIN CATCH IF @@TRANCOUNT > 0 ROLLBACK;DECLARE @ErrorMessage NVARCHAR(4000);DECLARE @ErrorSeverity INT;DECLARE @ErrorState INT;SELECT @ErrorMessage = ERROR_MESSAGE(),  @ErrorSeverity = ERROR_SEVERITY(),   @ErrorState = ERROR_STATE();  RAISERROR (@ErrorMessage,  @ErrorSeverity,@ErrorState ); END CATCH;";

                cmd = new SqlCommand(Update, con);
                int count = cmd.ExecuteNonQuery();

                if (count > 0)
                {
                    Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Data Saved Sucessfully ....'); </script> ");
                    DaintyDate1.Text = "";
                    txtRecdQty.Text  = "";
                    txtRecdBags.Text = "";
                    btnSave.Enabled  = false;
                }
                else
                {
                    Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Data Not Save For Movement Order'); </script> ");
                }
            }
            catch
            {
                Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Data Not Save For Movement Order'); </script> ");
            }

            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
        }
        else
        {
            string insquy = "Insert into QtyReceived_RackDispatchPoint (Racknumber ,sendingDist ,sendingIssueCenter ,TruckChallan ,CropYear ,sendBags ,SendQty ,RecdBags ,RecdQty ,RecdDate ,IP_Address ,Created_date ,OperatorID) values('" + racknum + "','" + distid + "','" + sendIC + "','" + challan + "','" + lblcropyear.Text + "','" + txtsendbags.Text + "','" + txtsendQty.Text + "','" + txtRecdBags.Text + "','" + txtRecdQty.Text + "','" + std + "','" + ip + "',getdate(),'" + opid + "')";

            SqlCommand cmdins = new SqlCommand(insquy, con);

            try
            {
                int x = cmdins.ExecuteNonQuery();

                if (x == 0)
                {
                    Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Not Saved, Might be Some Error ....'); </script> ");
                }
                else
                {
                    Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Data Saved Sucessfully ....'); </script> ");

                    DaintyDate1.Text = "";
                    txtRecdQty.Text  = "";
                    txtRecdBags.Text = "";
                    btnSave.Enabled  = false;
                }
            }

            catch
            {
                Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Not Saved, Might be Some Error ....'); </script> ");
            }

            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
        }
    }
Beispiel #2
0
    protected void btnsubmit_Click(object sender, EventArgs e)
    {
        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }

        if (ddlrackno.SelectedValue == "0" || ddlrackno.SelectedItem.Text == "--Select--")
        {
            Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Select Rack Number....'); </script> ");
            return;
        }


        if (ddlcommodity.SelectedValue == "0" || ddlcommodity.SelectedItem.Text == "--Select--")
        {
            Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Select Commodity Type....'); </script> ");
            return;
        }

        if (ddlgodown.SelectedValue == "0" || ddlgodown.SelectedItem.Text == "--Select--")
        {
            Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Select Godown Name....'); </script> ");
            return;
        }

        if (ddlcropyear.SelectedItem.Text == "--Select--")
        {
            Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Select Crop Year..'); </script> ");
            return;
        }

        if (txtbagno.Text == "0" || txtbagno.Text == "")
        {
            Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Bags Should not be 0 or Blank..'); </script> ");
            return;
        }

        if (txtquant.Text == "0" || txtquant.Text == "")
        {
            Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Quantity Should not be 0 or Blank..'); </script> ");
            return;
        }

        if (txttruckno.Text == "")
        {
            Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Please Enter Truck Number..'); </script> ");
            return;
        }

        //if (txttrukchlnno.Text == "")
        //{
        //    Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Please Enter Challan Number.'); </script> ");
        //    return;
        //}

        if (DaintyDate1.Text == "")
        {
            Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Please Select Receiving Date.'); </script> ");
            return;
        }

        if (ddlChallanNo.Visible == true)
        {
            if (ddlChallanNo.SelectedValue == "0" || ddlChallanNo.SelectedItem.Text == "--Select--")
            {
                Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Please Select Challan Number'); </script> ");
                return;
            }
            else
            {
                txttrukchlnno.Text = ddlChallanNo.SelectedItem.ToString();
            }
        }
        else
        {
            if (txttrukchlnno.Text == "")
            {
                Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Please Enter Challan Number.'); </script> ");
                return;
            }
        }

        string        duplichallan = "Select DC_MO from Return_from_Rack where DC_MO = '" + txttrukchlnno.Text.Trim() + "' and Issue_Center = '" + issueid + "' and FrmDist = '" + distid + "' ";
        SqlCommand    cmdchallan   = new SqlCommand(duplichallan, con);
        SqlDataReader drchallan;

        drchallan = cmdchallan.ExecuteReader();

        if (drchallan.Read())
        {
            Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Duplicate Challan Number Not Accepted..'); </script> ");
            drchallan.Close();
            return;
        }

        drchallan.Close();

        string challannum = txttrukchlnno.Text.Trim();

        string Racknum      = ddlrackno.SelectedItem.Text;
        string commodity    = ddlcommodity.SelectedValue;
        string scheme       = ddlscheme.SelectedValue;
        string GodownName   = ddlgodown.SelectedValue;
        string cropyear     = ddlcropyear.SelectedItem.Text;
        string Quantity     = txtquant.Text.Trim();
        string Bags         = txtbagno.Text.Trim();
        string TruckNumber  = txttruckno.Text.Trim();
        string Recevingdate = getDate_MDY(DaintyDate1.Text);
        string IPadd        = Request.ServerVariables["REMOTE_ADDR"].ToString();
        string opid         = Session["OperatorId"].ToString();

        string InseQry = "";

        if (ddlChallanNo.Visible == true)
        {
            GetFirstfour = result = "";
            length       = 0;

            GetFirstfour = ddlChallanNo.SelectedItem.ToString();
            length       = GetFirstfour.Length;
            if (length > 4)
            {
                result = GetFirstfour.Substring(0, 4);
            }

            if (result == "MORK")
            {
                InseQry = "BEGIN TRY; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED BEGIN TRANSACTION " +
                          "Update DeliveryChallan_MO Set RRDRecd_Qty='" + Quantity + "',RRDRecd_Bags='" + Bags + "',RRDRecd_Date='" + Recevingdate + "',RRDCreated=GETDATE() where Rack_No='" + ddlrackno.SelectedItem.ToString() + "' and DC_MO='" + ddlChallanNo.SelectedItem.ToString() + "' and FrmDist='" + distid + "' and STO_No='" + hdfSTO_No.Value + "';";

                InseQry += "Insert into Return_From_Rack (DC_MO,Rack_No,STO_No,FrmDist,Commodity,CropYear,Scheme,Issue_Center,Godown,Quantity,Bags,Truck_No,Recd_Date,CreatedDate,IP,OperatorID,Remark) Values ('" + challannum + "','" + Racknum + "','" + hdfSTO_No.Value + "','" + distid + "','" + commodity + "','" + cropyear + "','" + scheme + "','" + issueid + "','" + GodownName + "','" + Quantity + "','" + Bags + "','" + TruckNumber + "','" + Recevingdate + "',GETDATE(),'" + IPadd + "','" + opid + "','" + txtremark.Text + "');";

                InseQry += "COMMIT end TRY BEGIN CATCH IF @@TRANCOUNT > 0 ROLLBACK;DECLARE @ErrorMessage NVARCHAR(4000);DECLARE @ErrorSeverity INT;DECLARE @ErrorState INT;SELECT @ErrorMessage = ERROR_MESSAGE(),  @ErrorSeverity = ERROR_SEVERITY(),   @ErrorState = ERROR_STATE();  RAISERROR (@ErrorMessage,  @ErrorSeverity,@ErrorState ); END CATCH;";
            }
        }
        else
        {
            InseQry += "Insert into Return_From_Rack (DC_MO,Rack_No,STO_No,FrmDist,Commodity,CropYear,Scheme,Issue_Center,Godown,Quantity,Bags,Truck_No,Recd_Date,CreatedDate,IP,OperatorID,Remark) Values ('" + challannum + "','" + Racknum + "','" + hdfSTO_No.Value + "','" + distid + "','" + commodity + "','" + cropyear + "','" + scheme + "','" + issueid + "','" + GodownName + "','" + Quantity + "','" + Bags + "','" + TruckNumber + "','" + Recevingdate + "',GETDATE(),'" + IPadd + "','" + opid + "','" + txtremark.Text + "');";

            //InseQry = "Insert into Return_From_Rack (DistrictId,IssueCenter ,Challan_No,RackNumber ,Commodity ,Scheme ,GodownName ,CropYear ,Quantity,Bags ,TruckNumber  ,ReceivingDate ,IPaddress ,UserId  ,CreatedDate) Values ('" + distid + "','" + issueid + "','" + challannum + "','" + Racknum + "','" + commodity + "','" + scheme + "','" + GodownName + "','" + cropyear + "','" + Quantity + "','" + Bags + "','" + TruckNumber + "','" + Recevingdate + "','" + IPadd + "','" + opid + "',getdate())";
        }

        SqlCommand cmdins = new SqlCommand(InseQry, con);

        try
        {
            int x = cmdins.ExecuteNonQuery();

            if (x > 0)
            {
                Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Data Saved.'); </script> ");
                btnsubmit.Enabled = false;
            }

            else
            {
                Page.RegisterClientScriptBlock("mymsg2", "<script language=javascript> alert('Problem Occured.'); </script> ");
                return;
            }
        }

        catch (Exception ex)
        {
            Label11.Text = ex.ToString();
        }
    }