protected void btnSaveReading_Click(object sender, EventArgs e) { decimal m2n1 = Convert.ToDecimal(txtCurrentM2N1.Text) - Convert.ToDecimal(txtPreviousM2N1.Text) - Convert.ToDecimal(txtTestM2N1.Text), m2n2 = Convert.ToDecimal(txtCurrentM2N2.Text) - Convert.ToDecimal(txtPreviousM2N2.Text) - Convert.ToDecimal(txtTestM2N2.Text), m3n1 = Convert.ToDecimal(txtCurrentM3N1.Text) - Convert.ToDecimal(txtPreviousM3N1.Text) - Convert.ToDecimal(txtTestM3N1.Text), m3n2 = Convert.ToDecimal(txtCurrentM3N2.Text) - Convert.ToDecimal(txtPreviousM3N2.Text) - Convert.ToDecimal(txtTestM3N2.Text); SaveMachine1Data();//Save Machine no.1 Data TblSale objPMGSale = new TblSale(); objPMGSale.IsNew = true; objPMGSale.Qty = Convert.ToDouble((Convert.ToDecimal(txtCurrentM1N1.Text) - Convert.ToDecimal(txtPreviousM1N1.Text) - Convert.ToDecimal(txtTestM1N1.Text)) + (Convert.ToDecimal(txtCurrentM1N2.Text) - Convert.ToDecimal(txtPreviousM1N2.Text) - Convert.ToDecimal(txtTestM1N2.Text))); 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(); SaveMachine2Data(); //Save Machine no.2 Data SaveMachine3Data(); //Save Machine no.3 Data TblSale objHSDSale = new TblSale(); objHSDSale.IsNew = true; objHSDSale.Qty = Convert.ToDouble(m2n1 + m2n2 + m3n1 + m3n2); 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"); }
private void SaveTempData(DataTable dt) { TblSale objPMGSale = new TblSale(); objPMGSale.IsNew = true; objPMGSale.Qty = Convert.ToDouble(lblPMGUnits.Text); objPMGSale.Rate = Convert.ToDecimal(dt.Rows[0]["Rate"]); objPMGSale.Price = Convert.ToDecimal(objPMGSale.Qty * Convert.ToDouble(objPMGSale.Rate)); objPMGSale.CategoryID = 1; objPMGSale.DateX = Convert.ToDateTime(dt.Rows[0]["Date"]); objPMGSale.Save(); TblSale objHSDSale = new TblSale(); objHSDSale.IsNew = true; objHSDSale.Qty = Convert.ToDouble(lblHSDUnits.Text); objHSDSale.Rate = Convert.ToDecimal(dt.Rows[2]["Rate"]); objHSDSale.Price = Convert.ToDecimal(objHSDSale.Qty * Convert.ToDouble(objHSDSale.Rate)); objHSDSale.CategoryID = 2; objHSDSale.DateX = Convert.ToDateTime(dt.Rows[2]["Date"]); objHSDSale.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"); }