private void button1_Click(object sender, EventArgs e) { bool checkRepeatIsChange = false; TaskSer taskService = new TaskSer(); Tasks ts = new Tasks(); ts.Task_ID = obj.Task_ID; ts.Tittle = textBox1.Text; ts.Description = textBox2.Text; ts.Date = dateTimePicker2.Value.ToShortDateString(); ts.Time = dateTimePicker1.Value.ToShortTimeString(); CategorySer cS = new CategorySer(); int cat_ID; if (cBCategory.SelectedIndex < 0) { cat_ID = cS.GetCategoryID("Inbox", LogIn.user_ID); } else { cat_ID = cS.GetCategoryID(cBCategory.SelectedItem.ToString(), LogIn.user_ID); } ts.Category_ID = cat_ID; int prio; if (cBPriority.SelectedIndex < 0) { prio = 1; } else { if (cBPriority.SelectedItem.ToString().Equals("High")) { prio = 3; } else if (cBPriority.SelectedItem.ToString().Equals("Medium")) { prio = 2; } else { prio = 1; } } ts.Priority = prio; List <BeforeNotificationTime> notificationTimeList = new List <BeforeNotificationTime>(); if (cBSelectedReminders.Items.Count == 0) { //MessageBox.Show(cBSelectedReminders.Items.Count.ToString()); BeforeNotificationTime notifyTime = new BeforeNotificationTime(); notifyTime.Date = dateTimePicker2.Value.ToShortDateString(); notifyTime.Time = dateTimePicker1.Value.ToShortTimeString(); notificationTimeList.Add(notifyTime); } else { //MessageBox.Show("Inside The Else Part"); //5 minutes before //10 minutes before //15 minutes before //30 minutes before //1 hour before for (int i = 0; i < cBSelectedReminders.Items.Count; i++) { BeforeNotificationTime notifyTime = new BeforeNotificationTime(); string time; time = cBSelectedReminders.Items[i].ToString(); string an = ""; for (int k = 0; k < time.Length; k++) { if (time[k] == ' ') { break; } an += (time[k].ToString()); } int timeValue = Convert.ToInt32(an); //MessageBox.Show(timeValue.ToString()); if (cBSelectedReminders.Items[i].ToString().Contains("minutes before - NO")) { //MessageBox.Show("Inside Minutes Part"); notifyTime.NotifyTimeBeforeString = cBSelectedReminders.Items[i].ToString(); notifyTime.Date = dateTimePicker2.Value.ToShortDateString(); DateTime tm = dateTimePicker1.Value; DateTime tm2 = tm.AddMinutes(timeValue); TimeSpan t = tm2 - tm; tm = tm - t; notifyTime.Time = tm.ToShortTimeString(); //MessageBox.Show(tm.ToShortTimeString()); if (cBSelectedReminders.Items.ToString().Contains("EM")) { notifyTime.Notify_Via = 2; } if (cBSelectedReminders.Items.ToString().Contains("SM")) { notifyTime.Notify_Via = 3; } else { notifyTime.Notify_Via = 1; } notificationTimeList.Add(notifyTime); } else if (cBSelectedReminders.Items[i].ToString().Contains("hours before - NO")) { //MessageBox.Show("Inside Hours Part"); notifyTime.NotifyTimeBeforeString = cBSelectedReminders.Items[i].ToString(); notifyTime.Date = dateTimePicker2.Value.ToShortDateString(); DateTime tm = dateTimePicker1.Value; DateTime tm2 = tm.AddHours(timeValue); TimeSpan t = tm2 - tm; tm = tm - t; notifyTime.Time = tm.ToShortTimeString(); if (cBSelectedReminders.Items.ToString().Contains("EM")) { notifyTime.Notify_Via = 2; } if (cBSelectedReminders.Items.ToString().Contains("SM")) { notifyTime.Notify_Via = 3; } else { notifyTime.Notify_Via = 1; } notificationTimeList.Add(notifyTime); } else if (cBSelectedReminders.Items[i].ToString().Contains("days before - NO")) { //MessageBox.Show("Inside Days Part"); notifyTime.NotifyTimeBeforeString = cBSelectedReminders.Items[i].ToString(); DateTime tm = dateTimePicker1.Value; DateTime tm2 = tm.AddDays(timeValue); TimeSpan t = tm2 - tm; tm = tm - t; notifyTime.Date = tm.ToShortDateString(); notifyTime.Time = dateTimePicker1.Value.ToShortTimeString(); if (cBSelectedReminders.Items.ToString().Contains("EM")) { notifyTime.Notify_Via = 2; } if (cBSelectedReminders.Items.ToString().Contains("SM")) { notifyTime.Notify_Via = 3; } else { notifyTime.Notify_Via = 1; } notificationTimeList.Add(notifyTime); } else { //MessageBox.Show("Inside Weeks Part"); notifyTime.NotifyTimeBeforeString = cBSelectedReminders.Items[i].ToString(); DateTime tm = dateTimePicker1.Value; DateTime tm2 = tm.AddDays(timeValue * 7); TimeSpan t = tm2 - tm; tm = tm - t; notifyTime.Date = tm.ToShortDateString(); notifyTime.Time = dateTimePicker1.Value.ToShortTimeString(); if (cBSelectedReminders.Items.ToString().Contains("EM")) { notifyTime.Notify_Via = 2; } if (cBSelectedReminders.Items.ToString().Contains("SM")) { notifyTime.Notify_Via = 3; } else { notifyTime.Notify_Via = 1; } notificationTimeList.Add(notifyTime); } } } ts.Notify_Time_List = notificationTimeList; List <string> repeateDateList = new List <string>(100); if (cBRepeat.Text.Equals(obj.RepeatName) || cBRepeat.SelectedIndex < 0) { ts.Repeat_Date_List = obj.Repeat_Date_List; } else { if (MessageBox.Show("Are you update All Task Which is follwing this task????", "Hello!!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { checkRepeatIsChange = true; TaskSer taskS = new TaskSer(); taskS.DeleteByRepeatID(obj.RepeatDateTask_ID); ts.RepeatDateTask_ID = System.Guid.NewGuid().ToString(); if (cBRepeat.SelectedItem.ToString().Equals("Every day")) { DateTime dt = DateTime.Now; for (int i = 0; i < repeateDateList.Capacity; i++) { repeateDateList.Add(dt.ToShortDateString()); dt = dt.AddDays(1); } } else if (cBRepeat.SelectedItem.ToString().Equals("Every week")) { DateTime dt = DateTime.Now; for (int i = 0; i < repeateDateList.Capacity; i++) { repeateDateList.Add(dt.ToShortDateString()); dt = dt.AddDays(7); } } else if (cBRepeat.SelectedItem.ToString().Equals("Every month")) { DateTime dt = DateTime.Now; for (int i = 0; i < repeateDateList.Capacity; i++) { repeateDateList.Add(dt.ToShortDateString()); dt = dt.AddMonths(1); } } else { DateTime dt = DateTime.Now; for (int i = 0; i < repeateDateList.Capacity; i++) { repeateDateList.Add(dt.ToShortDateString()); dt = dt.AddYears(1); } } } else { cBRepeat.Text = obj.RepeatName; } } if (checkRepeatIsChange) { ts.Repeat_Date_List = repeateDateList; TaskSer tSer = new TaskSer(); tSer.Insert(ts); } else { TaskSer tSer = new TaskSer(); tSer.Update(ts); } this.Close(); }
private void button7_Click(object sender, EventArgs e) { OpenFileDialog fb = new OpenFileDialog(); fb.Filter = "Excel Office | *.xls; *.xlsx"; if (fb.ShowDialog() == DialogResult.OK) { FileStream strem = new FileStream(fb.FileName, FileMode.Open, FileAccess.Read); IExcelDataReader exReader = ExcelReaderFactory.CreateReader(strem); DataSet ds = exReader.AsDataSet(new ExcelDataSetConfiguration() { ConfigureDataTable = (_) => new ExcelDataTableConfiguration() { UseHeaderRow = true } }); List <Tasks> tk = new List <Tasks>(); Tasks t; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { t = new Tasks(); for (int j = 0; j < ds.Tables[0].Columns.Count; j++) { if (j == 0) { t.Task_ID = Convert.ToInt32(ds.Tables[0].Rows[i][j].ToString()); } else if (j == 1) { t.Tittle = ds.Tables[0].Rows[i][j].ToString(); } else if (j == 2) { t.Date = ds.Tables[0].Rows[i][j].ToString(); } else if (j == 3) { t.Time = ds.Tables[0].Rows[i][j].ToString(); } else if (j == 4) { t.RepeatDateTask_ID = ds.Tables[0].Rows[i][j].ToString(); } else if (j == 5) { t.Description = ds.Tables[0].Rows[i][j].ToString(); } else if (j == 6) { t.Priority = Convert.ToInt32(ds.Tables[0].Rows[i][j].ToString()); } else if (j == 7) { t.Category_ID = cat_ID; } else { t.Task_Complete = Convert.ToInt32(ds.Tables[0].Rows[i][j].ToString()); } } tk.Add(t); } exReader.Dispose(); strem.Dispose(); ds.Dispose(); TaskSer tkSer = new TaskSer(); for (int i = 0; i < tk.Count; i++) { tkSer.Insert(tk[i]); } MessageBox.Show("File Is Imported"); } }
private void AddTaskInDatabase() { List <string> repeateDateList = new List <string>(100); List <BeforeNotificationTime> notificationTimeList = new List <BeforeNotificationTime>(); CategorySer cSer = new CategorySer(); if (textBox1.Text != null) { Tasks ts = new Tasks(); ts.Tittle = textBox1.Text; if (textBox2.Text != null) { ts.Description = textBox2.Text; } ts.Date = dateTimePicker2.Value.ToShortDateString(); ts.Time = dateTimePicker1.Value.ToString("hh:mm tt"); if (cBCategory.SelectedIndex < 0) { ts.Category_ID = cSer.GetCategoryID("Inbox", LogIn.user_ID); } else { ts.Category_ID = cSer.GetCategoryID(cBCategory.SelectedItem.ToString(), LogIn.user_ID); } if (cBPriority.SelectedIndex < 0) { ts.Priority = 1; } else { if (cBPriority.SelectedItem.ToString().Equals("High")) { ts.Priority = 3; } else if (cBPriority.SelectedItem.ToString().Equals("Medium")) { ts.Priority = 2; } else { ts.Priority = 1; } } if (cBRepeat.SelectedIndex < 0) { ts.RepeatDateTask_ID = System.Guid.NewGuid().ToString(); } else { ts.RepeatDateTask_ID = System.Guid.NewGuid().ToString(); if (cBRepeat.SelectedItem.ToString().Equals("Every day")) { DateTime dt = DateTime.Now; for (int i = 0; i < repeateDateList.Capacity; i++) { repeateDateList.Add(dt.ToShortDateString()); dt = dt.AddDays(1); } } else if (cBRepeat.SelectedItem.ToString().Equals("Every week")) { DateTime dt = DateTime.Now; for (int i = 0; i < repeateDateList.Capacity; i++) { repeateDateList.Add(dt.ToShortDateString()); dt = dt.AddDays(7); } } else if (cBRepeat.SelectedItem.ToString().Equals("Every month")) { DateTime dt = DateTime.Now; for (int i = 0; i < repeateDateList.Capacity; i++) { repeateDateList.Add(dt.ToShortDateString()); dt = dt.AddMonths(1); } } else { DateTime dt = DateTime.Now; for (int i = 0; i < repeateDateList.Capacity; i++) { repeateDateList.Add(dt.ToShortDateString()); dt = dt.AddYears(1); } } } if (cBSelectedReminders.Items.Count == 0) { //MessageBox.Show(cBSelectedReminders.Items.Count.ToString()); BeforeNotificationTime notifyTime = new BeforeNotificationTime(); notifyTime.Date = dateTimePicker2.Value.ToShortDateString(); notifyTime.Time = dateTimePicker1.Value.ToShortTimeString(); notificationTimeList.Add(notifyTime); } else { //MessageBox.Show("Inside The Else Part"); //5 minutes before //10 minutes before //15 minutes before //30 minutes before //1 hour before for (int i = 0; i < cBSelectedReminders.Items.Count; i++) { BeforeNotificationTime notifyTime = new BeforeNotificationTime(); string time; time = cBSelectedReminders.Items[i].ToString(); string an = ""; for (int k = 0; k < time.Length; k++) { if (time[k] == ' ') { break; } an += (time[k].ToString()); } int timeValue = Convert.ToInt32(an); //MessageBox.Show(timeValue.ToString()); if (cBSelectedReminders.Items[i].ToString().Contains("minutes before - NO")) { //MessageBox.Show("Inside Minutes Part"); notifyTime.NotifyTimeBeforeString = cBSelectedReminders.Items[i].ToString(); notifyTime.Date = dateTimePicker2.Value.ToShortDateString(); DateTime tm = dateTimePicker1.Value; DateTime tm2 = tm.AddMinutes(timeValue); TimeSpan t = tm2 - tm; tm = tm - t; notifyTime.Time = tm.ToShortTimeString(); //MessageBox.Show(tm.ToShortTimeString()); if (cBSelectedReminders.Items.ToString().Contains("EM")) { notifyTime.Notify_Via = 2; } if (cBSelectedReminders.Items.ToString().Contains("SM")) { notifyTime.Notify_Via = 3; } else { notifyTime.Notify_Via = 1; } notificationTimeList.Add(notifyTime); } else if (cBSelectedReminders.Items[i].ToString().Contains("hours before - NO")) { //MessageBox.Show("Inside Hours Part"); notifyTime.NotifyTimeBeforeString = cBSelectedReminders.Items[i].ToString(); notifyTime.Date = dateTimePicker2.Value.ToShortDateString(); DateTime tm = dateTimePicker1.Value; DateTime tm2 = tm.AddHours(timeValue); TimeSpan t = tm2 - tm; tm = tm - t; notifyTime.Time = tm.ToShortTimeString(); if (cBSelectedReminders.Items.ToString().Contains("EM")) { notifyTime.Notify_Via = 2; } if (cBSelectedReminders.Items.ToString().Contains("SM")) { notifyTime.Notify_Via = 3; } else { notifyTime.Notify_Via = 1; } notificationTimeList.Add(notifyTime); } else if (cBSelectedReminders.Items[i].ToString().Contains("days before - NO")) { //MessageBox.Show("Inside Days Part"); notifyTime.NotifyTimeBeforeString = cBSelectedReminders.Items[i].ToString(); DateTime tm = dateTimePicker1.Value; DateTime tm2 = tm.AddDays(timeValue); TimeSpan t = tm2 - tm; tm = tm - t; notifyTime.Date = tm.ToShortDateString(); notifyTime.Time = dateTimePicker1.Value.ToShortTimeString(); if (cBSelectedReminders.Items.ToString().Contains("EM")) { notifyTime.Notify_Via = 2; } if (cBSelectedReminders.Items.ToString().Contains("SM")) { notifyTime.Notify_Via = 3; } else { notifyTime.Notify_Via = 1; } notificationTimeList.Add(notifyTime); } else { //MessageBox.Show("Inside Weeks Part"); notifyTime.NotifyTimeBeforeString = cBSelectedReminders.Items[i].ToString(); DateTime tm = dateTimePicker1.Value; DateTime tm2 = tm.AddDays(timeValue * 7); TimeSpan t = tm2 - tm; tm = tm - t; notifyTime.Date = tm.ToShortDateString(); notifyTime.Time = dateTimePicker1.Value.ToShortTimeString(); if (cBSelectedReminders.Items.ToString().Contains("EM")) { notifyTime.Notify_Via = 2; } if (cBSelectedReminders.Items.ToString().Contains("SM")) { notifyTime.Notify_Via = 3; } else { notifyTime.Notify_Via = 1; } notificationTimeList.Add(notifyTime); } } } ts.Repeat_Date_List = repeateDateList; ts.Notify_Time_List = notificationTimeList; TaskSer taskService = new TaskSer(); List <int> taskID = taskService.Insert(ts); taskService = new TaskSer(); taskService.InsertInNotificationTime(taskID, ts); MessageBox.Show("Task Is Added!!!"); this.Close(); UserControlForOnlyTestPurpose.uC.LoadTaskList(); } else { MessageBox.Show("You Should be Put the task tittle!!!"); } }