public static Staff LoadAll(DataRow row) { Staff staff = Load(row, "staff_"); staff.Person = PersonDB.Load(row, "person_"); staff.Person.Title = IDandDescrDB.Load(row, "title_title_id", "title_descr"); staff.Field = IDandDescrDB.Load(row, "field_field_id", "field_descr"); staff.StaffPosition = StaffPositionDB.Load(row, "staff_position_"); staff.CostCentre = CostCentreDB.Load(row, "cost_centre_"); return(staff); }
public static System.Collections.Hashtable GetAllInHashtable(bool incSupportStaff = false, bool showIsFired = false, bool showIsExternal = false, bool showOnlyExternal = false) { System.Collections.Hashtable hash = new System.Collections.Hashtable(); DataTable tbl = StaffDB.GetDataTable_StaffInfo(incSupportStaff, showIsFired, showIsExternal, showOnlyExternal); for (int i = 0; i < tbl.Rows.Count; i++) { Staff staff = Load(tbl.Rows[i]); staff.Person = PersonDB.Load(tbl.Rows[i]); staff.Person.Title = IDandDescrDB.Load(tbl.Rows[i], "title_id", "descr"); staff.Field = IDandDescrDB.Load(tbl.Rows[i], "field_field_id", "field_descr"); staff.StaffPosition = StaffPositionDB.Load(tbl.Rows[i], "staff_position_"); staff.CostCentre = CostCentreDB.Load(tbl.Rows[i], "cost_centre_"); hash[staff.StaffID] = staff; } return(hash); }
public static StaffOfferings LoadAll(DataRow row) { StaffOfferings so = Load(row, "so_"); so.Offering = OfferingDB.Load(row, "o_"); so.Offering.OfferingType = IDandDescrDB.Load(row, "type_offering_type_id", "type_descr"); so.Offering.Field = IDandDescrDB.Load(row, "fld_field_id", "fld_descr"); so.Offering.AgedCarePatientType = IDandDescrDB.Load(row, "acpatientcat_aged_care_patient_type_id", "acpatientcat_descr"); so.Offering.OfferingInvoiceType = IDandDescrDB.Load(row, "invtype_offering_invoice_type_id", "invtype_descr"); so.Staff = StaffDB.Load(row, "staff_"); so.Staff.Person = PersonDB.Load(row, "person_"); so.Staff.Person.Title = IDandDescrDB.Load(row, "title_title_id", "title_descr"); so.Staff.Field = IDandDescrDB.Load(row, "field_field_id", "field_descr"); so.Staff.StaffPosition = StaffPositionDB.Load(row, "staff_position_"); so.Staff.CostCentre = CostCentreDB.Load(row, "cost_centre_"); return(so); }
protected void btnSubmit_Click(object sender, EventArgs e) { if (!ddlEndDateValidateAllOrNoneSet.IsValid || !ddlStartDateValidateAllOrNoneSet.IsValid) { return; } txtPwd.Attributes["value"] = txtPwd.Text; // pwd fields is unset on send back to server, so re-set it if (GetUrlParamType() == UrlParamType.View) { Response.Redirect(UrlParamModifier.AddEdit(Request.RawUrl, "type", "edit")); } else if (GetUrlParamType() == UrlParamType.Edit) { Staff staff = StaffDB.GetByID(Convert.ToInt32(this.lblId.Text)); if (!Convert.ToBoolean(ConfigurationManager.AppSettings["UseConfigDB"]) && staff.Login != txtLogin.Text && UserDatabaseMapperDB.UsernameExists(txtLogin.Text)) { SetErrorMessage("Login name already in use by another user"); return; } if (StaffDB.LoginExists(txtLogin.Text, staff.StaffID)) { SetErrorMessage("Login name already in use by another user"); return; } if (staff.Pwd != txtPwd.Text && txtPwd.Text.Length < 6) { SetErrorMessage(staff.Pwd.Length >= 6 ? "Password must be at least 6 characters" : "New passwords must be at least 6 characters"); return; } bool loggedInUserIsStakeholder = Session["IsStakeholder"] != null && Convert.ToBoolean(Session["IsStakeholder"]); bool loggedInUserIsMasterAdmin = Session["IsMasterAdmin"] != null && Convert.ToBoolean(Session["IsMasterAdmin"]); PersonDB.Update(staff.Person.PersonID, Convert.ToInt32(ddlTitle.SelectedValue), Utilities.FormatName(txtFirstname.Text), Utilities.FormatName(txtMiddlename.Text), Utilities.FormatName(txtSurname.Text), staff.Person.Nickname, ddlGender.SelectedValue, staff.Person.Dob, DateTime.Now); StaffDB.Update(staff.StaffID, staff.Person.PersonID, txtLogin.Text, txtPwd.Text, staff.StaffPosition.StaffPositionID, staff.Field.ID, staff.CostCentre.CostCentreID, staff.IsContractor, staff.Tfn, staff.ProviderNumber, ddlStatus.SelectedValue == "Inactive", staff.IsCommission, staff.CommissionPercent, staff.IsStakeholder, staff.IsMasterAdmin, staff.IsAdmin, staff.IsPrincipal, staff.IsProvider, staff.IsExternal, GetStartDateFromForm(), GetEndDateFromForm(), txtComments.Text, staff.EnableDailyReminderSMS, staff.EnableDailyReminderEmail, staff.HideBookingNotes); if (!Convert.ToBoolean(ConfigurationManager.AppSettings["UseConfigDB"]) && staff.Login != txtLogin.Text) { UserDatabaseMapper curDBMapper = UserDatabaseMapperDB.GetByLogin(staff.Login, Session["DB"].ToString()); UserDatabaseMapperDB.Update(curDBMapper.ID, txtLogin.Text, Session["DB"].ToString()); } Response.Redirect(UrlParamModifier.AddEdit(Request.RawUrl, "type", "view")); } else if (GetUrlParamType() == UrlParamType.Add) { if (!Convert.ToBoolean(ConfigurationManager.AppSettings["UseConfigDB"]) && UserDatabaseMapperDB.UsernameExists(txtLogin.Text)) { SetErrorMessage("Login name already in use by another user"); return; } if (StaffDB.LoginExists(txtLogin.Text)) { SetErrorMessage("Login name already in use by another user"); return; } if (txtPwd.Text.Length < 6) { SetErrorMessage("Password must be at least 6 characters"); return; } int person_id = -1; int staff_id = -1; bool staff_added = false; int mainDbUserID = -1; try { if (!Convert.ToBoolean(ConfigurationManager.AppSettings["UseConfigDB"])) { mainDbUserID = UserDatabaseMapperDB.Insert(txtLogin.Text, Session["DB"].ToString()); } Staff loggedInStaff = StaffDB.GetByID(Convert.ToInt32(Session["StaffID"])); person_id = PersonDB.Insert(loggedInStaff.Person.PersonID, Convert.ToInt32(ddlTitle.SelectedValue), Utilities.FormatName(txtFirstname.Text), Utilities.FormatName(txtMiddlename.Text), Utilities.FormatName(txtSurname.Text), "", ddlGender.SelectedValue, DateTime.MinValue); staff_id = StaffDB.Insert(person_id, txtLogin.Text, txtPwd.Text, StaffPositionDB.GetByDescr("Unknown").StaffPositionID, 0, 59, false, "", "", ddlStatus.SelectedValue == "Inactive", false, 0, false, false, false, false, false, true, GetStartDateFromForm(), GetEndDateFromForm(), txtComments.Text, false, false, false); staff_added = true; string url = Request.RawUrl; url = UrlParamModifier.AddEdit(url, "type", "view"); url = UrlParamModifier.AddEdit(url, "id", staff_id.ToString()); Response.Redirect(url); } catch (Exception) { if (staff_added) { string url = Request.RawUrl; url = UrlParamModifier.AddEdit(url, "type", "view"); url = UrlParamModifier.AddEdit(url, "id", staff_id.ToString()); Response.Redirect(url); return; } // roll back - backwards of creation order PersonDB.Delete(person_id); if (!Convert.ToBoolean(ConfigurationManager.AppSettings["UseConfigDB"])) { UserDatabaseMapperDB.Delete(mainDbUserID); } throw; } } else { HideTableAndSetErrorMessage(); } }
protected void GrdStaff_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("Insert")) { CustomValidator txtValidateDOB = (CustomValidator)GrdStaff.FooterRow.FindControl("txtValidateNewDOB"); if (!txtValidateDOB.IsValid) { return; } DropDownList ddlTitle = (DropDownList)GrdStaff.FooterRow.FindControl("ddlNewTitle"); TextBox txtFirstname = (TextBox)GrdStaff.FooterRow.FindControl("txtNewFirstname"); TextBox txtMiddlename = (TextBox)GrdStaff.FooterRow.FindControl("txtNewMiddlename"); TextBox txtSurname = (TextBox)GrdStaff.FooterRow.FindControl("txtNewSurname"); DropDownList ddlGender = (DropDownList)GrdStaff.FooterRow.FindControl("ddlNewGender"); TextBox txtLogin = (TextBox)GrdStaff.FooterRow.FindControl("txtNewLogin"); TextBox txtPwd = (TextBox)GrdStaff.FooterRow.FindControl("txtNewPwd"); DropDownList ddlStatus = (DropDownList)GrdStaff.FooterRow.FindControl("ddlStatus"); if (!Convert.ToBoolean(ConfigurationManager.AppSettings["UseConfigDB"]) && UserDatabaseMapperDB.UsernameExists(txtLogin.Text)) { SetErrorMessage("Login name already in use by another user"); return; } if (StaffDB.LoginExists(txtLogin.Text)) { SetErrorMessage("Login name already in use by another user"); return; } if (txtPwd.Text.Length < 6) { SetErrorMessage("Password must be at least 6 characters"); return; } DateTime dob = DateTime.MinValue; int person_id = -1; int mainDbUserID = -1; try { if (!!Convert.ToBoolean(ConfigurationManager.AppSettings["UseConfigDB"])) { mainDbUserID = UserDatabaseMapperDB.Insert(txtLogin.Text, Session["DB"].ToString()); } Staff loggedInStaff = StaffDB.GetByID(Convert.ToInt32(Session["StaffID"])); person_id = PersonDB.Insert(loggedInStaff.Person.PersonID, Convert.ToInt32(ddlTitle.SelectedValue), Utilities.FormatName(txtFirstname.Text), Utilities.FormatName(txtMiddlename.Text), Utilities.FormatName(txtSurname.Text), "", ddlGender.SelectedValue, dob); StaffDB.Insert(person_id, txtLogin.Text, txtPwd.Text, StaffPositionDB.GetByDescr("Unknown").StaffPositionID, 0, 59, false, "", "", ddlStatus.SelectedValue == "Inactive", false, 0, false, false, false, false, false, true, DateTime.Today, DateTime.MinValue, "", false, false); FillGrid(); } catch (Exception) { // roll back - backwards of creation order PersonDB.Delete(person_id); if (!!Convert.ToBoolean(ConfigurationManager.AppSettings["UseConfigDB"])) { UserDatabaseMapperDB.Delete(mainDbUserID); } } } }
protected void GrdStaff_RowDataBound(object sender, GridViewRowEventArgs e) { DataTable fields = DBBase.GetGenericDataTable(null, "Field", "field_id", "descr"); DataTable costcentres = CostCentreDB.GetDataTable(); DataTable positions = StaffPositionDB.GetDataTable(); DataTable dt = Session["externalstaffinfo_data"] as DataTable; bool tblEmpty = (dt.Rows.Count == 1 && dt.Rows[0][0] == DBNull.Value); if (!tblEmpty && e.Row.RowType == DataControlRowType.DataRow) { Label lblId = (Label)e.Row.FindControl("lblId"); DataRow[] foundRows = dt.Select("staff_id=" + lblId.Text); DataRow thisRow = foundRows[0]; DropDownList ddlTitle = (DropDownList)e.Row.FindControl("ddlTitle"); if (ddlTitle != null) { DataTable titles = DBBase.GetGenericDataTable_WithWhereOrderClause(null, "Title", Convert.ToInt32(thisRow["title_id"]) == 0 ? "" : " title_id <> 0 ", " descr ", "title_id", "descr"); ddlTitle.DataSource = titles; ddlTitle.DataTextField = "descr"; ddlTitle.DataValueField = "title_id"; ddlTitle.DataBind(); ddlTitle.SelectedValue = thisRow["title_id"].ToString(); } DropDownList ddlGender = (DropDownList)e.Row.FindControl("ddlGender"); if (ddlGender != null) { if (thisRow["gender"].ToString() != "") { for (int i = ddlGender.Items.Count - 1; i >= 0; i--) { if (ddlGender.Items[i].Value == "") { ddlGender.Items.RemoveAt(i); } } } } if (ddlTitle != null && ddlGender != null) { ddlTitle.Attributes["onchange"] = "title_changed_reset_gender('" + ddlTitle.ClientID + "','" + ddlGender.ClientID + "');"; } DropDownList ddlDOB_Day = (DropDownList)e.Row.FindControl("ddlDOB_Day"); DropDownList ddlDOB_Month = (DropDownList)e.Row.FindControl("ddlDOB_Month"); DropDownList ddlDOB_Year = (DropDownList)e.Row.FindControl("ddlDOB_Year"); if (ddlDOB_Day != null && ddlDOB_Month != null && ddlDOB_Year != null) { ddlDOB_Day.Items.Add(new ListItem("--", "-1")); ddlDOB_Month.Items.Add(new ListItem("--", "-1")); ddlDOB_Year.Items.Add(new ListItem("----", "-1")); for (int i = 1; i <= 31; i++) { ddlDOB_Day.Items.Add(new ListItem(i.ToString(), i.ToString())); } for (int i = 1; i <= 12; i++) { ddlDOB_Month.Items.Add(new ListItem(i.ToString(), i.ToString())); } for (int i = 1915; i <= DateTime.Today.Year; i++) { ddlDOB_Year.Items.Add(new ListItem(i.ToString(), i.ToString())); } if (thisRow["dob"] != DBNull.Value) { DateTime dob = Convert.ToDateTime(thisRow["dob"]); ddlDOB_Day.SelectedValue = dob.Day.ToString(); ddlDOB_Month.SelectedValue = dob.Month.ToString(); int firstYearSelectable = Convert.ToInt32(ddlDOB_Year.Items[1].Value); int lastYearSelectable = Convert.ToInt32(ddlDOB_Year.Items[ddlDOB_Year.Items.Count - 1].Value); if (dob.Year < firstYearSelectable) { ddlDOB_Year.Items.Insert(1, new ListItem(dob.Year.ToString(), dob.Year.ToString())); } if (dob.Year > lastYearSelectable) { ddlDOB_Year.Items.Add(new ListItem(dob.Year.ToString(), dob.Year.ToString())); } ddlDOB_Year.SelectedValue = dob.Year.ToString(); } } TextBox txtPwd = (TextBox)e.Row.FindControl("txtPwd"); if (txtPwd != null) { txtPwd.Attributes["value"] = thisRow["pwd"].ToString(); } DropDownList ddlPosition = (DropDownList)e.Row.FindControl("ddlStaffPosition"); if (ddlPosition != null) { ddlPosition.DataSource = positions; ddlPosition.DataTextField = "descr"; ddlPosition.DataValueField = "staff_position_id"; ddlPosition.DataBind(); ddlPosition.SelectedValue = thisRow["staff_position_id"].ToString(); } DropDownList ddlField = (DropDownList)e.Row.FindControl("ddlField"); if (ddlField != null) { ddlField.DataSource = fields; ddlField.DataTextField = "descr"; ddlField.DataValueField = "field_id"; ddlField.DataBind(); ddlField.SelectedValue = thisRow["field_id"].ToString(); } DropDownList ddlCostCentre = (DropDownList)e.Row.FindControl("ddlCostCentre"); if (ddlCostCentre != null) { ddlCostCentre.DataSource = costcentres; ddlCostCentre.DataTextField = "descr"; ddlCostCentre.DataValueField = "costcentre_id"; ddlCostCentre.DataBind(); ddlCostCentre.SelectedValue = thisRow["costcentre_id"].ToString(); } bool is_fired = Convert.ToBoolean(thisRow["is_fired"]); DropDownList ddlStatus = (DropDownList)e.Row.FindControl("ddlStatus"); if (ddlStatus != null) { if (is_fired) { ddlStatus.SelectedValue = "Inactive"; } else { ddlStatus.SelectedValue = "Active"; } } Label lblIsFired = (Label)e.Row.FindControl("lblIsFired"); if (is_fired) { e.Row.ForeColor = System.Drawing.Color.Gray; if (lblIsFired != null) { lblIsFired.ForeColor = System.Drawing.Color.Red; } } Utilities.AddConfirmationBox(e); if ((e.Row.RowState & DataControlRowState.Edit) > 0) { Utilities.SetEditRowBackColour(e, System.Drawing.Color.LightGoldenrodYellow); } } if (e.Row.RowType == DataControlRowType.Footer) { DataTable titles = DBBase.GetGenericDataTable_WithWhereOrderClause(null, "Title", " title_id <> 0 ", " descr ", "title_id", "descr"); DropDownList ddlTitle = (DropDownList)e.Row.FindControl("ddlNewTitle"); ddlTitle.DataSource = titles; ddlTitle.DataBind(); ddlTitle.SelectedIndex = Utilities.IndexOf(ddlTitle, "mr", "mr."); } }
protected void GrdStaff_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("Insert")) { CustomValidator txtValidateDOB = (CustomValidator)GrdStaff.FooterRow.FindControl("txtValidateNewDOB"); if (!txtValidateDOB.IsValid) { return; } DropDownList ddlTitle = (DropDownList)GrdStaff.FooterRow.FindControl("ddlNewTitle"); TextBox txtFirstname = (TextBox)GrdStaff.FooterRow.FindControl("txtNewFirstname"); TextBox txtMiddlename = (TextBox)GrdStaff.FooterRow.FindControl("txtNewMiddlename"); TextBox txtSurname = (TextBox)GrdStaff.FooterRow.FindControl("txtNewSurname"); DropDownList ddlGender = (DropDownList)GrdStaff.FooterRow.FindControl("ddlNewGender"); TextBox txtDOB = (TextBox)GrdStaff.FooterRow.FindControl("txtNewDOB"); TextBox txtLogin = (TextBox)GrdStaff.FooterRow.FindControl("txtNewLogin"); TextBox txtPwd = (TextBox)GrdStaff.FooterRow.FindControl("txtNewPwd"); //DropDownList ddlStaffPosition = (DropDownList)GrdStaff.FooterRow.FindControl("ddlNewStaffPosition"); DropDownList ddlField = (DropDownList)GrdStaff.FooterRow.FindControl("ddlNewField"); CheckBox chkContractor = (CheckBox)GrdStaff.FooterRow.FindControl("chkNewContractor"); TextBox txtTFN = (TextBox)GrdStaff.FooterRow.FindControl("txtNewTFN"); DropDownList ddlStatus = (DropDownList)GrdStaff.FooterRow.FindControl("ddlStatus"); DropDownList ddlCostCentre = (DropDownList)GrdStaff.FooterRow.FindControl("ddlNewCostCentre"); TextBox txtProviderNumber = (TextBox)GrdStaff.FooterRow.FindControl("txtNewProviderNumber"); CheckBox chkIsCommission = (CheckBox)GrdStaff.FooterRow.FindControl("chkNewIsCommission"); TextBox txtCommissionPercent = (TextBox)GrdStaff.FooterRow.FindControl("txtNewCommissionPercent"); CheckBox chkIsStakeholder = (CheckBox)GrdStaff.FooterRow.FindControl("chkNewIsStakeholder"); CheckBox chkIsAdmin = (CheckBox)GrdStaff.FooterRow.FindControl("chkNewIsAdmin"); CheckBox chkIsMasterAdmin = (CheckBox)GrdStaff.FooterRow.FindControl("chkNewIsMasterAdmin"); CheckBox chkIsPrincipal = (CheckBox)GrdStaff.FooterRow.FindControl("chkNewIsPrincipal"); CheckBox chkIsProvider = (CheckBox)GrdStaff.FooterRow.FindControl("chkNewIsProvider"); CheckBox chkSMSBKs = (CheckBox)GrdStaff.FooterRow.FindControl("chkNewSMSBKs"); CheckBox chkEmailBKs = (CheckBox)GrdStaff.FooterRow.FindControl("chkNewEmailBKs"); CheckBox chkHideBKNotes = (CheckBox)GrdStaff.FooterRow.FindControl("chkNewHideBKNotes"); if (chkIsProvider.Checked && (StaffDB.GetCountOfProviders() >= Convert.ToInt32(SystemVariableDB.GetByDescr("MaxNbrProviders").Value))) { SetErrorMessage("You have reached your maximum allowable providers. Please uncheck their status as a provider to add them. Contact Mediclinic if you would like to upgrade your account."); return; } if (!Convert.ToBoolean(ConfigurationManager.AppSettings["UseConfigDB"]) && UserDatabaseMapperDB.UsernameExists(txtLogin.Text)) { SetErrorMessage("Login name already in use by another user"); return; } if (StaffDB.LoginExists(txtLogin.Text)) { SetErrorMessage("Login name already in use by another user"); return; } if (txtPwd.Text.Length < 6) { SetErrorMessage("Password must be at least 6 characters"); return; } DateTime dob = GetDate(txtDOB.Text.Trim()); int person_id = -1; int mainDbUserID = -1; try { if (!!Convert.ToBoolean(ConfigurationManager.AppSettings["UseConfigDB"])) { mainDbUserID = UserDatabaseMapperDB.Insert(txtLogin.Text, Session["DB"].ToString()); } if (chkIsMasterAdmin.Checked) { chkIsAdmin.Checked = true; } Staff loggedInStaff = StaffDB.GetByID(Convert.ToInt32(Session["StaffID"])); person_id = PersonDB.Insert(loggedInStaff.Person.PersonID, Convert.ToInt32(ddlTitle.SelectedValue), Utilities.FormatName(txtFirstname.Text), Utilities.FormatName(txtMiddlename.Text), Utilities.FormatName(txtSurname.Text), "", ddlGender.SelectedValue, dob); StaffDB.Insert(person_id, txtLogin.Text, txtPwd.Text, StaffPositionDB.GetByDescr("Unknown").StaffPositionID, Convert.ToInt32(ddlField.SelectedValue), Convert.ToInt32(ddlCostCentre.SelectedValue), chkContractor.Checked, txtTFN.Text, txtProviderNumber.Text.ToUpper(), ddlStatus.SelectedValue == "Inactive", chkIsCommission.Checked, Convert.ToDecimal(txtCommissionPercent.Text), chkIsStakeholder.Checked, chkIsMasterAdmin.Checked, chkIsAdmin.Checked, chkIsPrincipal.Checked, chkIsProvider.Checked, false, DateTime.Today, DateTime.MinValue, "", chkSMSBKs.Checked, chkEmailBKs.Checked, chkHideBKNotes.Checked); FillGrid(); } catch (Exception) { // roll back - backwards of creation order PersonDB.Delete(person_id); if (!!Convert.ToBoolean(ConfigurationManager.AppSettings["UseConfigDB"])) { UserDatabaseMapperDB.Delete(mainDbUserID); } } } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (!ddlEndDateValidateAllOrNoneSet.IsValid || !ddlStartDateValidateAllOrNoneSet.IsValid || !ddlDOBValidateAllOrNoneSet.IsValid) { return; } txtPwd.Attributes["value"] = txtPwd.Text; // pwd fields is unset on send back to server, so re-set it if (GetUrlParamType() == UrlParamType.View) { Response.Redirect(UrlParamModifier.AddEdit(Request.RawUrl, "type", "edit")); } else if (GetUrlParamType() == UrlParamType.Edit) { Staff staff = StaffDB.GetByID(Convert.ToInt32(this.lblId.Text)); if (!Convert.ToBoolean(ConfigurationManager.AppSettings["UseConfigDB"]) && staff.Login != txtLogin.Text && UserDatabaseMapperDB.UsernameExists(txtLogin.Text)) { SetErrorMessage("Login name already in use by another user"); return; } if (StaffDB.LoginExists(txtLogin.Text, staff.StaffID)) { SetErrorMessage("Login name already in use by another user"); return; } if (staff.Pwd != txtPwd.Text && txtPwd.Text.Length < 6) { SetErrorMessage(staff.Pwd.Length >= 6 ? "Password must be at least 6 characters" : "New passwords must be at least 6 characters"); return; } bool loggedInUserIsStakeholder = Session["IsStakeholder"] != null && Convert.ToBoolean(Session["IsStakeholder"]); bool loggedInUserIsMasterAdmin = Session["IsMasterAdmin"] != null && Convert.ToBoolean(Session["IsMasterAdmin"]); bool setIsStakeholder = loggedInUserIsStakeholder ? chkIsStakeholder.Checked : staff.IsStakeholder; bool setIsMasterAdmin = loggedInUserIsStakeholder || loggedInUserIsMasterAdmin ? chkIsMasterAdmin.Checked : staff.IsMasterAdmin; if (!staff.IsProvider && chkIsProvider.Checked && (StaffDB.GetCountOfProviders() >= Convert.ToInt32(SystemVariableDB.GetByDescr("MaxNbrProviders").Value))) { SetErrorMessage("You have reached your maximum allowable providers. Please uncheck their status as a provider to update them or hit cancel. Contact Mediclinic if you would like to upgrade your account."); return; } if (chkIsProvider.Checked) { System.Data.DataTable tbl = DBBase.GetGenericDataTable_WithWhereOrderClause(null, "Field", "has_offerings=1 AND field_id <> 0", "", "field_id", "descr"); bool roleSetAsProvider = false; IDandDescr[] fields = new IDandDescr[tbl.Rows.Count]; for (int i = 0; i < tbl.Rows.Count; i++) { fields[i] = new IDandDescr(Convert.ToInt32(tbl.Rows[i]["field_id"]), tbl.Rows[i]["descr"].ToString()); if (Convert.ToInt32(ddlField.SelectedValue) == Convert.ToInt32(tbl.Rows[i]["field_id"])) { roleSetAsProvider = true; } } if (!roleSetAsProvider) { if (fields.Length == 1) { SetErrorMessage("When setting a staff member as a provider, you need to set their Role as '" + fields[0].Descr + "'."); return; } else if (fields.Length == 2) { SetErrorMessage("When setting a staff member as a provider, you need to set their Role as '" + fields[0].Descr + "' or '" + fields[1].Descr + "'."); return; } else { string providerFields = string.Empty; for (int i = 0; i < fields.Length; i++) { providerFields += (providerFields.Length == 0 ? "" : ", ") + (fields.Length >= 2 && i == (fields.Length - 2) ? "or " : "") + fields[i].Descr; } SetErrorMessage("When setting a staff member as a provider, you need to set their Role as one of the following: " + providerFields); return; } } } if (chkIsMasterAdmin.Checked) { chkIsAdmin.Checked = true; } PersonDB.Update(staff.Person.PersonID, Convert.ToInt32(ddlTitle.SelectedValue), Utilities.FormatName(txtFirstname.Text), Utilities.FormatName(txtMiddlename.Text), Utilities.FormatName(txtSurname.Text), staff.Person.Nickname, ddlGender.SelectedValue, GetDOBFromForm(), DateTime.Now); StaffDB.Update(staff.StaffID, staff.Person.PersonID, txtLogin.Text, txtPwd.Text, staff.StaffPosition.StaffPositionID, Convert.ToInt32(ddlField.SelectedValue), staff.CostCentre.CostCentreID, chkContractor.Checked, txtTFN.Text, txtProviderNumber.Text.ToUpper(), ddlStatus.SelectedValue == "Inactive", chkIsCommission.Checked, Convert.ToDecimal(txtCommissionPercent.Text), setIsStakeholder, setIsMasterAdmin, chkIsAdmin.Checked, chkIsPrincipal.Checked, chkIsProvider.Checked, staff.IsExternal, GetStartDateFromForm(), GetEndDateFromForm(), txtComments.Text, chkSMSBKs.Checked, chkEmailBKs.Checked); if (!Convert.ToBoolean(ConfigurationManager.AppSettings["UseConfigDB"]) && staff.Login != txtLogin.Text) { UserDatabaseMapper curDBMapper = UserDatabaseMapperDB.GetByLogin(staff.Login, Session["DB"].ToString()); if (curDBMapper == null) { UserDatabaseMapperDB.Insert(txtLogin.Text, Session["DB"].ToString()); } else { UserDatabaseMapperDB.Update(curDBMapper.ID, txtLogin.Text, Session["DB"].ToString()); } } Response.Redirect(UrlParamModifier.AddEdit(Request.RawUrl, "type", "view")); } else if (GetUrlParamType() == UrlParamType.Add) { if (chkIsProvider.Checked && (StaffDB.GetCountOfProviders() >= Convert.ToInt32(SystemVariableDB.GetByDescr("MaxNbrProviders").Value))) { SetErrorMessage("You have reached your maximum allowable providers. Please uncheck their status as a provider to add them. Contact Mediclinic if you would like to upgrade your account."); return; } if (chkIsProvider.Checked) { System.Data.DataTable tbl = DBBase.GetGenericDataTable_WithWhereOrderClause(null, "Field", "has_offerings=1 AND field_id <> 0", "", "field_id", "descr"); bool roleSetAsProvider = false; IDandDescr[] fields = new IDandDescr[tbl.Rows.Count]; for (int i = 0; i < tbl.Rows.Count; i++) { fields[i] = new IDandDescr(Convert.ToInt32(tbl.Rows[i]["field_id"]), tbl.Rows[i]["descr"].ToString()); if (Convert.ToInt32(ddlField.SelectedValue) == Convert.ToInt32(tbl.Rows[i]["field_id"])) { roleSetAsProvider = true; } } if (!roleSetAsProvider) { if (fields.Length == 1) { SetErrorMessage("When setting a staff member as a provider, you need to set their Role as '" + fields[0].Descr + "'."); return; } else if (fields.Length == 2) { SetErrorMessage("When setting a staff member as a provider, you need to set their Role as '" + fields[0].Descr + "' or '" + fields[1].Descr + "'."); return; } else { string providerFields = string.Empty; for (int i = 0; i < fields.Length; i++) { providerFields += (providerFields.Length == 0 ? "" : ", ") + (fields.Length >= 2 && i == (fields.Length - 2) ? "or " : "") + fields[i].Descr; } SetErrorMessage("When setting a staff member as a provider, you need to set their Role as one of the following: " + providerFields); return; } } } if (!Convert.ToBoolean(ConfigurationManager.AppSettings["UseConfigDB"]) && UserDatabaseMapperDB.UsernameExists(txtLogin.Text)) { lblErrorMessage.Text = "Login name already in use by another user"; lblErrorMessage.Visible = true; return; } if (StaffDB.LoginExists(txtLogin.Text)) { lblErrorMessage.Text = "Login name already in use by another user"; lblErrorMessage.Visible = true; return; } if (txtPwd.Text.Length < 6) { SetErrorMessage("Password must be at least 6 characters"); return; } int person_id = -1; int staff_id = -1; bool staff_added = false; int mainDbUserID = -1; try { if (!Convert.ToBoolean(ConfigurationManager.AppSettings["UseConfigDB"])) { mainDbUserID = UserDatabaseMapperDB.Insert(txtLogin.Text, Session["DB"].ToString()); } bool loggedInUserIsStakeholder = Session["IsStakeholder"] != null && Convert.ToBoolean(Session["IsStakeholder"]); bool loggedInUserIsMasterAdmin = Session["IsMasterAdmin"] != null && Convert.ToBoolean(Session["IsMasterAdmin"]); bool setIsStakeholder = loggedInUserIsStakeholder ? chkIsStakeholder.Checked : false; bool setIsMasterAdmin = loggedInUserIsStakeholder || loggedInUserIsMasterAdmin ? chkIsMasterAdmin.Checked : false; if (chkIsMasterAdmin.Checked) { chkIsAdmin.Checked = true; } Staff loggedInStaff = StaffDB.GetByID(Convert.ToInt32(Session["StaffID"])); person_id = PersonDB.Insert(loggedInStaff.Person.PersonID, Convert.ToInt32(ddlTitle.SelectedValue), Utilities.FormatName(txtFirstname.Text), Utilities.FormatName(txtMiddlename.Text), Utilities.FormatName(txtSurname.Text), "", ddlGender.SelectedValue, GetDOBFromForm()); staff_id = StaffDB.Insert(person_id, txtLogin.Text, txtPwd.Text, StaffPositionDB.GetByDescr("Unknown").StaffPositionID, Convert.ToInt32(ddlField.SelectedValue), 59, chkContractor.Checked, txtTFN.Text, txtProviderNumber.Text.ToUpper(), ddlStatus.SelectedValue == "Inactive", chkIsCommission.Checked, Convert.ToDecimal(txtCommissionPercent.Text), setIsStakeholder, setIsMasterAdmin, chkIsAdmin.Checked, chkIsPrincipal.Checked, chkIsProvider.Checked, false, GetStartDateFromForm(), GetEndDateFromForm(), txtComments.Text, chkSMSBKs.Checked, chkEmailBKs.Checked); staff_added = true; string url = Request.RawUrl; url = UrlParamModifier.AddEdit(url, "type", "view"); url = UrlParamModifier.AddEdit(url, "id", staff_id.ToString()); Response.Redirect(url); } catch (Exception) { if (staff_added) { string url = Request.RawUrl; url = UrlParamModifier.AddEdit(url, "type", "view"); url = UrlParamModifier.AddEdit(url, "id", staff_id.ToString()); Response.Redirect(url); return; } // roll back - backwards of creation order PersonDB.Delete(person_id); if (!Convert.ToBoolean(ConfigurationManager.AppSettings["UseConfigDB"])) { UserDatabaseMapperDB.Delete(mainDbUserID); } throw; } } else { HideTableAndSetErrorMessage(); } }