protected void GrdOffering_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("Insert"))
        {
            TextBox      txtName         = (TextBox)GrdOffering.FooterRow.FindControl("txtNewName");
            TextBox      txtShortName    = (TextBox)GrdOffering.FooterRow.FindControl("txtNewShortName");
            TextBox      txtDescr        = (TextBox)GrdOffering.FooterRow.FindControl("txtNewDescr");
            DropDownList ddlOfferingType = (DropDownList)GrdOffering.FooterRow.FindControl("ddlNewOfferingType");
            DropDownList ddlField        = (DropDownList)GrdOffering.FooterRow.FindControl("ddlNewField");
            DropDownList ddlOfferingPatientSubcategory    = (DropDownList)GrdOffering.FooterRow.FindControl("ddlNewOfferingPatientSubcategory");
            DropDownList ddlNumClinicVisitsAllowedPerYear = (DropDownList)GrdOffering.FooterRow.FindControl("ddlNewNumClinicVisitsAllowedPerYear");
            DropDownList ddlOfferingInvoiceType           = (DropDownList)GrdOffering.FooterRow.FindControl("ddlNewOfferingInvoiceType");
            CheckBox     chkIsGstExempt                          = (CheckBox)GrdOffering.FooterRow.FindControl("chkNewIsGstExempt");
            TextBox      txtDefaultPrice                         = (TextBox)GrdOffering.FooterRow.FindControl("txtNewDefaultPrice");
            DropDownList ddlServiceTimeMinutes                   = (DropDownList)GrdOffering.FooterRow.FindControl("ddlNewServiceTimeMinutes");
            DropDownList ddlMaxNbrClaimable                      = (DropDownList)GrdOffering.FooterRow.FindControl("ddlNewMaxNbrClaimable");
            DropDownList ddlMaxNbrClaimableMonths                = (DropDownList)GrdOffering.FooterRow.FindControl("ddlNewMaxNbrClaimableMonths");
            TextBox      txtMedicareCompanyCode                  = (TextBox)GrdOffering.FooterRow.FindControl("txtNewMedicareCompanyCode");
            TextBox      txtDvaCompanyCode                       = (TextBox)GrdOffering.FooterRow.FindControl("txtNewDvaCompanyCode");
            TextBox      txtTacCompanyCode                       = (TextBox)GrdOffering.FooterRow.FindControl("txtNewTacCompanyCode");
            TextBox      txtMedicareCharge                       = (TextBox)GrdOffering.FooterRow.FindControl("txtNewMedicareCharge");
            TextBox      txtDvaCharge                            = (TextBox)GrdOffering.FooterRow.FindControl("txtNewDvaCharge");
            TextBox      txtTacCharge                            = (TextBox)GrdOffering.FooterRow.FindControl("txtNewTacCharge");
            DropDownList ddlReminderLetterMonthsLaterToSend      = (DropDownList)GrdOffering.FooterRow.FindControl("ddlNewReminderLetterMonthsLaterToSend");
            DropDownList ddlReminderLetter                       = (DropDownList)GrdOffering.FooterRow.FindControl("ddlNewReminderLetter");
            CheckBox     chkUseCustomColour                      = (CheckBox)GrdOffering.FooterRow.FindControl("chkNewUseCustomColour");
            System.Web.UI.HtmlControls.HtmlInputText ColorPicker = (System.Web.UI.HtmlControls.HtmlInputText)GrdOffering.FooterRow.FindControl("NewColorPicker");


            if (Convert.ToInt32(ddlReminderLetterMonthsLaterToSend.SelectedValue) > 0 && Convert.ToInt32(ddlReminderLetter.SelectedValue) == -1)
            {
                SetErrorMessage("For reminder letters - you must either set the number of months as disabled or select a reminder letter.");
                return;
            }


            // if logged not AC system, set AC patient subcat as 1 (--Not Aged Care--)
            // if logged not Clinic system, set clinic visit type as -1 (--Not Clinic--)
            // these are hidden in the gui also in method 'GrdOffering_RowCreated'
            int offeringPatientSubcategoryID = !UserView.GetInstance().IsAgedCareView ? 1 : Convert.ToInt32(ddlOfferingPatientSubcategory.SelectedValue);

            OfferingDB.Insert(Convert.ToInt32(ddlOfferingType.SelectedValue), Convert.ToInt32(ddlField.SelectedValue),
                              offeringPatientSubcategoryID,
                              Convert.ToInt32(ddlNumClinicVisitsAllowedPerYear.SelectedValue),
                              Convert.ToInt32(ddlOfferingInvoiceType.SelectedValue),
                              txtName.Text, txtShortName.Text, txtDescr.Text,
                              chkIsGstExempt.Checked, Convert.ToDecimal(txtDefaultPrice.Text), Convert.ToInt32(ddlServiceTimeMinutes.Text),
                              Convert.ToInt32(ddlMaxNbrClaimable.SelectedValue), Convert.ToInt32(ddlMaxNbrClaimableMonths.SelectedValue),
                              txtMedicareCompanyCode.Text.Trim(), txtDvaCompanyCode.Text.Trim(), txtTacCompanyCode.Text.Trim(),
                              Convert.ToDecimal(txtMedicareCharge.Text), Convert.ToDecimal(txtDvaCharge.Text), Convert.ToDecimal(txtTacCharge.Text), "",
                              Convert.ToInt32(ddlReminderLetterMonthsLaterToSend.SelectedValue),
                              Convert.ToInt32(ddlReminderLetter.SelectedValue),
                              chkUseCustomColour.Checked,
                              ColorPicker.Value
                              );

            Session["OfferingColors"] = OfferingDB.GetColorCodes();

            FillGrid();
        }

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

            try
            {
                if (e.CommandName.Equals("_Delete"))
                {
                    OfferingDB.UpdateInactive(offering_id);
                }
                else
                {
                    OfferingDB.UpdateActive(offering_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();
        }

        if (e.CommandName.Equals("SetAsBookingScreenDefaultService"))
        {
            int offering_id = Convert.ToInt32(e.CommandArgument);
            SystemVariableDB.Update("BookingScreenDefaultServiceID", offering_id.ToString());
            FillGrid();
        }
    }
Exemplo n.º 2
0
    private void LogIn(string login, string pwd)
    {
        try
        {
            Session.Remove("DB");
            if (Convert.ToBoolean(ConfigurationManager.AppSettings["UseConfigDB"]))
            {
                Session["DB"] = ConfigurationManager.AppSettings["Database"];
            }
            else // Get DB from Mediclinic_Main
            {
                UserDatabaseMapper user = UserDatabaseMapperDB.GetByLogin(login);
                if (user == null)
                {
                    this.FailureText.Text = "<div class=\"alert alert-danger\" runat=\"server\"><strong>Login Failed.</strong> Please ensure that your username and password are correct and try again.</div>";
                    return;
                }

                Session["DB"] = user.DBName;
            }



            Staff   staff              = StaffDB.GetByLogin(login);
            Patient patient            = PatientDB.GetByLogin(login);
            bool    allowPatientLogins = Convert.ToInt32(SystemVariableDB.GetByDescr("AllowPatientLogins").Value) == 1;
            bool    validStaff         = staff != null && staff.Pwd == pwd && !staff.IsFired;
            bool    validPatient       = allowPatientLogins && patient != null && patient.Pwd == pwd && !patient.IsDeleted;

            if (validStaff)
            {
                UserLogin curLogin = UserLoginDB.GetCurLoggedIn(staff.StaffID, -1, HttpContext.Current.Session.SessionID, -1);
                if (curLogin != null)
                {
                    UserLoginDB.UpdateLastAccessTime(curLogin.UserloginID, DateTime.Now, Request.RawUrl);
                    UserLoginDB.UpdateSetOtherSessionsOfThisUserLoggedOut(curLogin.UserloginID, staff.StaffID, -1);
                }
                else
                {
                    UserLoginDB.UpdateSetAllSessionsLoggedOut(staff.StaffID, -1);
                    UserLoginDB.Insert((staff == null) ? -1 : staff.StaffID, -1, login, -1, validStaff, HttpContext.Current.Session.SessionID, Request.UserHostAddress);
                }


                this.FailureText.Text = "";

                Session["IsLoggedIn"]    = true;
                Session["IsStakeholder"] = staff.IsStakeholder;
                Session["IsMasterAdmin"] = staff.IsMasterAdmin;
                Session["IsAdmin"]       = staff.IsAdmin;
                Session["IsPrincipal"]   = staff.IsPrincipal;
                Session["IsProvider"]    = staff.IsProvider;
                Session["IsExternal"]    = staff.IsExternal;
                Session["StaffID"]       = staff.StaffID;
                Session["StaffFullnameWithoutMiddlename"] = staff.Person.FullnameWithoutMiddlename;
                Session["StaffFirstname"] = staff.Person.Firstname;
                Session["NumDaysToDisplayOnBookingScreen"] = staff.NumDaysToDisplayOnBookingScreen;
                Session["HideBookingNotes"] = staff.HideBookingNotes;
                Session["ShowOtherProvidersOnBookingScreen"] = false;
                Session["ShowHeaderOnBookingScreen"]         = staff.ShowHeaderOnBookingScreen;
                Session["SystemVariables"] = SystemVariableDB.GetAll();
                Session["OfferingColors"]  = OfferingDB.GetColorCodes();
                System.Web.Security.FormsAuthentication.SetAuthCookie("--", true);  // needed to use forms authentication


                UserView userView = UserView.GetInstance();

                Site[] allowedSites = StaffSiteRestrictionDB.GetSitesNotRestricted(staff.StaffID, -1, false);


                //
                // until aged care is running, remove aged care from display
                //

                /*
                 * System.Collections.ArrayList list = new System.Collections.ArrayList();
                 * for (int i = 0; i < allowedSites.Length; i++)
                 *  if (allowedSites[i].SiteType.ID == 1 || Utilities.IsDev())
                 *      list.Add(allowedSites[i]);
                 * allowedSites = (Site[])list.ToArray(typeof(Site));
                 */

                Site[] allSites = SiteDB.GetAll();
                if (allowedSites.Length == 0 && allSites.Length == 1)
                {
                    Session["SiteID"]          = allSites[0].SiteID;
                    Session["SiteName"]        = allSites[0].Name;
                    Session["IsMultipleSites"] = false;
                    Session["SiteIsClinic"]    = allSites[0].SiteType.ID == 1;
                    Session["SiteIsAgedCare"]  = allSites[0].SiteType.ID == 2;
                    Session["SiteIsGP"]        = allSites[0].SiteType.ID == 3;
                    Session["SiteTypeID"]      = allSites[0].SiteType.ID;
                    Session["SiteTypeDescr"]   = allSites[0].SiteType.Descr;

                    UserLoginDB.UpdateSite(staff.StaffID, -1, allSites[0].SiteID);

                    if (!userView.IsAdminView)        // need to choose org
                    {
                        if (Session["OrgID"] == null) // providers need to select an org, need to choose one
                        {
                            Response.Redirect("~/Account/SelectOrgV2.aspx" + GetUrlCarryOverParams(), false);
                            return;
                        }
                    }
                }



                if (allowedSites.Length == 1)
                {
                    Session["SiteID"]          = allowedSites[0].SiteID;
                    Session["SiteName"]        = allowedSites[0].Name;
                    Session["IsMultipleSites"] = false;
                    Session["SiteIsClinic"]    = allowedSites[0].SiteType.ID == 1;
                    Session["SiteIsAgedCare"]  = allowedSites[0].SiteType.ID == 2;
                    Session["SiteIsGP"]        = allowedSites[0].SiteType.ID == 3;
                    Session["SiteTypeID"]      = allowedSites[0].SiteType.ID;
                    Session["SiteTypeDescr"]   = allowedSites[0].SiteType.Descr;

                    UserLoginDB.UpdateSite(staff.StaffID, -1, allowedSites[0].SiteID);

                    if (!userView.IsAdminView)        // need to choose org
                    {
                        if (Session["OrgID"] == null) // providers need to select an org, need to choose one
                        {
                            Response.Redirect("~/Account/SelectOrgV2.aspx" + GetUrlCarryOverParams(), false);
                            return;
                        }
                    }
                }
                else // if more than one site, go to choose. if no sites this page will say to contact admin
                {
                    if (Session["SiteID"] == null)  // admins if yet to login to a site, need to choose one
                    {
                        Session["IsMultipleSites"] = true;
                        Response.Redirect("~/Account/SelectSiteV2.aspx" + GetUrlCarryOverParams(), false);
                        return;
                    }
                }



                /*
                 *
                 * if (!staff.IsAdmin)
                 * {
                 *  // provs only login to clinic site
                 *  Site site = SiteDB.GetByID(2);
                 *  Session["SiteID"]   = site.SiteID;
                 *  Session["SiteName"] = site.Name;
                 *
                 *  if (Session["OrgID"] == null)  // providers et to login to select an org, need to choose one
                 *  {
                 *      if (Request.QueryString["from_url"] != null)
                 *      {
                 *          Response.Redirect("~/Account/SelectOrgV2.aspx?" + Request.RawUrl.Substring(Request.RawUrl.IndexOf("from_url=")), false);
                 *          return;
                 *      }
                 *      else
                 *      {
                 *          Response.Redirect("~/Account/SelectOrgV2.aspx", false);
                 *          return;
                 *      }
                 *  }
                 * }
                 * else
                 * {
                 *  if (Session["SiteID"] == null)  // admins if yet to login to a site, need to choose one
                 *  {
                 *      if (Request.QueryString["from_url"] != null)
                 *      {
                 *          Response.Redirect("~/Account/SelectSiteV2.aspx?" + Request.RawUrl.Substring(Request.RawUrl.IndexOf("from_url=")), false);
                 *          return;
                 *      }
                 *      else
                 *      {
                 *          Response.Redirect("~/Account/SelectSiteV2.aspx", false);
                 *          return;
                 *      }
                 *  }
                 * }
                 *
                 */

                if (Request.QueryString["from_url"] != null)
                {
                    Response.Redirect(Server.UrlDecode(Request.RawUrl.Substring(Request.RawUrl.IndexOf("from_url=") + 9)), false);
                    return;
                }
                else
                {
                    Response.Redirect(Convert.ToInt32(Session["StaffID"]) >= 0 ? "~/Default.aspx" : "~/StaffLoginsV2.aspx", false);
                    return;
                }
            }
            else if (validPatient)
            {
                UserLogin curLogin = UserLoginDB.GetCurLoggedIn(-1, patient.PatientID, HttpContext.Current.Session.SessionID, -1);
                if (curLogin != null)
                {
                    UserLoginDB.UpdateLastAccessTime(curLogin.UserloginID, DateTime.Now, Request.RawUrl);
                    UserLoginDB.UpdateSetOtherSessionsOfThisUserLoggedOut(curLogin.UserloginID, -1, patient.PatientID);
                }
                else
                {
                    UserLoginDB.UpdateSetAllSessionsLoggedOut(-1, patient.PatientID);
                    UserLoginDB.Insert(-1, (patient == null) ? -1 : patient.PatientID, login, -1, validPatient, HttpContext.Current.Session.SessionID, Request.UserHostAddress);
                }


                this.FailureText.Text = "";

                Session["IsLoggedIn"]    = true;
                Session["IsStakeholder"] = false;
                Session["IsMasterAdmin"] = false;
                Session["IsAdmin"]       = false;
                Session["IsPrincipal"]   = false;
                Session["IsProvider"]    = false;
                Session["IsExternal"]    = false;
                Session["PatientID"]     = patient.PatientID;
                Session["StaffFullnameWithoutMiddlename"] = patient.Person.FullnameWithoutMiddlename;
                Session["StaffFirstname"] = patient.Person.Firstname;
                Session["NumDaysToDisplayOnBookingScreen"]   = 3;
                Session["ShowOtherProvidersOnBookingScreen"] = false;
                Session["ShowHeaderOnBookingScreen"]         = true;
                Session["SystemVariables"] = SystemVariableDB.GetAll();
                Session["OfferingColors"]  = OfferingDB.GetColorCodes();
                System.Web.Security.FormsAuthentication.SetAuthCookie("--", true);  // needed to use forms authentication


                Site[] allSites     = SiteDB.GetAll();
                Site[] allowedSites = SiteDB.GetAll();


                //
                // remove aged care from display
                //
                System.Collections.ArrayList list = new System.Collections.ArrayList();
                for (int i = 0; i < allSites.Length; i++)
                {
                    if (allSites[i].SiteType.ID == 1)
                    {
                        list.Add(allSites[i]);
                    }
                }
                allowedSites = (Site[])list.ToArray(typeof(Site));

                if (allowedSites.Length == 0 && allSites.Length == 1)
                {
                    Session["SiteID"]         = allSites[0].SiteID;
                    Session["SiteName"]       = allSites[0].Name;
                    Session["SiteIsClinic"]   = allSites[0].SiteType.ID == 1;
                    Session["SiteIsAgedCare"] = allSites[0].SiteType.ID == 2;
                    Session["SiteIsGP"]       = allSites[0].SiteType.ID == 3;
                    Session["SiteTypeID"]     = allSites[0].SiteType.ID;
                    Session["SiteTypeDescr"]  = allSites[0].SiteType.Descr;


                    UserLoginDB.UpdateSite(-1, patient.PatientID, allSites[0].SiteID);

                    if (Session["OrgID"] == null)  // providers, ext staff, patient logins need to select an org, need to choose one
                    {
                        if (Request.QueryString["from_url"] != null)
                        {
                            string from_url = Server.UrlDecode(Request.RawUrl.Substring(Request.RawUrl.IndexOf("from_url=") + 9));
                            if (from_url.Contains("BookingsV2.aspx?") && from_url.Contains("orgs="))
                            {
                                Uri    theRealURL = new Uri(HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + from_url);
                                string orgs       = HttpUtility.ParseQueryString(theRealURL.Query).Get("orgs");
                                if (Regex.IsMatch(orgs, @"^\d+$"))
                                {
                                    Organisation org = OrganisationDB.GetByID(Convert.ToInt32(orgs));
                                    if (org != null)
                                    {
                                        Session["OrgID"]   = org.OrganisationID.ToString();
                                        Session["OrgName"] = org.Name;
                                        Response.Redirect(from_url, false);
                                        return;
                                    }
                                }
                            }
                        }


                        Response.Redirect("~/Account/SelectOrgV2.aspx" + GetUrlCarryOverParams(), false);
                        return;
                    }
                }

                if (allowedSites.Length == 1)
                {
                    Session["SiteID"]         = allowedSites[0].SiteID;
                    Session["SiteName"]       = allowedSites[0].Name;
                    Session["SiteIsClinic"]   = allowedSites[0].SiteType.ID == 1;
                    Session["SiteIsAgedCare"] = allowedSites[0].SiteType.ID == 2;
                    Session["SiteIsGP"]       = allowedSites[0].SiteType.ID == 3;
                    Session["SiteTypeID"]     = allowedSites[0].SiteType.ID;
                    Session["SiteTypeDescr"]  = allowedSites[0].SiteType.Descr;

                    UserLoginDB.UpdateSite(-1, patient.PatientID, allowedSites[0].SiteID);

                    if (Session["OrgID"] == null)  // providers need to select an org, need to choose one
                    {
                        if (Request.QueryString["from_url"] != null)
                        {
                            string from_url = Server.UrlDecode(Request.RawUrl.Substring(Request.RawUrl.IndexOf("from_url=") + 9));
                            if (from_url.Contains("BookingsV2.aspx?") && from_url.Contains("orgs="))
                            {
                                Uri    theRealURL = new Uri(HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + from_url);
                                string orgs       = HttpUtility.ParseQueryString(theRealURL.Query).Get("orgs");
                                if (Regex.IsMatch(orgs, @"^\d+$"))
                                {
                                    Organisation org = OrganisationDB.GetByID(Convert.ToInt32(orgs));
                                    if (org != null)
                                    {
                                        Session["OrgID"]   = org.OrganisationID.ToString();
                                        Session["OrgName"] = org.Name;
                                        Response.Redirect(from_url, false);
                                        return;
                                    }
                                }
                            }
                        }

                        Response.Redirect("~/Account/SelectOrgV2.aspx" + GetUrlCarryOverParams(), false);
                        return;
                    }
                }
                else // if more than one site, go to choose. if no sites this page will say to contact admin
                {
                    if (Session["SiteID"] == null)  // admins if yet to login to a site, need to choose one
                    {
                        Response.Redirect("~/Account/SelectSiteV2.aspx" + GetUrlCarryOverParams(), false);
                        return;
                    }
                }


                if (Request.QueryString["from_url"] != null)
                {
                    Response.Redirect(Server.UrlDecode(Request.RawUrl.Substring(Request.RawUrl.IndexOf("from_url=") + 9)), false);
                    return;
                }
                else
                {
                    Response.Redirect(Convert.ToInt32(Session["StaffID"]) >= 0 ? "~/Default.aspx" : "~/StaffLoginsV2.aspx", false);
                    return;
                }
            }

            else
            {
                //UserLoginDB.Insert((staff == null) ? -1 : staff.StaffID, login, -1, validStaff, HttpContext.Current.Session.SessionID, Request.UserHostAddress);
                this.FailureText.Text = "Login Failed.";
            }
        }
        catch (Exception ex)
        {
            Logger.LogException(ex);
            if (Utilities.IsDev())
            {
                FailureText.Text = ex.ToString();
            }
            else
            {
                throw;
            }
        }
    }
    protected void GrdOffering_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Label        lblId           = (Label)GrdOffering.Rows[e.RowIndex].FindControl("lblId");
        TextBox      txtName         = (TextBox)GrdOffering.Rows[e.RowIndex].FindControl("txtName");
        TextBox      txtShortName    = (TextBox)GrdOffering.Rows[e.RowIndex].FindControl("txtShortName");
        TextBox      txtDescr        = (TextBox)GrdOffering.Rows[e.RowIndex].FindControl("txtDescr");
        DropDownList ddlOfferingType = (DropDownList)GrdOffering.Rows[e.RowIndex].FindControl("ddlOfferingType");
        DropDownList ddlField        = (DropDownList)GrdOffering.Rows[e.RowIndex].FindControl("ddlField");
        DropDownList ddlOfferingPatientSubcategory    = (DropDownList)GrdOffering.Rows[e.RowIndex].FindControl("ddlOfferingPatientSubcategory");
        DropDownList ddlNumClinicVisitsAllowedPerYear = (DropDownList)GrdOffering.Rows[e.RowIndex].FindControl("ddlNumClinicVisitsAllowedPerYear");
        DropDownList ddlOfferingInvoiceType           = (DropDownList)GrdOffering.Rows[e.RowIndex].FindControl("ddlOfferingInvoiceType");
        CheckBox     chkIsGstExempt                     = (CheckBox)GrdOffering.Rows[e.RowIndex].FindControl("chkIsGstExempt");
        TextBox      txtDefaultPrice                    = (TextBox)GrdOffering.Rows[e.RowIndex].FindControl("txtDefaultPrice");
        DropDownList ddlServiceTimeMinutes              = (DropDownList)GrdOffering.Rows[e.RowIndex].FindControl("ddlServiceTimeMinutes");
        DropDownList ddlMaxNbrClaimable                 = (DropDownList)GrdOffering.Rows[e.RowIndex].FindControl("ddlMaxNbrClaimable");
        DropDownList ddlMaxNbrClaimableMonths           = (DropDownList)GrdOffering.Rows[e.RowIndex].FindControl("ddlMaxNbrClaimableMonths");
        TextBox      txtMedicareCompanyCode             = (TextBox)GrdOffering.Rows[e.RowIndex].FindControl("txtMedicareCompanyCode");
        TextBox      txtDvaCompanyCode                  = (TextBox)GrdOffering.Rows[e.RowIndex].FindControl("txtDvaCompanyCode");
        TextBox      txtTacCompanyCode                  = (TextBox)GrdOffering.Rows[e.RowIndex].FindControl("txtTacCompanyCode");
        TextBox      txtMedicareCharge                  = (TextBox)GrdOffering.Rows[e.RowIndex].FindControl("txtMedicareCharge");
        TextBox      txtDvaCharge                       = (TextBox)GrdOffering.Rows[e.RowIndex].FindControl("txtDvaCharge");
        TextBox      txtTacCharge                       = (TextBox)GrdOffering.Rows[e.RowIndex].FindControl("txtTacCharge");
        DropDownList ddlReminderLetterMonthsLaterToSend = (DropDownList)GrdOffering.Rows[e.RowIndex].FindControl("ddlReminderLetterMonthsLaterToSend");
        DropDownList ddlReminderLetter                  = (DropDownList)GrdOffering.Rows[e.RowIndex].FindControl("ddlReminderLetter");

        CheckBox chkUseCustomColour = (CheckBox)GrdOffering.Rows[e.RowIndex].FindControl("chkUseCustomColour");

        System.Web.UI.HtmlControls.HtmlInputText ColorPicker = (System.Web.UI.HtmlControls.HtmlInputText)GrdOffering.Rows[e.RowIndex].FindControl("ColorPicker");


        if (Convert.ToInt32(ddlReminderLetterMonthsLaterToSend.SelectedValue) > 0 && Convert.ToInt32(ddlReminderLetter.SelectedValue) == -1)
        {
            SetErrorMessage("For reminder letters - you must either set the number of months as disabled or select a reminder letter.");
            return;
        }

        Offering offering = OfferingDB.GetByID(Convert.ToInt32(lblId.Text));

        // if logged not AC system, set as was
        // if logged not Clinic system, set as was
        // these are hidden in the gui also in method 'GrdOffering_RowCreated'
        int offeringPatientSubcategoryID = !UserView.GetInstance().IsAgedCareView ? offering.AgedCarePatientType.ID : Convert.ToInt32(ddlOfferingPatientSubcategory.SelectedValue);

        OfferingDB.Update(Convert.ToInt32(lblId.Text),
                          Convert.ToInt32(ddlOfferingType.SelectedValue), Convert.ToInt32(ddlField.SelectedValue),
                          offeringPatientSubcategoryID,
                          Convert.ToInt32(ddlNumClinicVisitsAllowedPerYear.SelectedValue),
                          Convert.ToInt32(ddlOfferingInvoiceType.SelectedValue),
                          txtName.Text, txtShortName.Text, txtDescr.Text,
                          chkIsGstExempt.Checked, Convert.ToDecimal(txtDefaultPrice.Text), Convert.ToInt32(ddlServiceTimeMinutes.Text),
                          Convert.ToInt32(ddlMaxNbrClaimable.SelectedValue), Convert.ToInt32(ddlMaxNbrClaimableMonths.SelectedValue),
                          txtMedicareCompanyCode.Text.Trim(), txtDvaCompanyCode.Text.Trim(), txtTacCompanyCode.Text.Trim(),
                          Convert.ToDecimal(txtMedicareCharge.Text), Convert.ToDecimal(txtDvaCharge.Text), Convert.ToDecimal(txtTacCharge.Text), offering.PopupMessage,
                          Convert.ToInt32(ddlReminderLetterMonthsLaterToSend.SelectedValue),
                          Convert.ToInt32(ddlReminderLetter.SelectedValue),
                          chkUseCustomColour.Checked,
                          ColorPicker.Value
                          );

        Session["OfferingColors"] = OfferingDB.GetColorCodes();

        GrdOffering.EditIndex = -1;
        FillGrid();
    }