private void switchButton_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Are you sure you want to switch?", "Switch Confirmation", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { int oldid = 0, newid = 0; string oldname = l_NameComboBox.Text, newname = newlnameComboBox.Text; DateTime date = new DateTime(); date = switchDateTimePicker.Value; foreach (DataRow dt in bus449_TestDataSet.Employee.Rows) { string check = ""; check = dt["L_Name"].ToString(); if (oldname == check) { oldid = int.Parse(dt["ID"].ToString()); } if (newname == check) { newid = int.Parse(dt["ID"].ToString()); } } //creates usable adapter Bus449_TestDataSetTableAdapters.Oncall_CalendarTableAdapter oncall = new Bus449_TestDataSetTableAdapters.Oncall_CalendarTableAdapter(); //updates the calendar with the switch foreach (DataRow dr in bus449_TestDataSet.Oncall_Calendar.Rows) { int am = 0, pm = 0; bool holiday = bool.Parse(dr["holiday"].ToString()); string desc = dr["holiday_desc"].ToString(); am = int.Parse(dr["empid_am"].ToString()); pm = int.Parse(dr["empid_pm"].ToString()); if (am == oldid) { oncall.Update(newid, pm, holiday, desc, date, oldid, pm, holiday, desc); } if (pm == oldid) { oncall.Update(am, newid, holiday, desc, date, am, oldid, holiday, desc); } } l_NameComboBox.Text = newname; MessageBox.Show("The switch has been successful"); } }
private void deleteButton_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Are you sure want to delete this employee?", "Delete Confirmation", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { delete = true; delid = int.Parse(iDTextBox.Text); delshift = shiftComboBox.Text; int a = 0, p = 0; int[] empam, emppm; empam = new int[(int)this.employeeTableAdapter.AMCount()]; emppm = new int[(int)this.employeeTableAdapter.PMCount()]; foreach (DataRow dt in bus449_TestDataSet.Employee.Rows) { if (dt["shift"].ToString() == "A") { empam[a] = int.Parse(dt["ID"].ToString()); a++; } else { emppm[p] = int.Parse(dt["ID"].ToString()); p++; } } /* DateTime update = new DateTime(); * var form2 = new Form8(); * form2.Show(); * * //gets the date from the popup form * update = form2.getDate();*/ //creates usable adapter Bus449_TestDataSetTableAdapters.Oncall_CalendarTableAdapter oncall = new Bus449_TestDataSetTableAdapters.Oncall_CalendarTableAdapter(); int count = 0; foreach (DataRow dr in bus449_TestDataSet.Oncall_Calendar.Rows) { if (delid == empam[count] || delid == emppm[count]) { count++; } if (delid == int.Parse(dr["empid_am"].ToString())) { oncall.Update(empam[count], int.Parse(dr["empid_pm"].ToString()), bool.Parse(dr["holiday"].ToString()), dr["holiday_desc"].ToString(), DateTime.Parse(dr["Date_ID"].ToString()), delid, int.Parse(dr["empid_pm"].ToString()), bool.Parse(dr["holiday"].ToString()), dr["holiday_desc"].ToString()); count++; } if (delid == int.Parse(dr["empid_pm"].ToString())) { oncall.Update(int.Parse(dr["empid_am"].ToString()), emppm[count], bool.Parse(dr["holiday"].ToString()), dr["holiday_desc"].ToString(), DateTime.Parse(dr["Date_ID"].ToString()), int.Parse(dr["empid_am"].ToString()), delid, bool.Parse(dr["holiday"].ToString()), dr["holiday_desc"].ToString()); count++; } if (count >= empam.Length || count >= emppm.Length) { count = 0; } } foreach (DataRow dt in bus449_TestDataSet.Employee.Rows) { if (delid == int.Parse(dt["ID"].ToString())) { dt.Delete(); } } //saves any changes made to an employee this.Validate(); this.employeeBindingSource.EndEdit(); this.tableAdapterManager.UpdateAll(this.bus449_TestDataSet); MessageBox.Show("The employee has been deleted"); } }
private void shiftButton_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Are you sure want to change the shift of this employee?", "Shift Confirmation", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { this.Validate(); this.employeeBindingSource.EndEdit(); this.tableAdapterManager.UpdateAll(this.bus449_TestDataSet); int a = 0, p = 0, la, lp; int[] empam, emppm; string checker = "", old = ""; int checkers = shiftComboBox.SelectedIndex; la = (int)this.employeeTableAdapter.AMCount(); lp = (int)this.employeeTableAdapter.PMCount(); empam = new int[la]; emppm = new int[lp]; //creates usable adapter Bus449_TestDataSetTableAdapters.Oncall_CalendarTableAdapter oncall = new Bus449_TestDataSetTableAdapters.Oncall_CalendarTableAdapter(); int holicountx = 0, holicounty = 0, x = 0, y = 0; //populates am and pm employees foreach (DataRow dt in bus449_TestDataSet.Employee.Rows) { if (dt["shift"].ToString() == "A") { empam[a] = int.Parse(dt["ID"].ToString()); a++; } else { emppm[p] = int.Parse(dt["ID"].ToString()); p++; } } checker = shiftComboBox.Text; foreach (DataRow dr in bus449_TestDataSet.Oncall_Calendar.Rows) { //weights holidays if (bool.Parse(dr["holiday"].ToString())) { oncall.Update(empam[holicountx], int.Parse(dr["empid_pm"].ToString()), bool.Parse(dr["holiday"].ToString()), dr["holiday_desc"].ToString(), DateTime.Parse(dr["Date_ID"].ToString()), int.Parse(dr["empid_am"].ToString()), int.Parse(dr["empid_pm"].ToString()), bool.Parse(dr["holiday"].ToString()), dr["holiday_desc"].ToString()); holicountx++; oncall.Update(int.Parse(dr["empid_am"].ToString()), emppm[holicounty], bool.Parse(dr["holiday"].ToString()), dr["holday_desc"].ToString(), DateTime.Parse(dr["Date_ID"].ToString()), int.Parse(dr["empid_am"].ToString()), int.Parse(dr["empid_pm"].ToString()), bool.Parse(dr["holiday"].ToString()), dr["holiday_desc"].ToString()); holicounty++; } if (holicountx >= empam.Length) { holicountx = 0; } if (holicounty >= emppm.Length) { holicounty = 0; } //does the other days else { oncall.Update(empam[x], int.Parse(dr["empid_pm"].ToString()), bool.Parse(dr["holiday"].ToString()), dr["holiday_desc"].ToString(), DateTime.Parse(dr["Date_ID"].ToString()), int.Parse(dr["empid_am"].ToString()), int.Parse(dr["empid_pm"].ToString()), bool.Parse(dr["holiday"].ToString()), dr["holiday_desc"].ToString()); x++; oncall.Update(int.Parse(dr["empid_am"].ToString()), emppm[y], bool.Parse(dr["holiday"].ToString()), dr["holiday_desc"].ToString(), DateTime.Parse(dr["Date_ID"].ToString()), int.Parse(dr["empid_am"].ToString()), int.Parse(dr["empid_pm"].ToString()), bool.Parse(dr["holiday"].ToString()), dr["holiday_desc"].ToString()); y++; } if (x >= empam.Length) { x = 0; } if (y >= emppm.Length) { y = 0; } } this.Validate(); this.employeeBindingSource.EndEdit(); this.tableAdapterManager.UpdateAll(this.bus449_TestDataSet); MessageBox.Show("The shift has been changed."); } }