public void Delete(Person p)
        {
            PersonDB db = new PersonDB();

            db.Delete(p);
            db.SaveChanges();
        }
示例#2
0
        //删除指定ID的person
        static void DeletePersonById()
        {
            Person person = new Person()
            {
                Id = 1
            };
            int effectNum = PersonDB.Delete(person);

            Console.WriteLine($"删除了{effectNum}行数据!");
        }
示例#3
0
        //根据ID批量删除Person记录
        static void DeletePersonsById()
        {
            List <Person> persons = new List <Person>()
            {
                new Person()
                {
                    Id = 2
                },
                new Person()
                {
                    Id = 3
                }
            };
            int effectNum = PersonDB.Delete(persons);

            Console.WriteLine($"删除了{effectNum}行数据!");
        }
    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();
        }
    }
示例#5
0
    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 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);
                }
            }
        }
    }
示例#7
0
    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();
        }
    }
 public void DeletePerson(int id) => _persondb.Delete(id);
示例#9
0
    protected void CreatePatientButton_Click(object sender, EventArgs e)
    {
        if (!ddlDOBValidateAllSet.IsValid)
        {
            return;
        }

        int  person_id           = -1;
        int  patient_id          = -1;
        int  register_patient_id = -1;
        bool patient_added       = false;
        int  mainDbUserID        = -1;

        int  phone_id       = -1;
        int  email_id       = -1;
        bool contacts_added = false;

        try
        {
            string[] clinicInfo = ddlClinic.SelectedValue.Split(new string[] { "__" }, StringSplitOptions.None);
            string   dbID       = clinicInfo[0];
            int      siteID     = Convert.ToInt32(clinicInfo[1]);
            int      orgID      = Convert.ToInt32(clinicInfo[2]);

            Session["DB"] = dbID;
            Session["SystemVariables"] = SystemVariableDB.GetAll();

            txtEmailAddr.Text   = txtEmailAddr.Text.Trim();
            txtPhoneNumber.Text = txtPhoneNumber.Text.Trim();
            if (!Utilities.IsValidEmailAddress(txtEmailAddr.Text))
            {
                throw new CustomMessageException("Email must be in valid email format.");
            }

            txtLogin.Text = txtLogin.Text.Trim();
            txtPwd.Text   = txtPwd.Text.Trim();

            txtFirstname.Text = txtFirstname.Text.Trim();
            txtSurname.Text   = txtSurname.Text.Trim();



            // check if patient exists in the system, if so use existing patietn

            bool patientAlreadyExists = false;

            // check if email exists in the system
            if (!patientAlreadyExists)
            {
                if (ExistsAndCreatedLogin_FromEmail(orgID, txtPhoneNumber.Text, txtEmailAddr.Text, siteID, ref register_patient_id, ref phone_id, ref email_id))
                {
                    patientAlreadyExists      = true;
                    patient_added             = true;
                    contacts_added            = true;
                    this.lblErrorMessage.Text = "Your email alrady exist in this sytem.<br/>An email has been sent with new login details.<br/>When you receieve it, use the login link below.";
                }
            }

            // check if firstname / surname / DOB exists in the system
            if (!patientAlreadyExists)
            {
                if (ExistsAndCreatedLogin_FromNameAndDOB(orgID, txtPhoneNumber.Text, txtEmailAddr.Text, txtFirstname.Text, txtSurname.Text, GetDOBFromForm(), siteID, ref register_patient_id, ref phone_id, ref email_id))
                {
                    patientAlreadyExists      = true;
                    patient_added             = true;
                    contacts_added            = true;
                    this.lblErrorMessage.Text = "You alrady exist in this sytem.<br/>An email has been sent with new login details.<br/>When you receieve it, use the login link below.";
                }
            }



            if (!patientAlreadyExists)
            {
                if (!Convert.ToBoolean(ConfigurationManager.AppSettings["UseConfigDB"]) && UserDatabaseMapperDB.UsernameExists(txtLogin.Text))
                {
                    throw new CustomMessageException("Login name already in use. Please choose another");
                }
                if (PatientDB.LoginExists(txtLogin.Text))
                {
                    throw new CustomMessageException("Login name already in use. Please choose another");
                }


                // 1. Create Patient

                Staff loggedInStaff = StaffDB.GetByID(-6);
                person_id           = PersonDB.Insert(loggedInStaff.Person.PersonID, Convert.ToInt32(ddlTitle.SelectedValue), Utilities.FormatName(txtFirstname.Text), "", Utilities.FormatName(txtSurname.Text), "", ddlGender.SelectedValue, GetDOBFromForm());
                patient_id          = PatientDB.Insert(person_id, true, false, false, "", -1, DateTime.MinValue, "", "", DateTime.MinValue, false, false, DateTime.MinValue, -1, -1, txtLogin.Text, txtPwd.Text, false, "", "", "", "");
                register_patient_id = RegisterPatientDB.Insert(orgID, patient_id);
                patient_added       = true;   // added this because was throwing a thread aborted exception after patient added before Response.Redirect


                if (!Convert.ToBoolean(ConfigurationManager.AppSettings["UseConfigDB"]))
                {
                    if (txtLogin.Text.Length > 0)
                    {
                        mainDbUserID = UserDatabaseMapperDB.Insert(txtLogin.Text, Session["DB"].ToString());
                    }
                }


                // 2. Add Contact Info

                Patient patient = PatientDB.GetByID(patient_id);

                phone_id            = AddPhoneNbrIfNotExists(patient, siteID, txtPhoneNumber.Text);
                email_id            = AddEmailIfNotExists(patient, siteID, txtEmailAddr.Text);
                register_patient_id = AddOrgIfNotExists(patient, siteID, orgID);
                contacts_added      = true;


                SendInfoEmail(txtEmailAddr.Text, txtLogin.Text, txtPwd.Text);

                this.lblErrorMessage.Text = "An email has been sent with new login details.<br />When you receieve it, use the login link below.";
            }
        }
        catch (Exception ex)
        {
            if (!patient_added || !contacts_added)
            {
                // roll back - backwards of creation order

                if (Utilities.GetAddressType().ToString() == "Contact")
                {
                    ContactDB.Delete(phone_id);
                    ContactDB.Delete(email_id);
                }
                else if (Utilities.GetAddressType().ToString() == "ContactAus")
                {
                    ContactAusDB.Delete(phone_id);
                    ContactAusDB.Delete(email_id);
                }
                else
                {
                    throw new Exception("Unknown AddressType in config: " + Utilities.GetAddressType().ToString().ToString());
                }

                RegisterPatientDB.Delete(register_patient_id);
                PatientDB.Delete(patient_id);
                PersonDB.Delete(person_id);

                if (!Convert.ToBoolean(ConfigurationManager.AppSettings["UseConfigDB"]))
                {
                    UserDatabaseMapperDB.Delete(mainDbUserID);
                }

                if (ex is CustomMessageException)
                {
                    this.lblErrorMessage.Text = ex.Message;
                }
                else
                {
                    lblErrorMessage.Text = ex.ToString();
                }
            }
        }
        finally
        {
            //Session["DB"] = curDbName;
            //Session["SystemVariables"] = SystemVariableDB.GetAll();
            Session.Remove("DB");
            Session.Remove("SystemVariables");
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        // need to be able to roll back .. so keep id's same as invoice

        int  person_id      = -1;
        int  referrer_id    = -1;
        int  new_org_id     = 0;
        bool referrer_added = false;

        int  address_id     = -1;
        int  phone_id1      = -1;
        int  phone_id2      = -1;
        int  email_id       = -1;
        bool contacts_added = false;

        try
        {
            // add referrer
            if (lblId.Text == "-1") // add new referrer
            {
                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, new DateTime(1900, 1, 1));
                referrer_id = ReferrerDB.Insert(person_id);
            }
            else  // set existing referrer
            {
                referrer_id = Convert.ToInt32(lblId.Text);
            }


            // get org (or add new org)
            int org_id = 0;
            if (orgsListRow.Visible)
            {
                org_id = Convert.ToInt32(ddlOrgsList.SelectedValue);
            }
            else
            {
                org_id = new_org_id = OrganisationDB.InsertExtOrg(191, txtOrgName.Text, txtOrgACN.Text, txtOrgABN.Text, false, false, "", txtOrgComments.Text);

                // add contact info

                Organisation org = OrganisationDB.GetByID(org_id);

                if (Utilities.GetAddressType().ToString() == "Contact")
                {
                    if (txtAddressAddrLine1.Text.Trim().Length > 0 || txtAddressAddrLine2.Text.Trim().Length > 0)
                    {
                        address_id = ContactDB.Insert(org.EntityID,
                                                      Convert.ToInt32(ddlAddressContactType.SelectedValue),
                                                      txtAddressFreeText.Text,
                                                      txtAddressAddrLine1.Text,
                                                      txtAddressAddrLine2.Text,
                                                      Convert.ToInt32(ddlAddressAddressChannel.SelectedValue),
                                                      //Convert.ToInt32(ddlAddressSuburb.SelectedValue),
                                                      Convert.ToInt32(suburbID.Value),
                                                      Convert.ToInt32(ddlAddressCountry.SelectedValue),
                                                      Convert.ToInt32(Session["SiteID"]),
                                                      true,
                                                      true);
                    }

                    if (txtPhoneNumber1.Text.Trim().Length > 0)
                    {
                        phone_id1 = ContactDB.Insert(org.EntityID,
                                                     Convert.ToInt32(ddlPhoneNumber1.SelectedValue),
                                                     txtPhoneNumber1FreeText.Text,
                                                     System.Text.RegularExpressions.Regex.Replace(txtPhoneNumber1.Text, "[^0-9]", ""),
                                                     string.Empty,
                                                     -1,
                                                     -1,
                                                     -1,
                                                     Convert.ToInt32(Session["SiteID"]),
                                                     true,
                                                     true);
                    }

                    if (txtPhoneNumber2.Text.Trim().Length > 0)
                    {
                        phone_id2 = ContactDB.Insert(org.EntityID,
                                                     Convert.ToInt32(ddlPhoneNumber2.SelectedValue),
                                                     txtPhoneNumber2FreeText.Text,
                                                     System.Text.RegularExpressions.Regex.Replace(txtPhoneNumber2.Text, "[^0-9]", ""),
                                                     string.Empty,
                                                     -1,
                                                     -1,
                                                     -1,
                                                     Convert.ToInt32(Session["SiteID"]),
                                                     true,
                                                     true);
                    }

                    if (txtEmailAddrLine1.Text.Trim().Length > 0)
                    {
                        email_id = ContactDB.Insert(org.EntityID,
                                                    Convert.ToInt32(ddlEmailContactType.SelectedValue),
                                                    "",
                                                    txtEmailAddrLine1.Text,
                                                    string.Empty,
                                                    -1,
                                                    -1,
                                                    -1,
                                                    Convert.ToInt32(Session["SiteID"]),
                                                    true,
                                                    true);
                    }
                }
                else if (Utilities.GetAddressType().ToString() == "ContactAus")
                {
                    if (txtAddressAddrLine1.Text.Trim().Length > 0 || txtAddressAddrLine2.Text.Trim().Length > 0)
                    {
                        address_id = ContactAusDB.Insert(org.EntityID,
                                                         Convert.ToInt32(ddlAddressContactType.SelectedValue),
                                                         txtAddressFreeText.Text,
                                                         txtAddressAddrLine1.Text,
                                                         txtAddressAddrLine2.Text,
                                                         txtStreet.Text,
                                                         Convert.ToInt32(ddlAddressAddressChannelType.SelectedValue),
                                                         //Convert.ToInt32(ddlAddressSuburb.SelctedValue),
                                                         Convert.ToInt32(suburbID.Value),
                                                         Convert.ToInt32(ddlAddressCountry.SelectedValue),
                                                         Convert.ToInt32(Session["SiteID"]),
                                                         true,
                                                         true);
                    }

                    if (txtPhoneNumber1.Text.Trim().Length > 0)
                    {
                        phone_id1 = ContactAusDB.Insert(org.EntityID,
                                                        Convert.ToInt32(ddlPhoneNumber1.SelectedValue),
                                                        txtPhoneNumber1FreeText.Text,
                                                        System.Text.RegularExpressions.Regex.Replace(txtPhoneNumber1.Text, "[^0-9]", ""),
                                                        string.Empty,
                                                        string.Empty,
                                                        -1,
                                                        -1,
                                                        -1,
                                                        Convert.ToInt32(Session["SiteID"]),
                                                        true,
                                                        true);
                    }

                    if (txtPhoneNumber2.Text.Trim().Length > 0)
                    {
                        phone_id2 = ContactAusDB.Insert(org.EntityID,
                                                        Convert.ToInt32(ddlPhoneNumber2.SelectedValue),
                                                        txtPhoneNumber2FreeText.Text,
                                                        System.Text.RegularExpressions.Regex.Replace(txtPhoneNumber2.Text, "[^0-9]", ""),
                                                        string.Empty,
                                                        string.Empty,
                                                        -1,
                                                        -1,
                                                        -1,
                                                        Convert.ToInt32(Session["SiteID"]),
                                                        true,
                                                        true);
                    }

                    if (txtEmailAddrLine1.Text.Trim().Length > 0)
                    {
                        email_id = ContactAusDB.Insert(org.EntityID,
                                                       Convert.ToInt32(ddlEmailContactType.SelectedValue),
                                                       "",
                                                       txtEmailAddrLine1.Text,
                                                       string.Empty,
                                                       string.Empty,
                                                       -1,
                                                       -1,
                                                       -1,
                                                       Convert.ToInt32(Session["SiteID"]),
                                                       true,
                                                       true);
                    }
                }
                else
                {
                    throw new Exception("Unknown AddressType in config: " + Utilities.GetAddressType().ToString().ToString());
                }
            }

            contacts_added = true;

            // join association
            RegisterReferrerDB.Insert(org_id, referrer_id, txtProviderNumber.Text, chkIsReportEveryVisit.Checked, chkIsBatchSendAllPatientsTreatmentNotes.Checked);
            referrer_added = true;


            if (GetUrlIsPopup())
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.returnValue=false;self.close();</script>");
            }
            else
            {
                Response.Redirect("~/ReferrerList_DoctorClinicV2.aspx?surname_search=" + Utilities.FormatName(txtSurname.Text) + "&surname_starts_with=1", false);
                return;
            }
        }
        catch (Exception)
        {
            // roll back - backwards of creation order

            if (Utilities.GetAddressType().ToString() == "Contact")
            {
                ContactDB.Delete(address_id);
                ContactDB.Delete(phone_id1);
                ContactDB.Delete(phone_id2);
                ContactDB.Delete(email_id);
            }
            else if (Utilities.GetAddressType().ToString() == "ContactAus")
            {
                ContactAusDB.Delete(address_id);
                ContactAusDB.Delete(phone_id1);
                ContactAusDB.Delete(phone_id2);
                ContactAusDB.Delete(email_id);
            }
            else
            {
                throw new Exception("Unknown AddressType in config: " + Utilities.GetAddressType().ToString().ToString());
            }

            OrganisationDB.Delete(new_org_id);
            ReferrerDB.Delete(referrer_id);
            PersonDB.Delete(person_id);

            throw;
        }
    }
    protected void GrdReferrer_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("Insert"))
        {
            DropDownList ddlTitle      = (DropDownList)GrdReferrer.FooterRow.FindControl("ddlNewTitle");
            TextBox      txtFirstname  = (TextBox)GrdReferrer.FooterRow.FindControl("txtNewFirstname");
            TextBox      txtMiddlename = (TextBox)GrdReferrer.FooterRow.FindControl("txtNewMiddlename");
            TextBox      txtSurname    = (TextBox)GrdReferrer.FooterRow.FindControl("txtNewSurname");
            DropDownList ddlGender     = (DropDownList)GrdReferrer.FooterRow.FindControl("ddlNewGender");

            TextBox txtName = (TextBox)GrdReferrer.FooterRow.FindControl("txtNewName");
            TextBox txtABN  = (TextBox)GrdReferrer.FooterRow.FindControl("txtNewABN");
            TextBox txtACN  = (TextBox)GrdReferrer.FooterRow.FindControl("txtNewACN");

            TextBox      txtProviderNumber     = (TextBox)GrdReferrer.FooterRow.FindControl("txtNewProviderNumber");
            DropDownList ddlIsClinic           = (DropDownList)GrdReferrer.FooterRow.FindControl("ddlNewIsClinic");
            CheckBox     chkIsReportEveryVisit = (CheckBox)GrdReferrer.FooterRow.FindControl("chkNewIsReportEveryVisit");
            CheckBox     chkIsBatchSendAllPatientsTreatmentNotes = (CheckBox)GrdReferrer.FooterRow.FindControl("chkNewIsBatchSendAllPatientsTreatmentNotes");


            int person_id            = -1;
            int referrer_id          = -1;
            int organisation_id      = 0;
            int register_referrer_id = -1;

            try
            {
                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, new DateTime(1900, 1, 1));
                referrer_id          = ReferrerDB.Insert(person_id);
                organisation_id      = OrganisationDB.InsertExtOrg(191, txtName.Text, txtACN.Text, txtABN.Text, false, false, "", "");
                register_referrer_id = RegisterReferrerDB.Insert(organisation_id, referrer_id, txtProviderNumber.Text, chkIsReportEveryVisit.Checked, chkIsBatchSendAllPatientsTreatmentNotes.Checked);

                FillGrid();
            }
            catch (Exception)
            {
                // roll back - backwards of creation order
                RegisterReferrerDB.Delete(register_referrer_id);
                OrganisationDB.Delete(organisation_id);
                ReferrerDB.Delete(referrer_id);
                PersonDB.Delete(person_id);
            }
        }

        if (e.CommandName.Equals("_Delete") || e.CommandName.Equals("_UnDelete"))
        {
            int register_referrer_id = Convert.ToInt32(e.CommandArgument);

            try
            {
                if (e.CommandName.Equals("_Delete"))
                {
                    RegisterReferrerDB.UpdateInactive(register_referrer_id);
                }
                else
                {
                    RegisterReferrerDB.UpdateActive(register_referrer_id);
                }
            }
            catch (ForeignKeyConstraintException fkcEx)
            {
                if (Utilities.IsDev())
                {
                    SetErrorMessage("Can not delete because other records depend on this : " + fkcEx.Message);
                }
                else
                {
                    SetErrorMessage("Can not delete because other records depend on this");
                }
            }

            FillGrid();
        }
    }