none
Validation - Should not accept Multiple Records for Same Movement Order Id

    Question


  •  #region sumbit details
            protected void btnSubmit_Click(object sender, EventArgs e)
            {
               
                if (ddlmovnum.SelectedIndex == 0)
                {
                    return;
                }
           
    
                #region insert Final Claim Header
                objBOFinalClaim = new BOFinalClaim();
                objBLFinalClaim = new BLFinalClaim();
                objBOFinalClaim.OperationId = 1;
                //objBOFinalClaim.billno = Convert.ToInt16(Hdn_BillNo.Value);
                objBOFinalClaim.req_ID = Convert.ToInt16(Hdn_reqID.Value);
                objBOFinalClaim.MO_ID = Convert.ToInt16(HdnMoID.Value);
                objBOFinalClaim.timestart = ddlhrs.SelectedValue + ":" + ddlmin.SelectedValue;
                objBOFinalClaim.foodbill = Convert.ToDecimal(txtfoodbill.Text);
                objBOFinalClaim.roomrent = Convert.ToDecimal(txtroomrent.Text);
                objBOFinalClaim.advance = Convert.ToDecimal(lbladvance.Text);
                lblResult.Text = objBLFinalClaim.BL_InsertClaim(objBOFinalClaim);
                if (lblResult.Text == "You have Already Requested for a Final Claim on this movement order number!")
                {
                    btnSubmit.Enabled = false;
                    Gridview1.Enabled = false;
                    Gridview2.Enabled = false;
                    ddlmovnum.Enabled = false;
                }
                #endregion
                else
                    GetBillno();
                #region insert into finalclaimdetails
                foreach (GridViewRow gvr1 in Gridview1.Rows)
                {
                    objBOFinalClaim = new BOFinalClaim();
                    objBLFinalClaim = new BLFinalClaim();
                    DateTime? arrivaldate = null;
                    DateTime? departuredate = null;
                    objBOFinalClaim.OperationId = 4;
                    string arrivalcity = (gvr1.FindControl("Arrival_city") as TextBox).Text;
                    string arrivalhours = (gvr1.FindControl("ddlahrs") as DropDownList).SelectedValue;
                    string arrivalmins = (gvr1.FindControl("ddlamin") as DropDownList).SelectedValue;
                    System.Globalization.CultureInfo provider = new System.Globalization.CultureInfo("fr-FR");
                    arrivaldate = Convert.ToDateTime((gvr1.FindControl("arrival_Date") as TextBox).Text);
                    //arrivaldate = DateTime.ParseExact((gvr1.FindControl("Arrival_date") as TextBox).Text, ("dd/MM/yyyy"), provider);
                    string depthours = (gvr1.FindControl("ddldhrs") as DropDownList).SelectedValue;
                    string deptmins = (gvr1.FindControl("ddldmin") as DropDownList).SelectedValue;
                    //departuredate = Convert.ToDateTime((gvr1.FindControl("departure_Date") as TextBox).Text);
                    //departuredate = DateTime.ParseExact((gvr1.FindControl("departure_Date") as TextBox).Text, ("dd/MM/yyyy"), provider);
                    //departuredate = DateTime.ParseExact((gvr1.FindControl("departure_Date") as TextBox).Text, ("dd/MM/yyyy"), null);
                    //if (DateTime.ParseExact((gvr1.FindControl("departure_Date") as TextBox).Text, ("dd/MM/yyyy"), provider) == null)
                    //{
    
                    //}
                    //else
                    //{
                    //    departuredate = DateTime.ParseExact((gvr1.FindControl("departure_Date") as TextBox).Text, ("dd/MM/yyyy"), provider);
                    //}
                    departuredate = DateTime.ParseExact((gvr1.FindControl("Arrival_date") as TextBox).Text, ("dd/MM/yyyy"), provider);
                    string conveyance = (gvr1.FindControl("Conveyance") as TextBox).Text;
                    string ticketno = (gvr1.FindControl("Ticket_number") as TextBox).Text;
                    int distance = Convert.ToInt32((gvr1.FindControl("Distance") as TextBox).Text);
                    decimal amount = Convert.ToDecimal((gvr1.FindControl("txtAmount") as TextBox).Text);
                    objBOFinalClaim.billno = Convert.ToInt16(Hdn_BillNo.Value);
                    objBOFinalClaim.arrivalcity = arrivalcity;
                    objBOFinalClaim.ArrivalDate = Convert.ToDateTime(arrivaldate);
                    objBOFinalClaim.ArrivalTime = arrivalhours + ":" + arrivalmins;
                    objBOFinalClaim.DepartureTime = depthours + ":" + deptmins;
                    objBOFinalClaim.DepartureDate = Convert.ToDateTime(departuredate);
                    objBOFinalClaim.Conveyance = conveyance;
                    objBOFinalClaim.Ticketnumber = Convert.ToString(ticketno);
                    objBOFinalClaim.Distance = Convert.ToInt16(distance);
                    objBOFinalClaim.Amount = Convert.ToDecimal(amount);
                    lblResult.Text = objBLFinalClaim.BL_InsertClaimdetails(objBOFinalClaim);
                }
                #endregion
               
               
            public void GetBillno()
            {
                objBOFinalClaim = new BOFinalClaim();
                objBLFinalClaim = new BLFinalClaim();
                int reqid = Int16.Parse(Hdn_reqID.Value);
                objBOFinalClaim.OperationId = 2;
                DataTable dt = objBLFinalClaim.BL_getbillno(reqid);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        Hdn_BillNo.Value = dt.Rows[i]["BillNo"].ToString();
                    }
                }
            }
            #endregion
            
           


    IF(@intOperationID= 1)	--Inserting the values into T_TADA_FinalClaimheader
    BEGIN
    	IF NOT EXISTS( SELECT 1 FROM T_TADA_FinalClaimHeader WHERE IsActive=1 AND reqID=@reqID AND MoID=@MoID)
    		BEGIN
    			INSERT INTO	T_TADA_FinalClaimHeader
    		   (reqID,
    			MoID,
    			time_Start,
    			foodbill_paid,
    			roomrent_paid,
    			Advance, 
    			created_Date,
    			created_By,
    			IsActive)
    			VALUES
    		    (@reqID,
    			@MoID,
    			@timestart,
    			@foodbill_paid,
    			@roomrent_paid,
    			@Advance,
    			GETDATE(),
    			'tsoft1', 
    			1)							
    	SELECT 'Details Inserted Successfully'	
    		END		
    			ELSE
    			BEGIN
    					SELECT 'You have Already Requested for a Final Claim on this movement order number!'
    				END
    END


    IF(@intOperationID= 4)	--Inserting the values into T_TADA_FinalClaimdetails
    BEGIN	
    IF NOT EXISTS(SELECT 1 FROM T_TADA_FinalClaimDetails WHERE IsActive =1 AND(BillNo=@BillNo))
    --IF NOT EXISTS (SELECT 1 FROM T_TADA_FinalClaimHeader WHERE IsActive =1 AND (BillNo=@BillNo))
    		BEGIN
    			INSERT INTO	T_TADA_FinalClaimDetails
    			(BillNo,
    			City_arrived,
    			arrival_Date,
    			arrival_time,
    			departure_Date,
    			departure_Time, 
    			distance,
    		    conveyance,
    		    Amount,
    		    ticket_No, 
    		    created_Date,
    		    created_By,
    		    IsActive)
    			VALUES(@BillNo,
    			@City_arrived,
    			@arrival_Date,
    			@arrival_time,
    			@departure_Date,
    			@departure_Time, 
    			@distance, 
    			@conveyance,
    			@Amount,
    			@ticket_No,
    			GETDATE(),
    			'tsoft1',
    			 1)	
    			SELECT 'Details Inserted Successfully'	
    		END			
    	ELSE
    			BEGIN
    				SELECT 'You have Already Requested for a Final Claim on this movement order number!'
    			END
    END

    These are the codes and query that i am using for inserting values into gridview. ,and also one gridview contain  2 tables.The tables called finalclaimheader and finalclaimdetails.In this FinalclaimHeader table billno is primary key ,reqid & MoId are unique key and in FinalClaimDetails table only one unique column BillNo.In both table BillNo are same.Based upon that  FinalClaimHeader BillNo only it inserting value values into the FinalClaimDetails table.In front end FinalclaimDetails storing BillNo by HiddenField.In design view one dropdownlist is there it contain MoNum.For each MoNum one MoID will be there. it contain in two different tables.My requirement is I need to validate that if i raise multiple FinalClaim for same movement order then it should show the else part message

    SELECT 'You have Already Requested for a Final Claim on this movement order number!'

    .In FinalClaimHeader  if I mention reqID and MoID then the message returns  correctly.

    IF NOT EXISTS( SELECT 1 FROM T_TADA_FinalClaimHeader WHERE IsActive=1 AND reqID=@reqID AND MoID=@MoID)

    but in FinalClaimDetails part

    objBOFinalClaim.billno = Convert.ToInt16(Hdn_BillNo.Value);

    here shows error "input string was not in correct format".and shows the billno value 0

    because i didn't mention any BillNo in Header part.Based upon Header part BillNo only Details part inserting details. IF i use

    IF NOT EXISTS( SELECT 1 FROM T_TADA_FinalClaimHeader WHERE IsActive=1 AND reqID=@reqID AND MoID=@MoID AND BillNo)

    BillNo shows correctly in both tables,but it inserting values if the same movement order details present also.Thats not allowed.

    And there is no column called MoNum in FinalClaimHeader and FinalClaimDetails table.But in Front End i am using MoNum.For that MoNum one MoID will be generated.I need to validate with that MoID.

    Wednesday, February 15, 2017 6:38 AM

All replies

  • Hi Litty Alex,

    According to your description, I think you need to debug your project to find the reason.

    And your issue are more related to ASP.Net. I suggest you had better re-post this issue to the following forum for a professional answer:

    https://forums.asp.net/18.aspx/1?Web+Forms  

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 16, 2017 6:52 AM
    Moderator