示例#1
0
        private void CreateTaskInBd(TaskM task, int id_group)
        {
            using (var sqlCmd = MainPluginClass.App.SqlWork())
            {
                if (task.TypeTask == ETypeTask.route)
                {
                    sqlCmd.sql = String.Format(@"INSERT INTO autobase.waybills_tasks(car_id, time_from, time_till, route_id, type_id, external_id, group_id) 
VALUES ({0}, @time_from, @time_till, {1}, {2}, {3}, @group_id);
",
                                               task.IdCar, task.IdTaskObj, task.IdType, task.IdMT);
                    sqlCmd.AddParam("@time_from", _begin_date, System.Data.DbType.DateTime);
                    sqlCmd.AddParam("@time_till", _end_date, System.Data.DbType.DateTime);
                    sqlCmd.AddParam("@group_id", id_group, System.Data.DbType.Int32);
                    sqlCmd.ExecuteNonQuery();
                }
                if (task.TypeTask == ETypeTask.zone)
                {
                    sqlCmd.sql = String.Format(@"INSERT INTO autobase.waybills_tasks(car_id, time_from, time_till, zone_id, type_id, external_id, group_id) 
VALUES ({0}, @time_from, @time_till, {1}, {2}, {3}, @group_id);
",
                                               task.IdCar, task.IdTaskObj, task.IdType, task.IdMT);
                    sqlCmd.AddParam("@time_from", _begin_date, System.Data.DbType.DateTime);
                    sqlCmd.AddParam("@time_till", _end_date, System.Data.DbType.DateTime);
                    sqlCmd.AddParam("@group_id", id_group, System.Data.DbType.Int32);
                    sqlCmd.ExecuteNonQuery();
                }
            }
        }
示例#2
0
        private void CreateTasks(object obj)
        {
            if (!CanCreateTasks(null))
            {
                return;
            }
            //TimeSpan duration = _end_date - _begin_date;
            //if (duration <= new TimeSpan(0, 1, 0, 0) ||
            //    duration > new TimeSpan(1, 0, 0, 0))
            //{
            //    MessageBox.Show("Указан некорректный период!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Stop);
            //    return;
            //}
            if (_end_date < _begin_date)
            {
                MessageBox.Show("Дата начала должна быть раньше чем дата конца", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Stop);
                return;
            }
            string proc = null;

            try
            {
                proc = MainPluginClass.Work.OpenForm.ProcOpen("create_task");
                int group_id    = CreateTasksGroupe();
                var selectedOdh = Odhs.Where(w => w.Selected).ToList();
                foreach (var odh in selectedOdh)
                {
                    foreach (var item in WorkTypes)
                    {
                        foreach (var car in item.Cars.Where(w => w.Selected))
                        {
                            int   mt_id = CreateTaskInMt(odh, item, car.ExternalId, true);
                            TaskM task  = new TaskM(-1, car.Id, _begin_date, _end_date, odh.Id, item.Id, mt_id, ETypeTask.route);
                            CreateTaskInBd(task, group_id);
                        }
                    }
                }
                var selectedZones = Zones.Where(w => w.Selected).ToList();
                foreach (var zone in selectedZones)
                {
                    foreach (var item in WorkTypes)
                    {
                        foreach (var car in item.Cars.Where(w => w.Selected))
                        {
                            int   mt_id = CreateTaskInMt(zone, item, car.ExternalId, false);
                            TaskM task  = new TaskM(-1, car.Id, _begin_date, _end_date, zone.Id, item.Id, mt_id, ETypeTask.zone);
                            CreateTaskInBd(task, group_id);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MainPluginClass.Work.OpenForm.ProcClose(proc);
                MessageBox.Show("Ошибка: " + ex.Message, "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                MainPluginClass.Work.OpenForm.ProcClose(proc);
            }
            OnPropertyChanged("CloseCmd");
        }