private void CreateRouteToDb(string name) { int id_route = -1; using (var sqlCmd = MainPluginClass.App.SqlWork()) { sqlCmd.sql = "INSERT INTO autobase.waybills_tasks_ways_groups (name, org_id) VALUES (@name, @org_id) returning gid;"; sqlCmd.AddParam(new Params("@name", name, NpgsqlTypes.NpgsqlDbType.Text)); sqlCmd.AddParam(new Params("@org_id", _id_org, NpgsqlTypes.NpgsqlDbType.Integer)); id_route = sqlCmd.ExecuteScalar <int>(); } if (id_route > 0) { using (var sqlCmd = MainPluginClass.App.SqlWork()) { foreach (var item in Odhs.Where(w => w.Selected)) { sqlCmd.sql = String.Format("INSERT INTO autobase.waybills_tasks_ways (group_id, route_id) VALUES ({0}, {1});", id_route, item.Id); sqlCmd.ExecuteNonQuery(); } foreach (var item in Zones.Where(w => w.Selected)) { sqlCmd.sql = String.Format("INSERT INTO autobase.waybills_tasks_ways (group_id, zone_id) VALUES ({0}, {1});", id_route, item.Id); sqlCmd.ExecuteNonQuery(); } } } LoadRoutes(); }
private void LoadGroups() { this._groups.Clear(); using (var sqlCmd = MainPluginClass.App.SqlWork()) { sqlCmd.sql = string.Format(@"SELECT wtg.gid, wtg.name, ARRAY(SELECT route_id FROM autobase.waybills_tasks_ways WHERE group_id = wtg.gid AND route_id is not null) as routes, ARRAY(SELECT zone_id FROM autobase.waybills_tasks_ways WHERE group_id = wtg.gid AND zone_id is not null) as zones FROM autobase.waybills_tasks_ways_groups wtg WHERE wtg.gid in (SELECT * FROM autobase.get_access_ways_groups()) ORDER BY name;", _id_org); sqlCmd.ExecuteReader(); while (sqlCmd.CanRead()) { RouteM route = new RouteM(sqlCmd.GetValue <int>("gid"), sqlCmd.GetValue <string>("name"), _id_org); var odhs = sqlCmd.GetValue <int[]>("routes").ToList(); foreach (var item in odhs) { route.Odhs.Add(Odhs.FirstOrDefault(w => w.Id == item)); } var zones = sqlCmd.GetValue <int[]>("zones").ToList(); foreach (var item in zones) { route.Zones.Add(Zones.FirstOrDefault(w => w.Id == item)); } _groups.Add(route); } } }
private void SaveRoute(object obj) { if (!CanSaveRoute(obj)) { return; } if (MessageBox.Show("Вы действительно хотите пересохранить выбранный маршрут?", "Сохранение маршрута", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { using (var sqlCmd = MainPluginClass.App.SqlWork()) { sqlCmd.sql = String.Format("DELETE FROM autobase.waybills_tasks_ways WHERE group_id={0};", SelectedRoute.Id); sqlCmd.ExecuteNonQuery(); foreach (var item in Odhs.Where(w => w.Selected)) { sqlCmd.sql = String.Format("INSERT INTO autobase.waybills_tasks_ways (group_id, route_id) VALUES ({0}, {1});", SelectedRoute.Id, item.Id); sqlCmd.ExecuteNonQuery(); } foreach (var item in Zones.Where(w => w.Selected)) { sqlCmd.sql = String.Format("INSERT INTO autobase.waybills_tasks_ways (group_id, zone_id) VALUES ({0}, {1});", SelectedRoute.Id, item.Id); sqlCmd.ExecuteNonQuery(); } } LoadRoutes(); } }
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"); }
private bool CanCreateTasks(object obj) { return((Odhs.FirstOrDefault(w => w.Selected) != null || Zones.FirstOrDefault(w => w.Selected) != null) && (FindWorkTypes.Count(w => (w.Cars.Count(q => q.Selected) > 0)) > 0)); }
private void OdhsFind(string _find_odhs_text) { FindOdhs = new ObservableCollection <TaskGeomM>(Odhs.Where(w => w.Name.ToUpper().Contains(_find_odhs_text.ToUpper())).OrderByDescending(w => w.Selected)); }
private bool CanCreateRoute(object obj) { return((Odhs.FirstOrDefault(w => w.Selected) != null) || (Zones.FirstOrDefault(w => w.Selected) != null)); }
private bool CanSaveRoute(object obj) { return(((Odhs.FirstOrDefault(w => w.Selected) != null) || (Zones.FirstOrDefault(w => w.Selected) != null)) && SelectedRoute != null); }
private void OdhsFind(string text) { FindOdhs = new ObservableCollection <TaskGeomM>(Odhs.Where(w => w.Name.ToUpper().Contains(text.ToUpper())).OrderByDescending(w => w.Selected)); OnPropertyChanged("CountOdh"); }