Пример #1
0
        private void btnSaveAndClose_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            OnOkButton();
            if (scheduleId.Text.Trim() == "0")
            {
                ScheduleServices scheduleServices = new ScheduleServices();
                String[]         listDepartment   = checkedComboBoxEditDepartments.EditValue.ToString().Split(',');
                for (int i = 0; i < listDepartment.Length; i++)
                {
                    if (listDepartment[i].Trim() != "")
                    {
                        ScheduleDepartment schedule = new ScheduleDepartment();
                        schedule.idSchedule   = scheduleServices.getLastScheduleId();
                        schedule.idDepartment = Int32.Parse(listDepartment[i]);
                        scheduleServices.createScheduleForDepartment(schedule);
                    }
                }

                String[] listPosition = checkedComboBoxEditPosition.EditValue.ToString().Split(',');
                for (int i = 0; i < listPosition.Length; i++)
                {
                    if (listPosition[i].Trim() != "")
                    {
                        SchedulePosition schedule = new SchedulePosition();
                        schedule.idPosition = Int32.Parse(listPosition[i]);
                        schedule.idSchedule = scheduleServices.getLastScheduleId();
                        scheduleServices.createSchedulePosition(schedule);
                    }
                }
            }
        }
Пример #2
0
        public virtual bool SaveFormData(Appointment appointment)
        {
            ScheduleServices scheduleServices = new ScheduleServices();

            appointment.CustomFields["ApprovalStatus"]  = comboBoxEditApprovalStatus.SelectedItem.ToString();
            appointment.CustomFields["DepartmentsList"] = checkedComboBoxEditDepartments.EditValue.ToString();
            //MessageBox.Show("--->"+ checkedComboBoxEditDepartments.EditValue.ToString());
            appointment.CustomFields["PositionList"] = checkedComboBoxEditPosition.EditValue.ToString();

            if (scheduleId.Text.Trim() == "0")
            {
                //MessageBox.Show("Them moi");

                //MessageBox.Show(scheduleServices.getLastScheduleId().ToString());

                /*
                 * String[] listDepartment = checkedComboBoxEditDepartments.EditValue.ToString().Split(',');
                 * for (int i = 0; i < listDepartment.Length; i++)
                 * {
                 *  MessageBox.Show(listDepartment[i]);
                 *  ScheduleDepartment schedule = new ScheduleDepartment();
                 *  schedule.idSchedule = scheduleServices.getLastScheduleId();
                 *  schedule.idDepartment = Int32.Parse(listDepartment[i]);
                 *  scheduleServices.createScheduleForDepartment(schedule);
                 * }*/
            }
            else
            {
                if (schedulePositionTemp.Text.Trim() == "nothing")
                {
                    String[] listPosition = checkedComboBoxEditPosition.EditValue.ToString().Split(',');
                    for (int i = 0; i < listPosition.Length; i++)
                    {
                        if (listPosition[i].Trim() != "")
                        {
                            //MessageBox.Show("--->+"+ listPosition[i]);
                            SchedulePosition schedule = new SchedulePosition();
                            schedule.idPosition = Int32.Parse(listPosition[i]);
                            schedule.idSchedule = Int32.Parse(scheduleId.Text);
                            scheduleServices.createSchedulePosition(schedule);
                        }
                    }
                }
                else
                {
                    String[]      listPosition     = checkedComboBoxEditPosition.EditValue.ToString().Split(',');
                    String[]      listpositionTemp = schedulePositionTemp.Text.Split(',');
                    List <string> listChoose       = new List <string>(listPosition);
                    List <string> listTemp         = new List <string>(listpositionTemp);

                    List <string> listDelete = new List <string>(listpositionTemp);
                    List <string> listInsert = new List <string>(listPosition);

                    listChoose.ForEach(y =>
                    {
                        listTemp.ForEach(x =>
                        {
                            if (y.Trim() == x.Trim())
                            {
                                listInsert.Remove(y);
                                listDelete.Remove(x);
                            }
                        });
                    });

                    listDelete.ForEach(x =>
                    {
                        if (x.Trim() != "")
                        {
                            SchedulePosition schedule = new SchedulePosition();
                            schedule.idSchedule       = Int32.Parse(scheduleId.Text);
                            schedule.idPosition       = Int32.Parse(x);
                            scheduleServices.deleteSchedulePosition(schedule);
                        }
                    });

                    listInsert.ForEach(x =>
                    {
                        SchedulePosition schedule = new SchedulePosition();
                        schedule.idSchedule       = Int32.Parse(scheduleId.Text);
                        schedule.idPosition       = Int32.Parse(x);
                        scheduleServices.createSchedulePosition(schedule);
                    });
                }


                if (scheduleDepartmentTemp.Text.Trim() == "nothing")
                {
                    String[] listDepartment = checkedComboBoxEditDepartments.EditValue.ToString().Split(',');
                    for (int i = 0; i < listDepartment.Length; i++)
                    {
                        if (listDepartment[i].Trim() != "")
                        {
                            ScheduleDepartment schedule = new ScheduleDepartment();
                            schedule.idSchedule   = Int32.Parse(scheduleId.Text);
                            schedule.idDepartment = Int32.Parse(listDepartment[i]);
                            scheduleServices.createScheduleForDepartment(schedule);
                        }
                    }
                }
                else
                {
                    String[]      listDepartment     = checkedComboBoxEditDepartments.EditValue.ToString().Split(',');
                    String[]      listDepartmentTemp = scheduleDepartmentTemp.Text.Split(',');
                    List <string> listChoose         = new List <string>(listDepartment);
                    List <string> listTemp           = new List <string>(listDepartmentTemp);

                    List <string> listDelete = new List <string>(listDepartmentTemp);
                    List <string> listInsert = new List <string>(listDepartment);

                    listChoose.ForEach(y =>
                    {
                        listTemp.ForEach(x =>
                        {
                            if (y.Trim() == x.Trim())
                            {
                                listInsert.Remove(y);
                                listDelete.Remove(x);
                            }
                        });
                    });

                    listDelete.ForEach(x =>
                    {
                        if (x.Trim() != "")
                        {
                            ScheduleDepartment schedule = new ScheduleDepartment();
                            schedule.idSchedule         = Int32.Parse(scheduleId.Text);
                            schedule.idDepartment       = Int32.Parse(x);
                            scheduleServices.deleteScheduleDepartment(schedule);
                        }
                    });

                    listInsert.ForEach(x =>
                    {
                        if (x.Trim() != "")
                        {
                            ScheduleDepartment schedule = new ScheduleDepartment();
                            schedule.idSchedule         = Int32.Parse(scheduleId.Text);
                            schedule.idDepartment       = Int32.Parse(x);
                            scheduleServices.createScheduleForDepartment(schedule);
                        }
                    });
                }
            }
            return(true);
        }