protected void frmvwAddUpdateLipidProfile_ItemCommand(object sender, FormViewCommandEventArgs e) { #region Controls TextBox txtTestDate = (TextBox)frmvwAddUpdateLipidProfile.FindControl("txtTestDate"); TextBox txtTChol = (TextBox)frmvwAddUpdateLipidProfile.FindControl("txtTChol"); TextBox txtTriglycerides = (TextBox)frmvwAddUpdateLipidProfile.FindControl("txtTriglycerides"); TextBox txtHDLChol = (TextBox)frmvwAddUpdateLipidProfile.FindControl("txtHDLChol"); TextBox txtLDLChol = (TextBox)frmvwAddUpdateLipidProfile.FindControl("txtLDLChol"); TextBox txtTCholHDL = (TextBox)frmvwAddUpdateLipidProfile.FindControl("txtTCholHDL"); TextBox txtLDLHDLRatio = (TextBox)frmvwAddUpdateLipidProfile.FindControl("txtLDLHDLRatio"); #endregion if (e.CommandName == "AddLipidProfile") { DC_Message _msg = new DC_Message(); DC_LipidProfileReports _objAdd = new DC_LipidProfileReports(); _objAdd.TestDate = Convert.ToDateTime(txtTestDate.Text); _objAdd.PatientID = GetPatientID(); _objAdd.TChol = txtTChol.Text; _objAdd.Triglycerides = txtTriglycerides.Text; _objAdd.HDLChol = txtHDLChol.Text; _objAdd.LDLChol = txtLDLChol.Text; _objAdd.TCholHDL = txtTCholHDL.Text; _objAdd.LDLHDLRatio = txtLDLHDLRatio.Text; _objAdd.CreatedBy = "Ajay"; _objAdd.CreatedDate = DateTime.Today; _msg = _objDL.AddUpdateLipidProfileReports(_objAdd); if (_msg.StatusCode == ReadOnlyMessage.StatusCode.Success) { BootstrapAlert.BootstrapAlertMessage(divmsg, _msg.StatusMessage, BootstrapAlertType.Success); frmvwAddUpdateLipidProfile.ChangeMode(FormViewMode.Insert); BindGridDetails(); } } if (e.CommandName == "UpdateLipidProfile") { DC_Message _msg = new DC_Message(); DC_LipidProfileReports _objAdd = new DC_LipidProfileReports(); _objAdd.LPR_TestReportID = Guid.Parse(Convert.ToString(frmvwAddUpdateLipidProfile.DataKey.Value)); _objAdd.TestDate = Convert.ToDateTime(txtTestDate.Text); _objAdd.PatientID = GetPatientID(); _objAdd.TChol = txtTChol.Text; _objAdd.Triglycerides = txtTriglycerides.Text; _objAdd.HDLChol = txtHDLChol.Text; _objAdd.LDLChol = txtLDLChol.Text; _objAdd.TCholHDL = txtTCholHDL.Text; _objAdd.LDLHDLRatio = txtLDLHDLRatio.Text; _objAdd.EditedBy = "Ajay"; _objAdd.EditedDate = DateTime.Today; _msg = _objDL.AddUpdateLipidProfileReports(_objAdd); if (_msg.StatusCode == ReadOnlyMessage.StatusCode.Success) { BootstrapAlert.BootstrapAlertMessage(divmsg, _msg.StatusMessage, BootstrapAlertType.Success); frmvwAddUpdateLipidProfile.ChangeMode(FormViewMode.Insert); BindGridDetails(); } } }
public DC_Message AddUpdateLipidProfileReports(DC_LipidProfileReports _objSave) { DC_Message _msg = new DC_Message(); try { using (CLMS_DBEntities context = new CLMS_DBEntities()) { if (_objSave.LPR_TestReportID != null && _objSave.LPR_TestReportID != Guid.Empty) { var isDuplicate = (from x in context.tbl_LipidProfileReports where x.LPR_TestReportID != _objSave.LPR_TestReportID && x.PatientID == x.PatientID && x.TestDate == _objSave.TestDate select x).Count() == 0 ? false : true; if (isDuplicate) { _msg.StatusMessage = "Report " + ReadOnlyMessage.strAlreadyExist; _msg.StatusCode = ReadOnlyMessage.StatusCode.Duplicate; return(_msg); } var report = context.tbl_LipidProfileReports.Find(_objSave.LPR_TestReportID); if (report != null) { report.TestDate = _objSave.TestDate; report.IsActive = _objSave.IsActive; report.EditedBy = _objSave.EditedBy; report.EditedDate = _objSave.EditedDate; report.TChol = _objSave.TChol; report.Triglycerides = _objSave.Triglycerides; report.HDLChol = _objSave.HDLChol; report.LDLChol = _objSave.LDLChol; report.TCholHDL = _objSave.TCholHDL; report.LDLHDLRatio = _objSave.LDLHDLRatio; if (context.SaveChanges() == 1) { _msg.StatusMessage = "Lipid Profile has been" + ReadOnlyMessage.strUpdatedSuccessfully; _msg.StatusCode = ReadOnlyMessage.StatusCode.Success; } else { _msg.StatusMessage = "Lipid Profile has been" + ReadOnlyMessage.strFailed; _msg.StatusCode = ReadOnlyMessage.StatusCode.Failed; } } else { tbl_LipidProfileReports _objnew = new tbl_LipidProfileReports(); _objnew.LPR_TestReportID = Guid.NewGuid(); _objnew.PatientID = _objSave.PatientID; _objnew.CreatedBy = _objSave.CreatedBy; _objnew.CreatedDate = _objSave.CreatedDate; _objnew.TChol = _objSave.TChol; _objnew.Triglycerides = _objSave.Triglycerides; _objnew.HDLChol = _objSave.HDLChol; _objnew.LDLChol = _objSave.LDLChol; _objnew.TCholHDL = _objSave.TCholHDL; _objnew.LDLHDLRatio = _objSave.LDLHDLRatio; _objnew.IsActive = _objSave.IsActive; _objnew.TestDate = _objSave.TestDate; context.tbl_LipidProfileReports.Add(_objnew); if (context.SaveChanges() == 1) { _msg.StatusMessage = "Lipid Profile has been" + ReadOnlyMessage.strAddedSuccessfully; _msg.StatusCode = ReadOnlyMessage.StatusCode.Success; } else { _msg.StatusMessage = "Lipid Profile has been" + ReadOnlyMessage.strFailed; _msg.StatusCode = ReadOnlyMessage.StatusCode.Failed; } } } else { tbl_LipidProfileReports _objnew = new tbl_LipidProfileReports(); _objnew.LPR_TestReportID = Guid.NewGuid(); _objnew.PatientID = _objSave.PatientID; _objnew.CreatedBy = _objSave.CreatedBy; _objnew.CreatedDate = _objSave.CreatedDate; _objnew.TChol = _objSave.TChol; _objnew.Triglycerides = _objSave.Triglycerides; _objnew.HDLChol = _objSave.HDLChol; _objnew.LDLChol = _objSave.LDLChol; _objnew.TCholHDL = _objSave.TCholHDL; _objnew.LDLHDLRatio = _objSave.LDLHDLRatio; _objnew.IsActive = _objSave.IsActive; _objnew.TestDate = _objSave.TestDate; context.tbl_LipidProfileReports.Add(_objnew); if (context.SaveChanges() == 1) { _msg.StatusMessage = "Lipid Profile has been" + ReadOnlyMessage.strAddedSuccessfully; _msg.StatusCode = ReadOnlyMessage.StatusCode.Success; } else { _msg.StatusMessage = "Lipid Profile has been" + ReadOnlyMessage.strFailed; _msg.StatusCode = ReadOnlyMessage.StatusCode.Failed; } } } } catch (Exception ex) { } return(_msg); }