private void DoGood_Click(object sender, EventArgs e) { ReportTree.Nodes.Clear(); var lines = File.ReadAllLines(pathToMainBill, Encoding.UTF8); var bills = lines.Select(x => new Bill(x)); TradePoints = new List <TradePoint>(); foreach (var bill in bills) { var currentGroup = TradePoints.FirstOrDefault(x => x.GroupDesc == bill.Desc); if (currentGroup == null) { currentGroup = new TradePoint(bill.Desc, bill.Currency); TradePoints.Add(currentGroup); } currentGroup.Bills.Add(bill); } TradePoints = TradePoints.OrderByDescending(x => x.MainSumm).ToList(); SpendingGroups.ForEach(x => ReportTree.Nodes.Add(CreateTreeNode(x))); var otherNode = new TreeNode($"Остальное. Сумма: {TradePoints.Sum(x => x.MainSumm)}. Счетов: {TradePoints.Sum(x => x.Bills.Count())}"); TradePoints.ForEach(x => otherNode.Nodes.Add(x.Guid.ToString(), x.ToString())); ReportTree.Nodes.Add(otherNode); }
private void ApplyChangesBy(TradePoint tradePoint) { tradePoint.Name = textBoxes[0].Text; tradePoint.Type = comboBoxes[0].SelectedItem as TradePointType; try { tradePoint.Size = Int32.Parse(textBoxes[1].Text); } catch (Exception ex) { tradePoint.Size = 0; } try { tradePoint.NumberOfCounters = Int32.Parse(textBoxes[2].Text); } catch (Exception ex) { tradePoint.NumberOfCounters = 0; } if (tradePoint.Id < 0) { TradePointsController.GetInstance().AddTradePoint(tradePoint); } else { TradePointsController.GetInstance().EditTradePoint(tradePoint); } }
public TradePoint GetParent(TradePoint tradePoint) { var sqlResult = ServerHandler.GetInstance().GetRequest("TradePoints/GetParent/" + tradePoint.Id.ToString()).Result; if (sqlResult.Exception.Length != 0) { throw new Exception(sqlResult.Exception); } List <TradePoint> result = new List <TradePoint>(); for (int i = 0; i < sqlResult.Rows.Count; ++i) { result.Add(GetTradePointFromRow(sqlResult.Rows[i])); } if (result.Count == 0) { return(null); } TradePoint res; try { res = result.First(); } catch (Exception ex) { res = null; } return(res); }
public bool Delete(TradePoint point) { if (point.Id < 0) { return(false); } SQLConnectionHandler.GetInstance() .Execute(SQLCommand.DeleteTradePoint(point), true); return(true); }
private async Task <TradePointType> GetOrCreateType(TradePoint loadedTradePoint) { var type = await applicationDbContext.TradePointTypes .FirstOrDefaultAsync(t => t.Name == loadedTradePoint.Type.Name).ConfigureAwait(false) ?? new TradePointType { Id = Guid.NewGuid(), Name = loadedTradePoint.Type.Name }; return(type); }
public SuppliesUC() { InitializeComponent(); List <TradePoint> tradePointsList = TradePointsController.GetInstance().GetTradePoints(); tradePointsList.Sort((x, y) => x.FullName.CompareTo(y.FullName)); TradePoints = new ObservableCollection <TradePoint>(tradePointsList); Binding bind1 = new Binding(); bind1.Source = TradePoints; TradePointComboBox.DisplayMemberPath = "FullName"; TradePointComboBox.SetBinding(ComboBox.ItemsSourceProperty, bind1); TradePoint = TradePoints.FirstOrDefault(); TradePointComboBox.SelectedItem = TradePoint; List <Product> productsList = ProductsController.GetInstance().GetProducts(); Products = new ObservableCollection <Product>(productsList); Binding bind2 = new Binding(); bind2.Source = Products; ProductComboBox.DisplayMemberPath = "Name"; ProductComboBox.SetBinding(ComboBox.ItemsSourceProperty, bind2); Product = Products.FirstOrDefault(); ProductComboBox.SelectedItem = Product; List <Supplier> suppliersList = SuppliersController.GetInstance().GetSuppliers(); Suppliers = new ObservableCollection <Supplier>(suppliersList); Binding bind3 = new Binding(); bind3.Source = Suppliers; SupplierComboBox.DisplayMemberPath = "Name"; SupplierComboBox.SetBinding(ComboBox.ItemsSourceProperty, bind3); Supplier = Suppliers.FirstOrDefault(); SupplierComboBox.SelectedItem = Supplier; List <Order> ordersList = OrdersController.GetInstance().GetOrders(); Orders = new ObservableCollection <Order>(ordersList); Binding bind4 = new Binding(); bind4.Source = Orders; OrderComboBox.DisplayMemberPath = "Id"; OrderComboBox.SetBinding(ComboBox.ItemsSourceProperty, bind4); Order = Orders.FirstOrDefault(); OrderComboBox.SelectedItem = Order; }
private void AddFieldsBy(TradePoint point) { TextBox nameTB = new TextBox() { Text = point.Name, Margin = new Thickness(5, 5, 5, 5), Width = 200 }; List <TradePointType> tradePointsTypes = TradePointsController.GetInstance().GetTradePointTypes(); TradePointType currTradePointType; try { currTradePointType = point.Type == null?tradePointsTypes.First() : tradePointsTypes.Find(x => x.Id == point.Type.Id); } catch (Exception ex) { currTradePointType = null; } ComboBox typeCB = GetComboBoxOnData(tradePointsTypes.ToList <object>(), currTradePointType, "Name"); TextBox sizeTB = new TextBox() { Text = point.Size.ToString(), Margin = new Thickness(5, 5, 5, 5), Width = 200 }; sizeTB.PreviewTextInput += NumberValidationTextBox; TextBox numOfCountersTB = new TextBox() { Text = point.NumberOfCounters.ToString(), Margin = new Thickness(5, 5, 5, 5), Width = 200 }; numOfCountersTB.PreviewTextInput += NumberValidationTextBox; List <TradePoint> tradePoints = TradePointsController.GetInstance().GetParents(); TradePoint currParent = TradePointsController.GetInstance().GetParent(point); currParent = currParent == null ? null : tradePoints.Find(x => x.Id == currParent.Id); ComboBox parentCB = GetComboBoxOnData(tradePoints.ToList <object>(), currParent, "FullName"); Elements.Children.Add(nameTB); Elements.Children.Add(typeCB); Elements.Children.Add(sizeTB); Elements.Children.Add(numOfCountersTB); Elements.Children.Add(parentCB); textBoxes.Add(nameTB); comboBoxes.Add(typeCB); textBoxes.Add(sizeTB); textBoxes.Add(numOfCountersTB); comboBoxes.Add(parentCB); }
public async Task <(IEnumerable <TradePoint>, Error[])> HandleAsync(DataFile dataFile) { var tradePoints = new List <TradePoint>(); using (var ms = new MemoryStream(dataFile.Content)) { using (var textReader = new StreamReader(ms)) { var lineNumber = 0; try { string line; while ((line = await textReader.ReadLineAsync().ConfigureAwait(false)) != null) { var map = new Dictionary <string, string>(); var expressions = line.TrimEnd(';').Split(';'); foreach (var expression in expressions) { var property = expression.Split('='); map[property[0]] = property[1]; } var tradePoint = new TradePoint { Id = Guid.Parse(map[nameof(TradePoint.Id)]), Name = map[nameof(TradePoint.Name)], Type = new TradePointType { Id = Guid.Parse(map[$"Type{nameof(TradePointType.Id)}"]), Name = map[$"Type{nameof(TradePointType.Name)}"] }, Location = new Location { Latitude = double.Parse(map[nameof(Location.Latitude)]), Longitude = double.Parse(map[nameof(Location.Longitude)]) } }; tradePoints.Add(tradePoint); lineNumber++; } } catch (Exception) { return(null, Error.Create("InvalidSyntax", $"Invalid syntax at line {lineNumber}")); } return(tradePoints, Error.NoError); } } }
public void DeleteTradePoint(TradePoint tradePoint) { if (tradePoint == null) { return; } try { bool res = ServerHandler.GetInstance().PostRequest("TradePoints/Delete", tradePoint); } catch (Exception ex) { return; } }
internal void AddTradePoint(TradePoint tradePoint) { if (tradePoint == null) { return; } try { bool res = ServerHandler.GetInstance().PostRequest("TradePoints/Insert", tradePoint); } catch (Exception ex) { return; } }
internal List <TradePointProduct> GetTradePointProducts(TradePoint tradePoint) { var sqlResult = ServerHandler.GetInstance().GetRequest("TradePointsProducts/Get/" + tradePoint.Id).Result; if (sqlResult.Exception.Length != 0) { throw new Exception(sqlResult.Exception); } List <TradePointProduct> result = new List <TradePointProduct>(); for (int i = 0; i < sqlResult.Rows.Count; ++i) { result.Add(GetTradePointProductFromRow(sqlResult.Rows[i])); } return(result); }
public TradePointsRequestsUC() { InitializeComponent(); List <TradePoint> tradePointsList = TradePointsController.GetInstance().GetTradePoints(); tradePointsList.Sort((x, y) => x.FullName.CompareTo(y.FullName)); TradePoints = new ObservableCollection <TradePoint>(tradePointsList); Binding bind = new Binding(); bind.Source = TradePoints; TradePointComboBox.DisplayMemberPath = "FullName"; TradePointComboBox.SetBinding(ComboBox.ItemsSourceProperty, bind); TradePoint = TradePoints.FirstOrDefault(); TradePointComboBox.SelectedItem = TradePoint; }
internal List <Supply> GetSupplies(TradePoint tradePoint) { return(new List <Supply>()); }
public static String DeleteTradePoint(TradePoint point) { return(GetCommand(ref deleteTradePoint, deleteTradePointPath, new string[] { point.Id.ToString() })); }
public static String UpdateTradePoint(TradePoint point) { return(GetCommand(ref updateTradePoint, updateTradePointPath, new string[] { point.Name, point.Type.Id.ToString(), point.Size.ToString(), point.NumberOfCounters.ToString(), point.Id.ToString() })); }
public bool Insert(TradePoint point) { SQLConnectionHandler.GetInstance() .Execute(SQLCommand.InsertTradePoint(point), true); return(true); }