private void UpdateRecord(int formState, int financialExportFormId) { HiddenField currentCountry = null; Label currentAmount = null; FinancialExportFormCountry countryExport = null; if (FormGridView.Rows.Count == 0) { throw new Exception(Resources.Resource.mFinancialExportMandatory); } // remove all country export records associated to the current formId CxFinancialExportFormCountry.Delete(financialExportFormId); // Query the database for the row to be updated. using (var db = new Models.SmizeeContext()) { var entity = (from c in db.FinancialExportForms where c.FinancialExportFormID == financialExportFormId select c).First(); if (entity != null) { if (formState <= 3) { entity.SubmitDate = DateTime.Now; entity.SubmitUserName = User.Identity.Name; } else { entity.ApprovalUserName = User.Identity.Name; entity.ApprovalDate = DateTime.Now; } entity.StateID = formState; db.SaveChanges(); foreach (GridViewRow currentExport in FormGridView.Rows) { currentCountry = currentExport.FindControl("CountryIdHidden") as HiddenField; currentAmount = currentExport.FindControl("ExportAmountLabel") as Label; countryExport = new FinancialExportFormCountry(); countryExport.CountryID = int.Parse(currentCountry.Value); countryExport.ExportAmount = GetDecimalValue(currentAmount.Text); countryExport.FinancialExportFormID = entity.FinancialExportFormID; db.FinancialExportFormCountries.Add(countryExport); } db.SaveChanges(); } } }
private void CreateRecord(int formId, int productionUnitId) { HiddenField currentCountry = null; Label currentAmount = null; FinancialExportFormCountry countryExport = null; if (FormGridView.Rows.Count == 0) { throw new Exception(Resources.Resource.mFinancialExportMandatory); } using (var db = new Models.SmizeeContext()) { FinancialExportForm entity = new FinancialExportForm(); entity.FormID = formId; entity.StateID = 1; entity.SubmitDate = DateTime.Now; //entity.ApprovalDate = DateTime.Parse("01/01/2000 00:00:00"); entity.SubmitUserName = User.Identity.Name; db.FinancialExportForms.Add(entity); db.SaveChanges(); foreach (GridViewRow currentExport in FormGridView.Rows) { currentCountry = currentExport.FindControl("CountryIdHidden") as HiddenField; currentAmount = currentExport.FindControl("ExportAmount") as Label; countryExport = new FinancialExportFormCountry(); countryExport.CountryID = int.Parse(currentCountry.Value); countryExport.ExportAmount = GetDecimalValue(currentAmount.Text); countryExport.FinancialExportFormID = entity.FinancialExportFormID; db.FinancialExportFormCountries.Add(countryExport); } db.SaveChanges(); } BackPanel.Visible = true; ConfirmButtonPanel.Visible = false; DetailPanel.Visible = false; FormPanel.Visible = false; ShowInfo(MessagePanel, Resources.Resource.mCreateOK); }