//Обновление protected void btUpdate_Click(object sender, EventArgs e) { DataProcedures procedures = new DataProcedures(); try { if (DBConnection.idRecord != 0) { SqlCommand command = new SqlCommand("", DBConnection.connection); command.CommandType = System.Data.CommandType.Text; command.CommandText = "select [VacationEndDate] from [VacationOrder] inner join VacationList on [IDVacationList] = [VacationListID] " + "where [IDVacationOrder] like " + ddlOrder.SelectedValue.ToString() + ""; DBConnection.connection.Open(); string startDate = command.ExecuteScalar().ToString(); command.ExecuteNonQuery(); DBConnection.connection.Close(); //Дата окончания DateTime theDate1 = DateTime.ParseExact(tbEndDate.Text, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); string endDate = theDate1.ToString("dd.MM.yyyy"); DateTime dateNow = DateTime.UtcNow.Date; procedures.ExtensionOrder_Update(DBConnection.idRecord, dateNow.ToString(), tbReason.Text.ToString(), startDate, endDate, Convert.ToInt32(ddlOrder.SelectedValue.ToString())); Response.Redirect(Request.Url.AbsoluteUri); gvFill(QR); Cleaner(); ddlOrderFill(); } } catch { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Не удалось обновить запись запись :(')", true); } }
protected void btDelete_Click(object sender, EventArgs e) { int days; //Дни для добавления к дням отпуска try { DataProcedures procedures = new DataProcedures(); //Количество дней GridViewRow rows = gvVacation.SelectedRow; days = Convert.ToInt32(rows.Cells[5].Text.ToString()); days += Convert.ToInt32(lbldaysAvailable.Text); ddlType.SelectedValue = rows.Cells[1].Text.ToString(); procedures.Days_Amount_Update(days, DBConnection.idUser); procedures.VacationList_Delete(DBConnection.idRecord); Cleaner(); gvFill(QR); pageDataFill(); Response.Redirect(Request.Url.AbsoluteUri); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Запись успешно удалена.')", true); } catch { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Не удалось удалить запись :(')", true); } }
//Добавление записи protected void btInsert_Click(object sender, EventArgs e) { DataProcedures procedures = new DataProcedures(); DBConnection connection = new DBConnection(); try { if (connection.LoginCheck(tbLogin.Text) > 0) { lblLoginCheck.Visible = true; } else { lblLoginCheck.Visible = false; procedures.PersonalCard_Insert(tbSurname.Text, tbName.Text, tbMiddleName.Text, Convert.ToInt32(tbDaysAmount.Text), tbLogin.Text, tbPassword.Text, Convert.ToInt32(ddlPosition.SelectedValue.ToString())); Response.Redirect(Request.Url.AbsoluteUri); gvFill(QR); Cleaner(); ddlPositionFill(); } } catch { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Не удалось добавить запись :(')", true); } }
private void consultantHoursButton_Click(object sender, EventArgs e) { DataProcedures data = new DataProcedures(); resultsGroupBox.Visible = true; resultsGroupBox.Text = "Consultants hours"; resultTextBox.Text = string.Empty; string resultString = string.Empty; List <int> userIdsDistinct = data.returnDistinctConsultantsWithAppts(); userIdsDistinct.ForEach(varid => {//lambda used to make foreach simpler List <Appointment> consultantAppts = data.returnUserSchedule(varid); double totalHours = 0; consultantAppts.ForEach(appt => {//lambda used to make foreach simpler totalHours += (appt.end - appt.start).TotalHours; }); resultString += "\n\nTotal hours for user " + varid + ": " + totalHours; }); resultTextBox.Text = resultString; }
//Удаление protected void gvRecall_RowDeleting(object sender, GridViewDeleteEventArgs e) { try { if (DBConnection.idRecord != 0) { SqlCommand command = new SqlCommand("", DBConnection.connection); int Index = Convert.ToInt32(e.RowIndex); DataProcedures procedure = new DataProcedures(); GridViewRow rows = gvRecall.SelectedRow; DBConnection.idRecord = Convert.ToInt32(gvRecall.Rows[Index].Cells[1].Text.ToString()); command.CommandType = System.Data.CommandType.Text; command.CommandText = "delete from [RecallOrder] where [IDRecallOrder] = '" + DBConnection.idRecord + "'"; DBConnection.connection.Open(); command.ExecuteNonQuery(); DBConnection.connection.Close(); Response.Redirect(Request.Url.AbsoluteUri); gvFill(QR); Cleaner(); ddlOrderFill(); } } catch { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Не удалось удалить запись :(')", true); } }
private void apptTypesByMonthButton_Click(object sender, EventArgs e) { DataProcedures data = new DataProcedures(); resultsGroupBox.Visible = true; resultsGroupBox.Text = "Appt Types By Month"; resultTextBox.Text = string.Empty; string resultString = string.Empty; for (int i = 1; i <= 12; i++) { List <string> list = data.returnApptTypesByMonth(currentUser.userId, i); var q = from x in list group x by x into g let count = g.Count() orderby count descending select new { Value = g.Key, Count = count }; resultString += Environment.NewLine + DateTimeFormatInfo.CurrentInfo.GetMonthName(i) + Environment.NewLine; foreach (var x in q) { resultString += "Appointment type: " + x.Value + "\t Count: " + x.Count + Environment.NewLine; } } resultTextBox.Text = resultString; }
//Отказать в отпуске protected void btReject_Click(object sender, EventArgs e) { try { if (DBConnection.idRecord != 0) { int selectedRow = gvVacation.SelectedRow.RowIndex; GridViewRow rows = gvVacation.SelectedRow; int vacationDays = Convert.ToInt32(rows.Cells[9].Text.ToString()); int cardID = Convert.ToInt32(rows.Cells[3].Text.ToString()); int cardDays = Convert.ToInt32(rows.Cells[15].Text.ToString()); int daysAmount = cardDays + vacationDays; DataProcedures procedures = new DataProcedures(); procedures.VacationList_Status_Update(DBConnection.idRecord, "Отклонен"); procedures.Days_Amount_Update(daysAmount, cardID); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Отпуск успешно отклонен.')", true); gvFill(QR); Cleaner(); btConfirm.Visible = false; btReject.Visible = false; DBConnection.idRecord = 0; } } catch { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Не удалось выполнить :(')", true); } }
private void endDateTimePicker_ValueChanged(object sender, EventArgs e) { DataProcedures data = new DataProcedures(); bool overlap = data.checkForOverlappingAppointmentsWhenAdding(startDateTimePicker.Value.ToUniversalTime(), endDateTimePicker.Value.ToUniversalTime()); if (overlap) { validAppt = false; dateTimeErrorlabel.Text = "There are overlapping appt times."; dateTimeErrorlabel.Left = 42; dateTimeErrorlabel.Visible = true; } else { dateTimeErrorlabel.Visible = false; } if (startDateTimePicker.Value.ToUniversalTime() < endDateTimePicker.Value.ToUniversalTime()) { if (!overlap) { validAppt = true; } } else { validAppt = false; dateTimeErrorlabel.Text = "Please enter valid times."; dateTimeErrorlabel.Left = 72; dateTimeErrorlabel.Visible = true; } }
private void registerButton_Click(object sender, EventArgs e) { User userInfo = new User(usernameTextbox.Text, passwordTextbox.Text); DataProcedures data = new DataProcedures(); if (string.IsNullOrEmpty(usernameTextbox.Text) && string.IsNullOrEmpty(passwordTextbox.Text)) { enterInfolabel.Visible = true; } else { if (confirmPassTextBox.Text.Equals(passwordTextbox.Text)) { if (data.registerUser(userInfo)) { this.Hide(); LogIn logInForm = new LogIn(); logInForm.Show(); } } else { mismatchLabel.Visible = true; } } }
private void signInButton_Click(object sender, EventArgs e) { DataProcedures data = new DataProcedures(); User userInfo = new User(usernameTextbox.Text, passwordTextbox.Text); userInfo.userId = data.verifyUser(userInfo); if (userInfo.userId != -1) { DateTime dateTime = DateTime.Now; data.logUserActivity("Username: '******'. UserID: " + userInfo.userId + ". Logged in at " + dateTime); this.Hide(); MainScreen mainScr = new MainScreen(userInfo); mainScr.Show(); //Show upcoming appts when user signs in. List <Appointment> upcomingAppts = data.checkUserReminders(userInfo.userId); if (upcomingAppts.Count > 0) { foreach (var appt in upcomingAppts) { Reminder apptReminder = new Reminder(appt); apptReminder.Show(); } } } else { errorLabel.Show(); } }
private void customerDataGridView_CellClick(object sender, DataGridViewCellEventArgs e) { DataProcedures data = new DataProcedures(); int custSelected = Convert.ToInt32(customerDataGridView.Rows[customerDataGridView.CurrentCell.RowIndex].Cells[0].Value); apptDataGridView.DataSource = data.getAppointments(custSelected, currentUser.userId); apptGroupBox.Text = "Appointments for " + customerDataGridView.Rows[customerDataGridView.CurrentCell.RowIndex].Cells[1].Value; }
public AddAppointment(User user) { InitializeComponent(); currentUser = new User(); currentUser.username = user.username; currentUser.userId = user.userId; DataProcedures data = new DataProcedures(); customerDataGridView.DataSource = data.getCustomers(); }
public Reminder(Appointment appt) { InitializeComponent(); DataProcedures data = new DataProcedures(); string customerName = data.getCustomerInformation(appt.customerId).customerName; headMsg.Text += customerName; titleTextBox.Text = appt.title; descriptionTextBox.Text = appt.description; locationTextBox.Text = appt.location; contactTextBox.Text = appt.contact; typeTextBox.Text = appt.type; urlTextBox.Text = appt.url; startDateTimePicker.Value = appt.start.ToLocalTime(); endDateTimePicker.Value = appt.end.ToLocalTime(); }
protected void btInsert_Click(object sender, EventArgs e) { DataProcedures procedures = new DataProcedures(); try { procedures.VacationType_Insert(tbType.Text); gvFill(QR); Response.Redirect(Request.Url.AbsoluteUri); Cleaner(); } catch { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Не удалось добавить запись :(')", true); } }
protected void btUpdate_Click(object sender, EventArgs e) { try { if (DBConnection.idRecord != 0) { DataProcedures procedures = new DataProcedures(); procedures.VacationType_Update(DBConnection.idRecord, tbType.Text); gvFill(QR); Response.Redirect(Request.Url.AbsoluteUri); Cleaner(); } } catch { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Не удалось обновить запись запись :(')", true); } }
//Удаление записи protected void gvType_RowDeleting(object sender, GridViewDeleteEventArgs e) { try { int Index = Convert.ToInt32(e.RowIndex); DataProcedures procedure = new DataProcedures(); GridViewRow rows = gvType.SelectedRow; DBConnection.idRecord = Convert.ToInt32(gvType.Rows[Index].Cells[1].Text.ToString()); procedure.VacationType_Delete(DBConnection.idRecord); gvFill(QR); Response.Redirect(Request.Url.AbsoluteUri); Cleaner(); } catch { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Не удалось удалить запись :(')", true); } }
private void deleteCustButton_Click(object sender, EventArgs e) { DialogResult deletePartDialogResult = MessageBox.Show("Are you sure you want to delete this part?", "Delete Part", MessageBoxButtons.YesNo); int custSelected = Convert.ToInt32(customerDataGridView.Rows[customerDataGridView.CurrentCell.RowIndex].Cells[0].Value); if (custSelected != -1) { if (deletePartDialogResult == DialogResult.Yes) { DataProcedures data = new DataProcedures(); data.deleteCustomer(custSelected); customerDataGridView.DataSource = data.getCustomers();//set data source to show current list } } else { MessageBox.Show("There are no customers to delete.", "Error"); } }
private void emboldenMonthCalendar() { DataProcedures data = new DataProcedures(); List <Appointment> appts = data.returnUserSchedule(currentUser.userId); DateTime[] datesToBold = new DateTime[60]; int iterator = 0; appts.ForEach(appt => {//lambda used to make foreach simpler datesToBold[iterator] = appt.start; iterator++; }); monthCalendar.BoldedDates = datesToBold; }
private void deleteApptButton_Click(object sender, EventArgs e) { DialogResult deleteApptDialogResult = MessageBox.Show("Are you sure you want to delete this appointment?", "Delete appointment", MessageBoxButtons.YesNo); int apptSelected = Convert.ToInt32(apptDataGridView.Rows[apptDataGridView.CurrentCell.RowIndex].Cells[0].Value); if (apptSelected != -1) { if (deleteApptDialogResult == DialogResult.Yes) { DataProcedures data = new DataProcedures(); data.deleteAppointment(apptSelected); int custSelected = Convert.ToInt32(customerDataGridView.Rows[customerDataGridView.CurrentCell.RowIndex].Cells[0].Value); apptDataGridView.DataSource = data.getAppointments(custSelected, currentUser.userId); } } else { MessageBox.Show("There are no appointments to delete.", "Error"); } }
public ModifyCustomer(User user, int modifiedCustId) { InitializeComponent(); custId = modifiedCustId; currentUser = user; DataProcedures data = new DataProcedures(); CustomerInformation custInfo = data.getCustomerInformation(custId); nameTextBox.Text = custInfo.customerName; phNumberTextBox.Text = custInfo.phone; addressTextBox.Text = custInfo.address; address2TextBox.Text = custInfo.address2; cityTextBox.Text = custInfo.city; postalCodeTextBox.Text = custInfo.postalCode; countryTextBox.Text = custInfo.country; custGroupBox.Text = "Customer " + modifiedCustId.ToString(); }
//Обновление записи protected void btUpdate_Click(object sender, EventArgs e) { try { if (DBConnection.idRecord != 0) { DataProcedures procedures = new DataProcedures(); procedures.PersonalCard_Update(DBConnection.idRecord, tbSurname.Text, tbName.Text, tbMiddleName.Text, Convert.ToInt32(tbDaysAmount.Text), tbLogin.Text, tbPassword.Text, Convert.ToInt32(ddlPosition.SelectedValue.ToString())); Response.Redirect(Request.Url.AbsoluteUri); gvFill(QR); Cleaner(); ddlPositionFill(); } } catch { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Не удалось обновить запись запись :(')", true); } }
//Добавление protected void btInsert_Click(object sender, EventArgs e) { DataProcedures procedures = new DataProcedures(); try { //Дата отзыва DateTime theDate1 = DateTime.ParseExact(tbRecallDate.Text, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); string recallDate = theDate1.ToString("dd.MM.yyyy"); //Дата окончания DateTime dateNow = DateTime.UtcNow.Date; procedures.RecallOrder_Insert(dateNow.ToString(), tbReason.Text.ToString(), recallDate, Convert.ToInt32(ddlOrder.SelectedValue.ToString())); gvFill(QR); Cleaner(); ddlOrderFill(); } catch { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Не удалось добавить запись :(')", true); } }
public MainScreen(User user) { InitializeComponent(); currentUser = new User(); currentUser = user; mainGroupBox.Text = "Hi " + user.username; DataProcedures data = new DataProcedures(); customerDataGridView.DataSource = data.getCustomers(); emboldenMonthCalendar(); //If datagridview is not empty select the appointments for the first record if (customerDataGridView.Rows.Count != 0) { int custSelected = Convert.ToInt32(customerDataGridView.Rows[0].Cells[0].Value); apptDataGridView.DataSource = data.getAppointments(custSelected, currentUser.userId); apptGroupBox.Text = "Appointments for " + customerDataGridView.Rows[0].Cells[1].Value; } }
public ModifyAppointment(User user, int modifiedApptId) { InitializeComponent(); apptId = modifiedApptId; currentUser = user; DataProcedures data = new DataProcedures(); customerDataGridView.DataSource = data.getCustomers(); Appointment appt = data.getAppointmentInformation(apptId); appt.userId = currentUser.userId; titleTextBox.Text = appt.title; descriptionTextBox.Text = appt.description; locationTextBox.Text = appt.location; contactTextBox.Text = appt.contact; typeTextBox.Text = appt.type; urlTextBox.Text = appt.url; startDateTimePicker.Value = appt.start.ToLocalTime(); endDateTimePicker.Value = appt.end.ToLocalTime(); }
private void weeklyButton_Click(object sender, EventArgs e) { DataProcedures data = new DataProcedures(); if (weeklyButton.Text == "View Monthly") { weeklyDataGridView.Hide(); prevWeekButton.Hide(); nextWeekButton.Hide(); weekLabel.Hide(); weeklyButton.Text = "View Weekly"; monthCalendar.Show(); } else { weeklyDataGridView.Show(); prevWeekButton.Show(); nextWeekButton.Show(); weekLabel.Show(); //Code was referrenced from: https://docs.microsoft.com/en-us/dotnet/api/system.globalization.calendar.getweekofyear?view=netframework-4.7.2 // Gets the Calendar instance associated with a CultureInfo. CultureInfo myCI = new CultureInfo("en-US"); Calendar myCal = myCI.Calendar; // Gets the DTFI properties required by GetWeekOfYear. CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule; DayOfWeek myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek; weekOfTheYear = myCal.GetWeekOfYear(DateTime.Now, myCWR, myFirstDOW); setWeeklyCalendar(); weekLabel.Text = "Week " + weekOfTheYear; weeklyButton.Text = "View Monthly"; monthCalendar.Hide(); } }
//Согласовать отпуск protected void btConfirm_Click(object sender, EventArgs e) { try { if (DBConnection.idRecord != 0) { DateTime dateNow = DateTime.UtcNow.Date; DataProcedures procedures = new DataProcedures(); procedures.VacationOrder_Insert(dateNow.ToString(), DBConnection.idRecord); procedures.VacationList_Status_Update(DBConnection.idRecord, "Согласован"); Response.Redirect(Request.Url.AbsoluteUri); gvFill(QR); Cleaner(); btConfirm.Visible = false; btReject.Visible = false; DBConnection.idRecord = 0; } } catch { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Не удалось выполнить :(')", true); } }
//Обновление protected void btUpdate_Click(object sender, EventArgs e) { DataProcedures procedures = new DataProcedures(); try { if (DBConnection.idRecord != 0) { //Дата отзыва DateTime theDate1 = DateTime.ParseExact(tbRecallDate.Text, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); string recallDate = theDate1.ToString("dd.MM.yyyy"); procedures.RecallOrder_Update(DBConnection.idRecord, tbReason.Text.ToString(), recallDate, Convert.ToInt32(ddlOrder.SelectedValue.ToString())); Response.Redirect(Request.Url.AbsoluteUri); gvFill(QR); Cleaner(); ddlOrderFill(); } } catch { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Не удалось обновить запись запись :(')", true); } }
private void consultantScheduleButton_Click(object sender, EventArgs e) { DataProcedures data = new DataProcedures(); resultsGroupBox.Visible = true; resultsGroupBox.Text = "Consultants schedule"; resultTextBox.Text = string.Empty; string resultString = string.Empty; List <int> userIdsDistinct = data.returnDistinctConsultantsWithAppts(); userIdsDistinct.ForEach(varid => {//lambda used to make foreach simpler List <Appointment> consultantAppts = data.returnUserSchedule(varid); resultString += "\n\nAppointments for user " + varid + "\n"; consultantAppts.ForEach(appt => {//lambda used to make foreach simpler resultString += "\nStart: " + appt.start + " End: " + appt.end + Environment.NewLine; }); }); resultTextBox.Text = resultString; }
private void saveButton_Click(object sender, EventArgs e) { bool textBoxesNotEmpty; if (string.IsNullOrWhiteSpace(titleTextBox.Text)) { textBoxesNotEmpty = false; } else if (string.IsNullOrWhiteSpace(descriptionTextBox.Text)) { textBoxesNotEmpty = false; } else if (string.IsNullOrWhiteSpace(locationTextBox.Text)) { textBoxesNotEmpty = false; } else if (string.IsNullOrWhiteSpace(contactTextBox.Text)) { textBoxesNotEmpty = false; } else if (string.IsNullOrWhiteSpace(typeTextBox.Text)) { textBoxesNotEmpty = false; } else if (string.IsNullOrWhiteSpace(urlTextBox.Text)) { textBoxesNotEmpty = false; } else { textBoxesNotEmpty = true; } if (textBoxesNotEmpty && validAppt) { int custSelected = Convert.ToInt32(customerDataGridView.Rows[customerDataGridView.CurrentCell.RowIndex].Cells[0].Value); Appointment appt = new Appointment(); appt.customerId = custSelected; appt.userId = currentUser.userId; appt.title = titleTextBox.Text; appt.description = descriptionTextBox.Text; appt.location = locationTextBox.Text; appt.contact = contactTextBox.Text; appt.type = typeTextBox.Text; appt.url = urlTextBox.Text; appt.start = startDateTimePicker.Value.ToUniversalTime();//all times are stored and compared as UTC, and displayed to the user in their local time. appt.end = endDateTimePicker.Value.ToUniversalTime(); DataProcedures data = new DataProcedures(); if (data.addAppointment(appt) != -1) { MainScreen mainScreen = new MainScreen(currentUser); this.Hide(); mainScreen.Show(); } } else { fillFieldsLabel.Visible = true; } }
private void saveButton_Click(object sender, EventArgs e) { bool textBoxesNotEmpty; if (string.IsNullOrWhiteSpace(titleTextBox.Text)) { textBoxesNotEmpty = false; } else if (string.IsNullOrWhiteSpace(descriptionTextBox.Text)) { textBoxesNotEmpty = false; } else if (string.IsNullOrWhiteSpace(locationTextBox.Text)) { textBoxesNotEmpty = false; } else if (string.IsNullOrWhiteSpace(contactTextBox.Text)) { textBoxesNotEmpty = false; } else if (string.IsNullOrWhiteSpace(typeTextBox.Text)) { textBoxesNotEmpty = false; } else if (string.IsNullOrWhiteSpace(urlTextBox.Text)) { textBoxesNotEmpty = false; } else { textBoxesNotEmpty = true; } if (textBoxesNotEmpty) { if (validAppt) { int custSelected = Convert.ToInt32(customerDataGridView.Rows[customerDataGridView.CurrentCell.RowIndex].Cells[0].Value); Appointment appt = new Appointment(); appt.appointmentId = apptId; appt.customerId = custSelected; appt.userId = currentUser.userId; appt.title = titleTextBox.Text; appt.description = descriptionTextBox.Text; appt.location = locationTextBox.Text; appt.contact = contactTextBox.Text; appt.type = typeTextBox.Text; appt.url = urlTextBox.Text; appt.start = startDateTimePicker.Value.ToUniversalTime(); appt.end = endDateTimePicker.Value.ToUniversalTime(); DataProcedures data = new DataProcedures(); if (data.updateAppointment(appt)) { MainScreen mainScreen = new MainScreen(currentUser); this.Hide(); mainScreen.Show(); } } else { dateTimeErrorlabel.Text = "Please enter valid times."; dateTimeErrorlabel.Left = 72; dateTimeErrorlabel.Visible = true; } } else { fillFieldsLabel.Visible = true; } }