protected void btAddFuelFutureUpdate_Click(object sender, EventArgs e) { ReportModels rp = new ReportModels(); var listFuelDetail = rp.DE_ReportFuelDetail.Where(x => x.ReportId == ReportId && x.IsNextYear == true).ToList(); foreach (RepeaterItem ri in rptFuelFuture.Items) { TextBox txtNoFuel = ri.FindControl("txtNoFuel") as TextBox; TextBox txtReason = ri.FindControl("txtReason") as TextBox; HiddenField hdFuelId = ri.FindControl("hdFuelId") as HiddenField; int _FuelId = Convert.ToInt32(hdFuelId.Value); decimal tmpDecimal = 0; if (txtNoFuel.Text != "") { decimal.TryParse(txtNoFuel.Text, style, culture, out tmpDecimal); } var _existedFuel = listFuelDetail.FirstOrDefault(o => o.FuelId == _FuelId); if (_existedFuel != null) { _existedFuel.NoFuel = tmpDecimal; _existedFuel.Reason = txtReason.Text.Trim(); } else { HiddenField hdGroupFuelId = ri.FindControl("hdGroupFuelId") as HiddenField; HiddenField hdMeasurementId = ri.FindControl("hdMeasurementId") as HiddenField; var _insertd = new DE_ReportFuelDetail { FuelId = _FuelId, NoFuel = tmpDecimal, ReportId = ReportId, EnterpriseId = memVal.OrgId, Year = ReportYear, IsNextYear = true, Reason = txtReason.Text.Trim(), GroupFuelId = Convert.ToInt32(hdMeasurementId.Value), MeasurementId = Convert.ToInt32(hdMeasurementId.Value), }; rp.DE_ReportFuelDetail.Add(_insertd); } } //SaveChanges rp.SaveChanges(); btAddFuelFuture.Visible = true; btAddFuelFutureUpdate.Visible = false; btAddFuelFutureCancel.Visible = false; foreach (RepeaterItem ri in rptFuelFuture.Items) { TextBox txtNoFuel = ri.FindControl("txtNoFuel") as TextBox; txtNoFuel.ReadOnly = true; TextBox txtReason = ri.FindControl("txtReason") as TextBox; txtReason.ReadOnly = true; } }
protected void btAddElectrictFutureUpdate_Click(object sender, EventArgs e) { ReportModels rp = new ReportModels(); //DE_UsingElectrict var checkUsingElectrict = rp.DE_UsingElectrict.Any(x => x.ReportId == ReportId && x.IsPlan == true); var _usingElectrict = new DE_UsingElectrict(); if (checkUsingElectrict == true) { _usingElectrict = rp.DE_UsingElectrict.FirstOrDefault(x => x.ReportId == ReportId && x.IsPlan == true); } else { _usingElectrict.ReportId = ReportId; _usingElectrict.IsPlan = true; _usingElectrict.ReportYear = ReportYear; _usingElectrict.FuelId = 0; } if (txtUsingElectrictFuture_InstalledCapacity.Text.Trim() != "") { _usingElectrict.InstalledCapacity = Convert.ToDecimal(txtUsingElectrictFuture_InstalledCapacity.Text.Trim(), culture); } if (txtUsingElectrictFuture_Quantity.Text.Trim() != "") { _usingElectrict.Quantity = Convert.ToDecimal(txtUsingElectrictFuture_Quantity.Text.Trim(), culture); } if (txtUsingElectrictFuture_CongSuatBanRa.Text.Trim() != "") { _usingElectrict.CongSuatBan = Convert.ToDecimal(txtUsingElectrictFuture_CongSuatBanRa.Text.Trim(), culture); } if (txtUsingElectrictFuture_SanLuongBanRa.Text.Trim() != "") { _usingElectrict.SanLuongBan = Convert.ToDecimal(txtUsingElectrictFuture_SanLuongBanRa.Text.Trim(), culture); } if (checkUsingElectrict == false) { rp.DE_UsingElectrict.Add(_usingElectrict); } //DE_ElectrictProduce var checkElectrictSelfProduce = rp.DE_ElectrictProduce.Any(x => x.ReportId == ReportId); if (checkElectrictSelfProduce == true) //Update DE_ElectrictProduce { var tempData = rp.DE_ElectrictProduce.Where(x => x.ReportId == ReportId).ToList(); foreach (RepeaterItem ri in rptUsingElectrictFuture.Items) { TextBox txtInstalledCapacity = ri.FindControl("txtInstalledCapacity") as TextBox; TextBox txtProduceQty = ri.FindControl("txtProduceQty") as TextBox; HiddenField hdTechKey = ri.FindControl("hdTechKey") as HiddenField; var tmp = tempData.FirstOrDefault(x => x.TechKey == hdTechKey.Value); if (tmp != null) { if (txtInstalledCapacity.Text.Trim() != "") { tmp.InstalledCapacity = Convert.ToDecimal(txtInstalledCapacity.Text.Trim(), culture); } if (txtProduceQty.Text.Trim() != "") { tmp.ProduceQty = Convert.ToDecimal(txtProduceQty.Text.Trim(), culture); } } } } else //Insert DE_ElectrictProduce { foreach (RepeaterItem ri in rptUsingElectrictFuture.Items) { TextBox txtInstalledCapacity = ri.FindControl("txtInstalledCapacity") as TextBox; TextBox txtProduceQty = ri.FindControl("txtProduceQty") as TextBox; HiddenField hdTechKey = ri.FindControl("hdTechKey") as HiddenField; DE_ElectrictProduce _usingElectrictInserted = new DE_ElectrictProduce(); _usingElectrictInserted.ReportId = ReportId; _usingElectrictInserted.ReportYear = ReportYear; _usingElectrictInserted.TechKey = hdTechKey.Value; _usingElectrictInserted.IsPlan = true; if (txtInstalledCapacity.Text.Trim() != "") { _usingElectrictInserted.InstalledCapacity = Convert.ToDecimal(txtInstalledCapacity.Text.Trim(), culture); } if (txtProduceQty.Text.Trim() != "") { _usingElectrictInserted.ProduceQty = Convert.ToDecimal(txtProduceQty.Text.Trim(), culture); } rp.DE_ElectrictProduce.Add(_usingElectrictInserted); } } rp.SaveChanges(); btAddElectrictFutureCancel_Click(sender, e); }
protected void btnUpdateProductResult_Click(object sender, EventArgs e) { ReportModels rp = new ReportModels(); if (rp.DE_ProductCapacity.Any(x => x.ReportId == ReportId && x.IsPlan == false)) //Update { var tempData = rp.DE_ProductCapacity.Where(x => x.ReportId == ReportId && x.IsPlan == false).ToList(); foreach (RepeaterItem ri in rptProductResult.Items) { HiddenField hdProductId = ri.FindControl("hdProductId") as HiddenField; int ProductId = Convert.ToInt32(hdProductId.Value); var pcInfo = tempData.FirstOrDefault(x => x.ProductId == ProductId); if (pcInfo == null) { //Khởi tạo pcInfo pcInfo = new DE_ProductCapacity(); pcInfo.ProductId = ProductId; pcInfo.ReportId = ReportId; pcInfo.IsPlan = false; pcInfo.ReportYear = ReportYear; rp.DE_ProductCapacity.Add(pcInfo); TextBox txtDataReport1415 = ri.FindControl("txtDataReport1415") as TextBox; pcInfo.DataReport1415 = txtDataReport1415.Text.Trim(); } else { TextBox txtDataReport1415 = ri.FindControl("txtDataReport1415") as TextBox; pcInfo.DataReport1415 = txtDataReport1415.Text.Trim(); } } rp.SaveChanges(); } else //Insert { foreach (RepeaterItem ri in rptProductResult.Items) { DE_ProductCapacity pcInfo = new DE_ProductCapacity(); TextBox txtDataReport1415 = ri.FindControl("txtDataReport1415") as TextBox; HiddenField hdProductId = ri.FindControl("hdProductId") as HiddenField; int ProductId = Convert.ToInt32(hdProductId.Value); pcInfo.ProductId = ProductId; pcInfo.ReportId = ReportId; pcInfo.IsPlan = false; pcInfo.ReportYear = ReportYear; pcInfo.DataReport1415 = txtDataReport1415.Text.Trim(); rp.DE_ProductCapacity.Add(pcInfo); } rp.SaveChanges(); } btnAddProductResult.Visible = true; btnUpdateProductResult.Visible = false; btnCancelProductResult.Visible = false; foreach (RepeaterItem ri in rptProductResult.Items) { TextBox txtDataReport1415 = ri.FindControl("txtDataReport1415") as TextBox; txtDataReport1415.ReadOnly = true; } }
protected void btnAddProductNextResultUpdate_Click(object sender, EventArgs e) { ReportModels rp = new ReportModels(); if (rp.DE_ProductCapacity.Any(x => x.ReportId == ReportId && x.IsPlan == true)) //Update { var tempData = rp.DE_ProductCapacity.Where(x => x.ReportId == ReportId && x.IsPlan == true).ToList(); foreach (RepeaterItem ri in rptProductPlan.Items) { TextBox txtMaxQuantity = ri.FindControl("txtMaxQuantity") as TextBox; TextBox txtDesignQuantity = ri.FindControl("txtDesignQuantity") as TextBox; HiddenField hdProductId = ri.FindControl("hdProductId") as HiddenField; int ProductId = Convert.ToInt32(hdProductId.Value); var pcInfo = tempData.FirstOrDefault(x => x.ProductId == ProductId); decimal tmpDecimal = 0; if (decimal.TryParse(txtMaxQuantity.Text, style, culture, out tmpDecimal)) { pcInfo.MaxQuantity = tmpDecimal; } else { pcInfo.MaxQuantity = 0; } if (decimal.TryParse(txtDesignQuantity.Text, style, culture, out tmpDecimal)) { pcInfo.DesignQuantity = tmpDecimal; } else { pcInfo.DesignQuantity = 0; } } rp.SaveChanges(); } else //Insert { foreach (RepeaterItem ri in rptProductPlan.Items) { DE_ProductCapacity pcInfo = new DE_ProductCapacity(); TextBox txtMaxQuantity = ri.FindControl("txtMaxQuantity") as TextBox; TextBox txtDesignQuantity = ri.FindControl("txtDesignQuantity") as TextBox; HiddenField hdProductId = ri.FindControl("hdProductId") as HiddenField; int ProductId = Convert.ToInt32(hdProductId.Value); pcInfo.ProductId = ProductId; pcInfo.ReportId = ReportId; pcInfo.IsPlan = true; pcInfo.ReportYear = ReportYear; decimal tmpDecimal = 0; if (decimal.TryParse(txtMaxQuantity.Text, style, culture, out tmpDecimal)) { pcInfo.MaxQuantity = tmpDecimal; } else { pcInfo.MaxQuantity = 0; } if (decimal.TryParse(txtDesignQuantity.Text, style, culture, out tmpDecimal)) { pcInfo.DesignQuantity = tmpDecimal; } else { pcInfo.DesignQuantity = 0; } rp.DE_ProductCapacity.Add(pcInfo); } rp.SaveChanges(); } btnAddProductNextResultCancel_Click(sender, e); }