public static async Task <Dictionary <string, int> > PostGenerateDiagram(DiagramDTO dto) { HttpResponseMessage response; using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(DataHolder.ServerAddress); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic"); try { response = await client.PostAsJsonAsync("api/reports/generatediagram", dto); } catch (HttpRequestException ex) { throw new Exception(ex.InnerException.Message); } if (response.IsSuccessStatusCode) { return(await response.Content.ReadAsAsync <Dictionary <string, int> >()); } return(null); } }
public void ProcessCreateNewDiagram() { var databaseID = new ProjectTreeHelper().GetFirstAncestorID <DatabaseDTO>(); if (databaseID == Guid.Empty) { throw new InvalidOperationException("No database selected."); } var newDiagram = new DiagramDTO() { DiagramName = "<Enter name>", DatabaseID = databaseID }; var view = new DiagramDetailsView(); view.Object = newDiagram; var popup = new PopupWindow(); popup.Title = "New Diagram"; popup.Validate = () => { return(new Validator().Validate(newDiagram)); }; popup.ViewPanel.Children.Add(view); if (popup.ShowDialog() == true) { new ObjectDataSource().SaveObject(newDiagram); ServiceLocator serviceLocator = ServiceLocator.GetActive(); serviceLocator.BasicController.ProcessProjectTreeRefresh(); } }
public void BuildFromDiagram(DiagramDTO diagram) { if (diagram == null) { throw new ArgumentNullException("diagram"); } ProcessEntities(diagram); ProcessRelations(diagram); }
private void ReBuild(DiagramDTO diagram) { ChartBuilder cb = new ChartBuilder(); cb.BuildFromDiagram(diagram); if (!diagram.IsAdjusted) { var arranger = new SimpleArranger(); arranger.Arrange(cb.Items, cb.Connections); } SetItems(cb.Items); SetConnections(cb.Connections); }
private void ProcessRelations(DiagramDTO diagram) { var serviceLocator = ServiceLocator.GetActive(); var relations = serviceLocator.RelationInfo.GetDiagramRelations(diagram.ID); foreach (var relation in relations) { var connector = new Connector() { From = _entities[relation.ForeignEntityID], To = _entities[relation.PrimaryEntityID] }; SetConnectorType(relation, connector); _connections.Add(connector); } }
private void ProcessEntities(DiagramDTO diagram) { foreach (var diagramEntity in diagram.Entities) { var entityContainer = new VerticalContainer() { Object = diagramEntity, X = diagramEntity.X, Y = diagramEntity.Y }; // Entity header var entityNameBox = new TextRectangle() { Text = diagramEntity.EntitySchemaPrefixedName, BgColor = Colors.LightCyan }; entityContainer.AddItem(diagramEntity.EntitySchemaPrefixedName, entityNameBox); // Entity attributes foreach (var attr in diagramEntity.Entity.Attributes) { var attrBox = new TextRectangle() { Text = attr.AttributeName }; entityContainer.AddItem(attr.AttributeName, attrBox); } // Sentinel var sentinel = new TextRectangle() { Text = "." }; entityContainer.AddItem("sentinel", sentinel); _items.Add(entityContainer); _entities.Add(diagramEntity.EntityID, entityContainer); // TODO: should not be possible to add a table to the diagram more than once, otherwise fails here. } }
public void ProcessAddNewEntityOnDiagram(DiagramDTO diagram, Point point) { if (diagram == null) { throw new InvalidOperationException("No diagram selected."); } var newEntity = ProcessCreateNewEntity(); if (newEntity != null) { var newDiagramEntity = new DiagramEntityDTO() { DiagramID = diagram.ID, EntityID = newEntity.ID, X = (int)point.X, Y = (int)point.Y }; new ObjectDataSource().SaveObject(newDiagramEntity); } ServiceLocator serviceLocator = ServiceLocator.GetActive(); serviceLocator.BasicController.ProcessProjectTreeRefresh(); }
private async void btnGenerateDiagram_Click(object sender, EventArgs e) { labelErrorDiagram.Visible = false; chartMovement.Series.Clear(); int diagram; int temp1; if (DataHolder.UserCulture.TwoLetterISOLanguageName == "bg") { Enums.DiagramTypeBg diagramType; Enum.TryParse(cbDiagramType.SelectedValue.ToString(), out diagramType); diagram = (int)diagramType; Enums.ItemTypesBg temp; Enum.TryParse(cbItemTypesDiagram.SelectedValue.ToString(), out temp); temp1 = (int)temp; } else { Enums.DiagramType diagramType; Enum.TryParse(cbDiagramType.SelectedValue.ToString(), out diagramType); diagram = (int)diagramType; Enums.ItemTypes temp; Enum.TryParse(cbItemTypesDiagram.SelectedValue.ToString(), out temp); temp1 = (int)temp; } DiagramDTO dto = new DiagramDTO { ReportType = diagram, FromDate = dtFromDiagram.Value, ToDate = dtToDiagram.Value, IsType = cbItemTypeDiagram.Checked, ItemType = temp1 }; List <ReportMovement> result = await SAReports.PostGenerateDiagramMovement(dto); var counter = result.SelectMany(row => row.QuantityesList).Aggregate(0, (current, n) => current + n.Value); // check if everywhere is 0(empty result) if (counter == 0) { labelErrorDiagram.Visible = true; labelErrorDiagram.Text = DataHolder.GetString("no_results_found"); } else { List <ReportMovement> parsedResults = new List <ReportMovement>(); if (!cbItemTypeDiagram.Checked) { foreach (ReportMovement row in result) { if (DataHolder.UserCulture.TwoLetterISOLanguageName == "bg") { int value; int.TryParse(row.Name, out value); Enums.ItemTypesBg types = (Enums.ItemTypesBg)value; ReportMovement element = new ReportMovement(); element.Name = types.ToString(); element.QuantityesList = row.QuantityesList; parsedResults.Add(element); } else { int value; int.TryParse(row.Name, out value); Enums.ItemTypes types = (Enums.ItemTypes)value; ReportMovement element = new ReportMovement(); element.Name = types.ToString(); element.QuantityesList = row.QuantityesList; parsedResults.Add(element); } } foreach (var row in parsedResults) { chartMovement.Series.Add(row.Name); foreach (var rowvalue in row.QuantityesList) { chartMovement.Series[row.Name].Points.AddXY(rowvalue.Key, rowvalue.Value); } } } else { foreach (var row in result) { chartMovement.Series.Add(row.Name); foreach (var rowvalue in row.QuantityesList) { chartMovement.Series[row.Name].Points.AddXY(rowvalue.Key, rowvalue.Value); } } } } }
public List <ReportMovement> PostGenerateDiagramMovement([FromBody] DiagramDTO dto) { return(BLReports.GenerateDiagramMovement(dto)); }
public Dictionary <string, int> PostGenerateDiagram([FromBody] DiagramDTO dto) { return(BLReports.GenerateDiagram(dto)); }
private async void btnGenerateDiagram_Click(object sender, EventArgs e) { labelErrorDiagram.Visible = false; chartSales.Series["Items"].Points.Clear(); int diagram; int temp1; if (DataHolder.UserCulture.TwoLetterISOLanguageName == "bg") { Enums.DiagramTypeBg diagramType; Enum.TryParse(cbDiagramType.SelectedValue.ToString(), out diagramType); diagram = (int)diagramType; Enums.ItemTypesBg temp; Enum.TryParse(cbItemTypesDiagram.SelectedValue.ToString(), out temp); temp1 = (int)temp; } else { Enums.DiagramType diagramType; Enum.TryParse(cbDiagramType.SelectedValue.ToString(), out diagramType); diagram = (int)diagramType; Enums.ItemTypes temp; Enum.TryParse(cbItemTypesDiagram.SelectedValue.ToString(), out temp); temp1 = (int)temp; } DiagramDTO dto = new DiagramDTO { ReportType = diagram, FromDate = dtFromDiagram.Value, ToDate = dtToDiagram.Value, IsType = cbItemTypeDiagram.Checked, ItemType = temp1 }; Dictionary <string, int> result = await SAReports.PostGenerateDiagram(dto); if (result == null || result.Count == 0) { labelErrorDiagram.Visible = true; labelErrorDiagram.Text = DataHolder.GetString("no_results_found"); } else { List <KeyValuePair <string, int> > parsedResults = new List <KeyValuePair <string, int> >(); if (!cbItemTypeDiagram.Checked) { foreach (KeyValuePair <string, int> row in result) { if (DataHolder.UserCulture.TwoLetterISOLanguageName == "bg") { int value; int.TryParse(row.Key, out value); Enums.ItemTypesBg types = (Enums.ItemTypesBg)value; parsedResults.Add(new KeyValuePair <string, int>(types.ToString(), row.Value)); } else { int value; int.TryParse(row.Key, out value); Enums.ItemTypes types = (Enums.ItemTypes)value; parsedResults.Add(new KeyValuePair <string, int>(types.ToString(), row.Value)); } } } else { parsedResults.AddRange(result.Select(row => new KeyValuePair <string, int>(row.Key, row.Value))); } foreach (var row in parsedResults) { chartSales.Series["Items"].Points.AddXY(row.Key, row.Value); } } }
internal static List <ReportMovement> GenerateDiagramMovement(DiagramDTO dto) { DatabaseEntities entities = new DatabaseEntities(); List <ReportMovement> results = new List <ReportMovement>(); if (dto.ToDate <= dto.FromDate) { return(new List <ReportMovement>()); } if (!dto.IsType) { foreach (var type in entities.ItemTypesDDS) { ReportMovement temp = new ReportMovement(); temp.Name = type.Type.ToString(); temp.QuantityesList = new Dictionary <DateTime, int>(); for (var dt = dto.FromDate.Date; dt <= dto.ToDate.Date; dt = dt.AddDays(1)) { temp.QuantityesList.Add(dt, 0); } results.Add(temp); } } else { List <Item> allItems = entities.Items.Where(p => p.Type.Value == dto.ItemType).ToList(); foreach (var item in allItems) { ReportMovement temp = new ReportMovement(); temp.Name = item.Name; temp.QuantityesList = new Dictionary <DateTime, int>(); for (var dt = dto.FromDate.Date; dt <= dto.ToDate.Date; dt = dt.AddDays(1)) { temp.QuantityesList.Add(dt, 0); } results.Add(temp); } } if (dto.ReportType == 0) { List <Purchase> dbSet = new List <Purchase>(entities.Purchases.Where(p => p.Date >= dto.FromDate && p.Date <= dto.ToDate)); foreach (Purchase purchase in dbSet) { if (!dto.IsType) // for all { foreach (var item in purchase.PurchasedItems) { Item dbItem = entities.Items.FirstOrDefault(p => p.ItemId == item.ItemId); ReportMovement element = results.FirstOrDefault(p => p.Name == dbItem.Type.Value.ToString()); if (element != null && dbItem != null && element.QuantityesList.ContainsKey(purchase.Date.Date)) { element.QuantityesList[purchase.Date.Date] = element.QuantityesList[purchase.Date.Date] + item.Quantity; } else { element.QuantityesList[purchase.Date.Date] = element.QuantityesList[purchase.Date.Date] + item.Quantity; } } } else // specific type { foreach (var item in purchase.PurchasedItems) { Item dbItem = entities.Items.FirstOrDefault(p => p.ItemId == item.ItemId); ReportMovement element = results.FirstOrDefault(p => p.Name == dbItem.Name); if (dbItem != null && element != null && dbItem.Type == dto.ItemType) { if (element.QuantityesList.ContainsKey(purchase.Date.Date)) { element.QuantityesList[purchase.Date.Date] = element.QuantityesList[purchase.Date.Date] + item.Quantity; } else { element.QuantityesList[purchase.Date.Date] = element.QuantityesList[purchase.Date.Date] + item.Quantity; } } } } } } else if (dto.ReportType == 1) { List <Sale> dbSet = new List <Sale>(entities.Sales.Where(p => p.Date >= dto.FromDate && p.Date <= dto.ToDate)); foreach (Sale sale in dbSet) { if (!dto.IsType) // for all { foreach (var item in sale.SoldItems) { Item dbItem = entities.Items.FirstOrDefault(p => p.ItemId == item.ItemId); ReportMovement element = results.FirstOrDefault(p => p.Name == dbItem.Type.Value.ToString()); if (element != null && dbItem != null && element.QuantityesList.ContainsKey(sale.Date.Date)) { element.QuantityesList[sale.Date.Date] = element.QuantityesList[sale.Date.Date] + item.Quantity; } else { element.QuantityesList[sale.Date.Date] = element.QuantityesList[sale.Date.Date] + item.Quantity; } } } else // specific type { foreach (var item in sale.SoldItems) { Item dbItem = entities.Items.FirstOrDefault(p => p.ItemId == item.ItemId); ReportMovement element = results.FirstOrDefault(p => p.Name == dbItem.Name); if (dbItem != null && element != null && dbItem.Type == dto.ItemType) { if (element.QuantityesList.ContainsKey(sale.Date.Date)) { element.QuantityesList[sale.Date.Date] = element.QuantityesList[sale.Date.Date] + item.Quantity; } else { element.QuantityesList[sale.Date.Date] = element.QuantityesList[sale.Date.Date] + item.Quantity; } } } } } } else { return(new List <ReportMovement>()); } return(results); }
internal static Dictionary <string, int> GenerateDiagram(DiagramDTO dto) { Dictionary <string, int> results = new Dictionary <string, int>(); DatabaseEntities entities = new DatabaseEntities(); if (dto.ReportType == 0) { List <Purchase> dbSet = new List <Purchase>(entities.Purchases.Where(p => p.Date >= dto.FromDate && p.Date <= dto.ToDate)); foreach (Purchase purchase in dbSet) { if (!dto.IsType) // for all { foreach (var item in purchase.PurchasedItems) { Item dbItem = entities.Items.FirstOrDefault(p => p.ItemId == item.ItemId); if (dbItem != null && results.ContainsKey(dbItem.Type.Value.ToString())) { results[dbItem.Type.ToString()] = (int)(results[dbItem.Type.ToString()] + item.Quantity * item.Price); } else { if (dbItem != null) { results.Add(dbItem.Type.ToString(), (int)(item.Quantity * item.Price)); } } } } else // specific type { foreach (var item in purchase.PurchasedItems) { Item dbItem = entities.Items.FirstOrDefault(p => p.ItemId == item.ItemId); if (dbItem != null && dbItem.Type == dto.ItemType) { if (results.ContainsKey(dbItem.Name)) { results[dbItem.Name] = (int)(results[dbItem.Name] + item.Quantity * item.Price); } else { results.Add(dbItem.Name, (int)(item.Quantity * item.Price)); } } } } } } else if (dto.ReportType == 1) { List <Sale> dbSet = new List <Sale>(entities.Sales.Where(p => p.Date >= dto.FromDate && p.Date <= dto.ToDate)); foreach (Sale purchase in dbSet) { if (!dto.IsType) // for all { foreach (var item in purchase.SoldItems) { Item dbItem = entities.Items.FirstOrDefault(p => p.ItemId == item.ItemId); if (dbItem != null && results.ContainsKey(dbItem.Type.Value.ToString())) { results[dbItem.Type.ToString()] = (int)(results[dbItem.Type.ToString()] + item.Quantity * item.Price); } else { if (dbItem != null) { results.Add(dbItem.Type.ToString(), (int)(item.Quantity * item.Price)); } } } } else // specific type { foreach (var item in purchase.SoldItems) { Item dbItem = entities.Items.FirstOrDefault(p => p.ItemId == item.ItemId); if (dbItem != null && dbItem.Type == dto.ItemType) { if (results.ContainsKey(dbItem.Name)) { results[dbItem.Name] = (int)(results[dbItem.Name] + item.Quantity * item.Price); } else { results.Add(dbItem.Name, (int)(item.Quantity * item.Price)); } } } } } } else { return(null); } return(results); }