protected void DeleteButton_Click(object sender, EventArgs e)
        {
            StaffingData staffingData = new StaffingData();

            staffingData.WardCode     = WardName_DropDownList.SelectedItem.Value;
            staffingData.Shift        = Shift_DropDownList.SelectedItem.Text;
            staffingData.StaffingDate = Day_DropDownList.SelectedItem.Value;

            int staffingPeriodIndex = 0;

            int.TryParse(DatePeriodRange_DropDownList.SelectedItem.Value, out staffingPeriodIndex);

            if (staffingPeriodIndex > 0)
            {
                staffingData.StaffingDateRangeIndex = staffingPeriodIndex;

                if (staffingDataDA.DeleteStaffingData(staffingData))
                {
                    DisplayMessage(true, "Record Deleted");
                    ClearFields();
                }
                else
                {
                    DisplayMessage(false, "Record Not Deleted");
                }
            }
            else
            {
                DisplayMessage(false, "Staffing index is invalid");
            }
        }
        public bool DeleteStaffingData(StaffingData record)
        {
            bool isSuccessful = false;

            using (SqlConnection con = GetConnection())
            {
                con.Open();

                SqlCommand command = new SqlCommand("DeleteStaffing", con);
                command.CommandType = CommandType.StoredProcedure;

                SqlParameter WardCode          = GetParameter("@WardCode", SqlDbType.VarChar, record.WardCode);
                SqlParameter Shift             = GetParameter("@Shift", SqlDbType.VarChar, record.Shift);
                SqlParameter Day               = GetParameter("@Day", SqlDbType.VarChar, record.StaffingDate);
                SqlParameter StaffingDateIndex = GetParameter("@StaffingDateIndex", SqlDbType.Int, record.StaffingDateRangeIndex);

                command.Parameters.Add(WardCode);
                command.Parameters.Add(Shift);
                command.Parameters.Add(Day);
                command.Parameters.Add(StaffingDateIndex);

                var results = command.ExecuteNonQuery();

                if (results > 0)
                {
                    isSuccessful = true;
                }

                return(isSuccessful);
            }
        }
        public bool AddOrUpdateStaffingData(StaffingData record, string sp)
        {
            bool isSuccess = false;

            using (SqlConnection con = GetConnection())
            {
                con.Open();

                SqlCommand command = new SqlCommand(sp, con);
                command.CommandType = CommandType.StoredProcedure;

                SqlParameter WardCode               = GetParameter("@WardCode", SqlDbType.VarChar, record.WardCode);
                SqlParameter Shift                  = GetParameter("@Shift", SqlDbType.VarChar, record.Shift);
                SqlParameter StaffingDate           = GetParameter("@Day", SqlDbType.VarChar, record.StaffingDate);
                SqlParameter Beds                   = GetParameter("@Beds", SqlDbType.Int, record.Beds);
                SqlParameter OptimumHCA             = GetParameter("@OptimumStaffingHCA", SqlDbType.Int, record.OptimumHCA);
                SqlParameter OptimumRN              = GetParameter("@OptimumStaffingRN", SqlDbType.Int, record.OptimumRN);
                SqlParameter SafeHCA                = GetParameter("@SafeStaffingHCA", SqlDbType.Int, record.SafeHCA);
                SqlParameter SafeRN                 = GetParameter("@SafeStaffingRN", SqlDbType.Int, record.SafeRN);
                SqlParameter StaffingDateRangeIndex = GetParameter("@StaffingDateIndex", SqlDbType.Int, record.StaffingDateRangeIndex);

                command.Parameters.Add(WardCode);
                command.Parameters.Add(Shift);
                command.Parameters.Add(StaffingDate);
                command.Parameters.Add(Beds);
                command.Parameters.Add(OptimumHCA);
                command.Parameters.Add(OptimumRN);
                command.Parameters.Add(SafeHCA);
                command.Parameters.Add(SafeRN);
                command.Parameters.Add(StaffingDateRangeIndex);

                var results = command.ExecuteNonQuery();

                if (results > 0)
                {
                    isSuccess = true;
                }
            }

            return(isSuccess);
        }
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            bool         executionStatus = false;
            StaffingData staffingData    = new StaffingData();

            staffingData.WardCode     = WardName_DropDownList.SelectedItem.Value;
            staffingData.Shift        = Shift_DropDownList.SelectedItem.Text;
            staffingData.StaffingDate = Day_DropDownList.SelectedItem.Text;

            //Shift ID
            int shid;

            int.TryParse(Shift_DropDownList.SelectedItem.Value, out shid);
            staffingData.ShiftID = shid;

            //Staffing date range index
            int sdri;

            int.TryParse(DatePeriodRange_DropDownList.SelectedItem.Value, out sdri);
            staffingData.StaffingDateRangeIndex = sdri;

            //Beds
            int beds;

            int.TryParse(Beds_TextBox.Text, out beds);
            staffingData.Beds = beds;

            //RN Optimum Staffing
            int rnos;

            int.TryParse(RN_OptimumStaffing_TextBox.Text, out rnos);
            staffingData.OptimumRN = rnos;

            //HCA Optimum Staffing
            int hcaos;

            int.TryParse(HCA_OptimumStaffing_TextBox.Text, out hcaos);
            staffingData.OptimumHCA = hcaos;

            //RN Safe Staffing
            int rnss;

            int.TryParse(RN_SafeStaffing_TextBox.Text, out rnss);
            staffingData.SafeRN = rnss;

            //HCA Safe Staffing
            int hcass;

            int.TryParse(HCA_SafeStaffing_TextBox.Text, out hcass);
            staffingData.SafeHCA = hcass;

            if (StaffingDataEntryFound_HiddenField.Text.Equals("true"))
            {
                //update
                executionStatus = staffingDataDA.UpdateStaffingData(staffingData);
            }
            else
            {
                //add
                executionStatus = staffingDataDA.AddStaffingData(staffingData);
            }

            //Refresh the existing DB instance
            if (executionStatus)
            {
                DataRepository.Instance.RefreshStaffingData();
            }

            DisplayMessage(executionStatus);
        }
        public List <StaffingData> GetAllStaffing()
        {
            List <StaffingData> allWards = new List <StaffingData>();

            using (SqlConnection con = GetConnection())
            {
                con.Open();

                SqlCommand command = new SqlCommand("GetAllStaffing", con);
                command.CommandType = CommandType.StoredProcedure;

                var results = command.ExecuteReader();

                if (results.HasRows)
                {
                    StaffingData             ward;
                    StaffingDateRangeDA      staffingDateRangeDA = new StaffingDateRangeDA();
                    List <StaffingDateRange> staffingDateRanges  = staffingDateRangeDA.GetAllStaffingDateRanges();

                    int tempInt;

                    while (results.Read())
                    {
                        ward              = new StaffingData();
                        ward.WardCode     = results["Ward Code"].ToString();
                        ward.StaffingDate = results["Day"].ToString();
                        ward.Shift        = results["Shift"].ToString();

                        int.TryParse(results["Beds"].ToString(), out tempInt);
                        ward.Beds = tempInt;

                        if (int.TryParse(results["Safe Staffing RN"].ToString(), out tempInt))
                        {
                            ward.SafeRN = tempInt;
                        }
                        if (int.TryParse(results["Safe Staffing HCA"].ToString(), out tempInt))
                        {
                            ward.SafeHCA = tempInt;
                        }
                        if (int.TryParse(results["Optimum Staffing RN"].ToString(), out tempInt))
                        {
                            ward.OptimumRN = tempInt;
                        }
                        if (int.TryParse(results["Optimum Staffing HCA"].ToString(), out tempInt))
                        {
                            ward.OptimumHCA = tempInt;
                        }
                        if (int.TryParse(results["StaffingDateIndex"].ToString(), out tempInt))
                        {
                            ward.StaffingDateRangeIndex = tempInt;

                            var staffingDateRange = (from p in staffingDateRanges
                                                     where p.Index == tempInt
                                                     select p).SingleOrDefault();

                            if (staffingDateRange != null)
                            {
                                ward.PeriodStartDate = staffingDateRange.StartDate;
                                ward.PeriodEndDate   = staffingDateRange.EndDate;
                            }
                        }

                        allWards.Add(ward);
                    }
                }
            }

            return(allWards);
        }
 public bool UpdateStaffingData(StaffingData record)
 {
     return(AddOrUpdateStaffingData(record, "UpdateStaffing"));
 }
 public bool AddStaffingData(StaffingData record)
 {
     return(AddOrUpdateStaffingData(record, "InsertStaffing"));
 }
        private void LoadDataForUpdate()
        {
            string        wardCode = WardName_DropDownList.SelectedItem.Value;
            DateTime      currentDate;
            ShiftRecordDA sda;

            //ShiftID
            int shiftID = -1;

            int.TryParse(Shift_DropDownList.SelectedItem.Value, out shiftID);
            DateTime.TryParse(Date_TextBox.Text, out currentDate);

            if (string.IsNullOrWhiteSpace(wardCode) || shiftID < 0 || currentDate == null)
            {
                return;
            }

            sda = new ShiftRecordDA();
            ShiftRecord record = sda.GetShiftRecord(currentDate, wardCode, shiftID);

            if (record.ShiftRecordExists)
            {
                ShiftDataEntryFound_HiddenField.Value = "true";
            }
            else
            {
                ShiftDataEntryFound_HiddenField.Value = "false";
            }

            //Beds
            Beds_TextBox.Text = record.Beds.ToString();
            //OptimumStaffingRN
            RN_OptimumStaffing_TextBox.Text = record.OptimumStaffingRN.ToString();
            //OptimumStaffingHCA
            HCA_OptimumStaffing_TextBox.Text = record.OptimumStaffingHCA.ToString();
            //PlannedNumberRN
            RN_PlannedNumber_TextBox.Text = record.PlannedNumberRN;
            //PlannedNumberHCA
            HCA_PlannedNumber_TextBox.Text = record.PlannedNumberHCA;
            //SafeStaffingRN
            RN_SafeStaffing_TextBox.Text = record.SafeStaffingRN.ToString();
            //SafeStaffingHCA
            HCA_SafeStaffing_TextBox.Text = record.SafeStaffingHCA.ToString();


            //Fix if defualt value is 0, empty string will be displayed.
            //TodayTrustRN
            RN_TodayTrust_TextBox.Text           = record.TodayTrustRN;
            Overrride_RN_TodayTrust_TextBox.Text = record.TodayTrustRN;
            //TodayTrustHCA
            HCA_TodayTrust_TextBox.Text           = record.TodayTrustHCA;
            Overrride_HCA_TodayTrust_TextBox.Text = record.TodayTrustHCA;
            //TodayBankRN
            RN_TodayBank_TextBox.Text           = record.TodayBankRN;
            Overrride_RN_TodayBank_TextBox.Text = record.TodayBankRN;
            //TodayBankHCA
            HCA_TodayBank_TextBox.Text           = record.TodayBankHCA;
            Overrride_HCA_TodayBank_TextBox.Text = record.TodayBankHCA;
            //TodayNonTrustRN
            RN_TodayNonTrust_TextBox.Text           = record.TodayNonTrustRN;
            Overrride_RN_TodayNonTrust_TextBox.Text = record.TodayNonTrustRN;
            //TodayNonTrustHCA
            HCA_TodayNonTrust_TextBox.Text           = record.TodayNonTrustHCA;
            Overrride_HCA_TodayNonTrust_TextBox.Text = record.TodayNonTrustHCA;
            //Comments
            Comments_TextBox.Text = record.Comments;

            if (record.IsSafeAfterMitigation == null)
            {
                //Safe
                if (record.IsSafe)
                {
                    safeDropdown.SelectedIndex = 0;
                    mitigationPanel.Visible    = false;
                }
                else
                {
                    safeDropdown.SelectedIndex = 1;
                    mitigationPanel.Visible    = true;
                }
            }

            //Check if the ward is unsafe and display the staffing adjustment panel
            if (record.IsSafeAfterMitigation == true)
            {
                safeDropdown.SelectedIndex           = 0;
                mitigationPanel.Visible              = false;
                Overrride_safeDropdown.SelectedIndex = 1;
            }
            else if (record.IsSafeAfterMitigation == false)
            {
                safeDropdown.SelectedIndex = 1;
                mitigationPanel.Visible    = true;

                adjustStaffingFiguresPanel.Visible = true;
                adjustStaffingFiguresPanel.Attributes.Add("style", "display: block;");
                fade.Attributes.Add("style", "display: block;");

                Overrride_safeDropdown.SelectedIndex = 0;
            }

            //UnSafeMitigation
            if (UnSafeMitigation_DropDownList.Items.FindByValue(record.UnSafeMitigation) != null)
            {
                UnSafeMitigation_DropDownList.SelectedValue = record.UnSafeMitigation;
            }
            else
            {
                UnSafeMitigation_DropDownList.SelectedIndex = 0;
            }


            string shiftDataEntryFound = ShiftDataEntryFound_HiddenField.Value;

            if (shiftDataEntryFound.Equals("false"))
            {
                //Shift Name
                string shiftName = Shift_DropDownList.SelectedItem.Text;

                //ShiftRecord record = sda.GetShiftRecord(date, wardCode, shiftID);
                StaffingData         staffingDataRecord = new StaffingData();
                IList <StaffingData> allStaffing        = DataRepository.Instance.AllStaffing;

                StaffingDateRangeDA      staffingDateRangeDA = new StaffingDateRangeDA();
                List <StaffingDateRange> staffingDateRange   = new List <StaffingDateRange>();
                staffingDateRange = staffingDateRangeDA.GetAllStaffingDateRanges();

                // This is the logic that loads the optimum/safe staffing values according to the current date

                int        currentDatePeriodIndex  = 0;
                List <int> currentDatePeriodIndexs = new List <int>();

                //foreach (StaffingDateRange item in staffingDateRange)
                //{
                //    if (IsCurrentDateInSpecifiedDatePeriod(currentDate, item.StartDate, item.EndDate))
                //    {
                //        currentDatePeriodIndex = item.Index;
                //        break;
                //    }
                //}

                //Support for multiple periods
                foreach (StaffingDateRange item in staffingDateRange)
                {
                    if (IsCurrentDateInSpecifiedDatePeriod(currentDate, item.StartDate, item.EndDate))
                    {
                        currentDatePeriodIndexs.Add(item.Index);
                    }
                }

                foreach (StaffingData item in allStaffing)
                {
                    foreach (int period in currentDatePeriodIndexs)
                    {
                        if (item.StaffingDateRangeIndex == period && wardCode.Equals(item.WardCode) && shiftName.Equals(item.Shift) && item.StaffingDate == currentDate.ToString("dddd"))
                        {
                            staffingDataRecord = item;
                            break;
                        }
                    }
                }

                //Beds
                Beds_TextBox.Text = staffingDataRecord.Beds.ToString();
                //OptimumStaffingRN
                RN_OptimumStaffing_TextBox.Text = staffingDataRecord.OptimumRN.ToString();
                //OptimumStaffingHCA
                HCA_OptimumStaffing_TextBox.Text = staffingDataRecord.OptimumHCA.ToString();
                //SafeStaffingRN
                RN_SafeStaffing_TextBox.Text = staffingDataRecord.SafeRN.ToString();
                //SafeStaffingHCA
                HCA_SafeStaffing_TextBox.Text = staffingDataRecord.SafeHCA.ToString();
            }

            SetEntryAreaBckground();
        }