private void BindDropDownCallCycleByFilter() { foreach (GridViewRow gridViewRow in GridViewResult.Rows) { HiddenField hiddenFieldStoreCallCycleId = (HiddenField)gridViewRow.Cells[11].FindControl("HiddenFieldStoreCallCycleId"); DropDownList dropDownListCallCycle = (DropDownList)gridViewRow.Cells[2].FindControl("DropDownListCallCycle"); StoreCallCycle storeCallCycle = StoreCallCycle.GetStoreCallCycleByStoreCallCycleId(Convert.ToInt32(hiddenFieldStoreCallCycleId.Value)); dropDownListCallCycle.Items.FindByValue(storeCallCycle.CallCycleId.ToString()).Selected = true; } }
private void BindStoreCallCycle() { GridViewResult.DataSource = StoreCallCycle.GetStoreCallCycleByRepresentativeStoreId(this.repStoreId); GridViewResult.DataBind(); if (GridViewResult.Rows.Count > 0) { ButtonSaveList.Visible = true; //BindCallCycleByFilter(); BindDropDownCallCycleByFilter(); BindCallCycleByFilter(); } else { ButtonSaveList.Visible = false; LabelError.Text = "No records returned."; PanelError.Visible = true; } }
private void BindCallCycleByFilter() { foreach (GridViewRow gridViewRow in GridViewResult.Rows) { HiddenField hiddenFieldStoreCallCycleId = (HiddenField)gridViewRow.Cells[11].FindControl("HiddenFieldStoreCallCycleId"); DropDownList dropDownListCallCycle = (DropDownList)gridViewRow.Cells[3].FindControl("DropDownListCallCycle"); StoreCallCycle storeCallCycle = StoreCallCycle.GetStoreCallCycleByStoreCallCycleId(Convert.ToInt32(hiddenFieldStoreCallCycleId.Value)); dropDownListCallCycle.Items.FindByValue(storeCallCycle.CallCycleId.ToString()).Selected = true; if (dropDownListCallCycle.SelectedItem.Text.ToLower() == "week days") { RuleWeekDay(gridViewRow.RowIndex); } if (dropDownListCallCycle.SelectedItem.Text.ToLower() == "week end only") { RuleWeekEnd(gridViewRow.RowIndex); } if (dropDownListCallCycle.SelectedItem.Text.ToLower() == "daily") { RuleDaily(gridViewRow.RowIndex); } //if (dropDownListCallCycle.SelectedItem.Text.ToLower() == "#days per week") //{ // RuleDaysPerWeek(gridViewRow.RowIndex); //} //if (dropDownListCallCycle.SelectedItem.Text.ToLower() == "fortnightly") //{ // RuleFortnightly(gridViewRow.RowIndex); //} //if (dropDownListCallCycle.SelectedItem.Text.ToLower() == "monthly") //{ // RuleMonthly(gridViewRow.RowIndex); //} } }
protected void ButtonSave_Click(object sender, EventArgs e) { if (Page.IsValid) { try { LabelError.Text = ""; bool hasError = false; foreach (GridViewRow gridViewRow in GridViewResult.Rows) { HiddenField hiddenFieldStoreCallCycleId = (HiddenField)gridViewRow.Cells[11].FindControl("HiddenFieldStoreCallCycleId"); CheckBox checkBoxStoreCallCycleLink = (CheckBox)gridViewRow.Cells[1].FindControl("CheckBoxLink"); DropDownList dropDownListCallCycle = (DropDownList)gridViewRow.Cells[2].FindControl("DropDownListCallCycle"); //Store Call Cycle = 0 which is no entry and not selected to link if ((Convert.ToInt32(hiddenFieldStoreCallCycleId.Value) == 0) && (!checkBoxStoreCallCycleLink.Checked)) { //Do Nothing } //Store Call Cycle > 0 which is entry exist and not selected to link if ((Convert.ToInt32(hiddenFieldStoreCallCycleId.Value) > 0) && (!checkBoxStoreCallCycleLink.Checked)) { //Delete StoreCallCycle.DeleteStoreCallCycleByStoreCallCycleId(Convert.ToInt32(hiddenFieldStoreCallCycleId.Value)); } //Store Call Cycle = 0 which is no entry and selected to link OR //Store Call Cycle > 0 which is entry exist and selected to link if (((Convert.ToInt32(hiddenFieldStoreCallCycleId.Value) == 0) && (checkBoxStoreCallCycleLink.Checked)) || ((Convert.ToInt32(hiddenFieldStoreCallCycleId.Value) > 0) && (checkBoxStoreCallCycleLink.Checked))) { //Insert OR Update CheckBox checkBoxDay1 = (CheckBox)gridViewRow.Cells[3].FindControl("CheckBoxDay1"); CheckBox checkBoxDay2 = (CheckBox)gridViewRow.Cells[4].FindControl("CheckBoxDay2"); CheckBox checkBoxDay3 = (CheckBox)gridViewRow.Cells[5].FindControl("CheckBoxDay3"); CheckBox checkBoxDay4 = (CheckBox)gridViewRow.Cells[6].FindControl("CheckBoxDay4"); CheckBox checkBoxDay5 = (CheckBox)gridViewRow.Cells[7].FindControl("CheckBoxDay5"); CheckBox checkBoxDay6 = (CheckBox)gridViewRow.Cells[8].FindControl("CheckBoxDay6"); CheckBox checkBoxDay7 = (CheckBox)gridViewRow.Cells[9].FindControl("CheckBoxDay7"); if (checkBoxDay1.Checked || checkBoxDay2.Checked || checkBoxDay3.Checked || checkBoxDay4.Checked || checkBoxDay5.Checked || checkBoxDay6.Checked || checkBoxDay7.Checked) { if (dropDownListCallCycle.SelectedValue == "0") { LabelError.Text += "Call Cycle is required. <br />"; PanelError.Visible = true; hasError = true; } } if (dropDownListCallCycle.SelectedItem.Text.ToLower() == "week days") { if (!checkBoxDay1.Checked && !checkBoxDay2.Checked && !checkBoxDay3.Checked && !checkBoxDay4.Checked && !checkBoxDay5.Checked) { LabelError.Text += "Please select at least one day for Call Cycle - Week Days. <br />"; PanelError.Visible = true; hasError = true; } } if (dropDownListCallCycle.SelectedItem.Text.ToLower() == "week end only") { if (!checkBoxDay6.Checked && !checkBoxDay7.Checked) { LabelError.Text += "Please select at least one day for Call Cycle - Week End Only. <br />"; PanelError.Visible = true; hasError = true; } } if (dropDownListCallCycle.SelectedItem.Text.ToLower() == "daily") { if (!checkBoxDay1.Checked && !checkBoxDay2.Checked && !checkBoxDay3.Checked && !checkBoxDay4.Checked && !checkBoxDay5.Checked && !checkBoxDay6.Checked && !checkBoxDay7.Checked) { LabelError.Text += "Please select at least one day for Call Cycle - Daily. <br />"; PanelError.Visible = true; hasError = true; } } if (dropDownListCallCycle.SelectedItem.Text.ToLower() == "half day") { if (!checkBoxDay1.Checked && !checkBoxDay2.Checked && !checkBoxDay3.Checked && !checkBoxDay4.Checked && !checkBoxDay5.Checked && !checkBoxDay6.Checked && !checkBoxDay7.Checked) { LabelError.Text += "Please select at least one day for Call Cycle - Half Day. <br />"; PanelError.Visible = true; hasError = true; } } if (dropDownListCallCycle.SelectedItem.Text.ToLower() == "#days per week") { if (!checkBoxDay1.Checked && !checkBoxDay2.Checked && !checkBoxDay3.Checked && !checkBoxDay4.Checked && !checkBoxDay5.Checked && !checkBoxDay6.Checked && !checkBoxDay7.Checked) { LabelError.Text += "Please select at least one day for Call Cycle - #Days Per Week. <br />"; PanelError.Visible = true; hasError = true; } if (checkBoxDay1.Checked && checkBoxDay2.Checked && checkBoxDay3.Checked && checkBoxDay4.Checked && checkBoxDay5.Checked && checkBoxDay6.Checked && checkBoxDay7.Checked) { LabelError.Text += "Please select a max of 6 days for Call Cycle - #Days Per Week. <br />"; PanelError.Visible = true; hasError = true; } } if (hasError == false) { HiddenField hiddenFieldRepStoreId = (HiddenField)gridViewRow.Cells[10].FindControl("HiddenFieldRepStoreId"); HiddenField hiddenFieldWeekNumber = (HiddenField)gridViewRow.Cells[12].FindControl("HiddenFieldWeekNumber"); StoreCallCycle storeCallCycle = new StoreCallCycle(); storeCallCycle.StoreCallCycleId = Convert.ToInt32(hiddenFieldStoreCallCycleId.Value); storeCallCycle.RepStoreId = Convert.ToInt32(hiddenFieldRepStoreId.Value); storeCallCycle.WeekNumber = Convert.ToInt32(hiddenFieldWeekNumber.Value); storeCallCycle.ModifiedUser = this.Master.LoggedOnAccount; storeCallCycle.CallCycleId = Convert.ToInt32(dropDownListCallCycle.SelectedValue); storeCallCycle.Day1 = (checkBoxDay1.Checked == true ? 1 : 0); storeCallCycle.Day2 = (checkBoxDay2.Checked == true ? 1 : 0); storeCallCycle.Day3 = (checkBoxDay3.Checked == true ? 1 : 0); storeCallCycle.Day4 = (checkBoxDay4.Checked == true ? 1 : 0); storeCallCycle.Day5 = (checkBoxDay5.Checked == true ? 1 : 0); storeCallCycle.Day6 = (checkBoxDay6.Checked == true ? 1 : 0); storeCallCycle.Day7 = (checkBoxDay7.Checked == true ? 1 : 0); storeCallCycle.Save(); } } } if (hasError == false) { if (this.employeeId > 0) { Response.Redirect(String.Format("RepStoreEdit.aspx?EmployeeId={0}", this.employeeId)); } else { Response.Redirect(String.Format("RepStoreEditByStore.aspx?StoreId={0}", this.storeId)); } } } catch (System.Data.SqlClient.SqlException sqlEx) { LabelError.Text = ""; for (int i = 0; i < sqlEx.Errors.Count; i++) { LabelError.Text += (sqlEx.Errors[i].Message + "<br />"); } PanelError.Visible = true; } } }