private void SaveMachine3Data() { obj = new TblMachineReading(); obj.MachineID = 3; obj.PreviousReading = Convert.ToDecimal(txtPreviousM3N1.Text); obj.CurrentReading = Convert.ToDecimal(txtCurrentM3N1.Text); if (txtPetrolDate.Enabled) { obj.DateX = Convert.ToDateTime(txtPetrolDate.SelectedDate).ToShortDateString(); } else { obj.DateX = Convert.ToDateTime(txtPetrolDate.SelectedDate).AddDays(1).ToShortDateString(); } obj.IsActive = true; obj.CategoryID = 2; obj.TestLiter = Convert.ToDecimal(txtTestM3N1.Text); obj.NozleID = 5; obj.Rate = Convert.ToDecimal(txtDesialRate.Text); obj.Save(); obj = new TblMachineReading(); obj.MachineID = 3; obj.PreviousReading = Convert.ToDecimal(txtPreviousM3N2.Text); obj.CurrentReading = Convert.ToDecimal(txtCurrentM3N2.Text); if (txtPetrolDate.Enabled) { obj.DateX = Convert.ToDateTime(txtPetrolDate.SelectedDate).ToShortDateString(); } else { obj.DateX = Convert.ToDateTime(txtPetrolDate.SelectedDate).AddDays(1).ToShortDateString(); } obj.IsActive = true; obj.CategoryID = 2; obj.TestLiter = Convert.ToDecimal(txtTestM3N2.Text); obj.NozleID = 6; obj.Rate = Convert.ToDecimal(txtDesialRate.Text); obj.Save(); }
protected void btnSaveReading_Click(object sender, EventArgs e) { HiddenField hfMachineID = null, hfNozleNo = null, hfCategoryID = null; double PMGQuantity = 0, HSDQuantity = 0, N1, N2; TextBox txtPreviousReadingN1 = null, txtCurrentReadingN1 = null, txtTestUnitsN1 = null, txtPreviousReadingN2 = null, txtCurrentReadingN2 = null, txtTestUnitsN2 = null; for (int i = 0; i < rptMachines.Items.Count; i++) { hfNozleNo = (HiddenField)rptMachines.Items[i].FindControl("hfNozleNo"); hfMachineID = (HiddenField)rptMachines.Items[i].FindControl("hfMachineID"); hfCategoryID = (HiddenField)rptMachines.Items[i].FindControl("hfCategoryID"); //First Nozle txtPreviousReadingN1 = (TextBox)rptMachines.Items[i].FindControl("txtPreviousReadingN1"); txtCurrentReadingN1 = (TextBox)rptMachines.Items[i].FindControl("txtCurrentReadingN1"); txtTestUnitsN1 = (TextBox)rptMachines.Items[i].FindControl("txtTestUnitsN1"); //Second Nozle txtPreviousReadingN2 = (TextBox)rptMachines.Items[i].FindControl("txtPreviousReadingN2"); txtCurrentReadingN2 = (TextBox)rptMachines.Items[i].FindControl("txtCurrentReadingN2"); txtTestUnitsN2 = (TextBox)rptMachines.Items[i].FindControl("txtTestUnitsN2"); //First Nozle obj = new TblMachineReading(); obj.MachineID = Convert.ToInt32(hfMachineID.Value); obj.PreviousReading = Convert.ToDecimal(txtPreviousReadingN1.Text); obj.CurrentReading = Convert.ToDecimal(txtCurrentReadingN1.Text); if (txtPetrolDate.Enabled) { obj.DateX = Convert.ToDateTime(txtPetrolDate.SelectedDate).ToShortDateString(); } else { obj.DateX = Convert.ToDateTime(txtPetrolDate.SelectedDate).AddDays(1).ToShortDateString(); } obj.TestLiter = Convert.ToDecimal(txtTestUnitsN1.Text); obj.IsActive = true; obj.CategoryID = Convert.ToInt32(hfCategoryID.Value); obj.NozleID = Convert.ToInt32(hfNozleNo.Value.Split(',')[0]); obj.Rate = obj.CategoryID == 1 ? Convert.ToDecimal(txtPetrolRate.Text) : Convert.ToDecimal(txtDesialRate.Text); obj.Save(); //Second Nozle obj = new TblMachineReading(); obj.MachineID = Convert.ToInt32(hfMachineID.Value); obj.PreviousReading = Convert.ToDecimal(txtPreviousReadingN2.Text); obj.CurrentReading = Convert.ToDecimal(txtCurrentReadingN2.Text); if (txtPetrolDate.Enabled) { obj.DateX = Convert.ToDateTime(txtPetrolDate.SelectedDate).ToShortDateString(); } else { obj.DateX = Convert.ToDateTime(txtPetrolDate.SelectedDate).AddDays(1).ToShortDateString(); } obj.TestLiter = Convert.ToDecimal(txtTestUnitsN2.Text); obj.IsActive = true; obj.CategoryID = Convert.ToInt32(hfCategoryID.Value); obj.NozleID = Convert.ToInt32(hfNozleNo.Value.Split(',')[1]); obj.Rate = obj.CategoryID == 1 ? Convert.ToDecimal(txtPetrolRate.Text) : Convert.ToDecimal(txtDesialRate.Text); obj.Save(); if (obj.CategoryID == 1) { N1 = Convert.ToDouble(Convert.ToDecimal(txtCurrentReadingN1.Text) - Convert.ToDecimal(txtPreviousReadingN1.Text)); N2 = Convert.ToDouble(Convert.ToDecimal(txtCurrentReadingN2.Text) - Convert.ToDecimal(txtPreviousReadingN2.Text)); PMGQuantity += N1 + N2; } else { N1 = Convert.ToDouble(Convert.ToDecimal(txtCurrentReadingN1.Text) - Convert.ToDecimal(txtPreviousReadingN1.Text)); N2 = Convert.ToDouble(Convert.ToDecimal(txtCurrentReadingN2.Text) - Convert.ToDecimal(txtPreviousReadingN2.Text)); HSDQuantity += N1 + N2; } } TblSale objPMGSale = new TblSale(); objPMGSale.IsNew = true; objPMGSale.Qty = PMGQuantity; objPMGSale.Rate = Convert.ToDecimal(txtPetrolRate.Text); objPMGSale.Price = Convert.ToDecimal(objPMGSale.Qty * Convert.ToDouble(objPMGSale.Rate)); objPMGSale.CategoryID = 1; objPMGSale.DateX = Convert.ToDateTime(txtPetrolDate.SelectedDate); objPMGSale.Save(); TblSale objHSDSale = new TblSale(); objHSDSale.IsNew = true; objHSDSale.Qty = HSDQuantity; objHSDSale.Rate = Convert.ToDecimal(txtDesialRate.Text); objHSDSale.Price = Convert.ToDecimal(objHSDSale.Qty * Convert.ToDouble(objHSDSale.Rate)); objHSDSale.CategoryID = 2; objHSDSale.DateX = Convert.ToDateTime(txtPetrolDate.SelectedDate); objHSDSale.Save(); Response.Redirect("MachineReading.aspx"); }