void DrawItemsEditView()
 {
     if (GUILayout.Button("Select List",GUILayout.ExpandWidth(false)))
         OpenItemsList();
     if (mItemsList == null)
         return;
     if (GUILayout.Button("Save", GUILayout.ExpandWidth(false)))
         EditorUtility.SetDirty(mItemsList);
     itemNames = new string[mItemsList.AllItems.Count];
     for(int i = 0; i<mItemsList.AllItems.Count;i++)
         itemNames[i] = mItemsList.AllItems[i].name;
     GUILayout.Space(10);
     GUILayout.Label(mItemsList.name, EditorStyles.boldLabel);
     GUILayout.BeginHorizontal();
     if (GUILayout.Button("Create New", GUILayout.ExpandWidth(false)))
         AddNewItem();
     if (GUILayout.Button("Remove Selected", GUILayout.ExpandWidth(false)))
         RemoveSelectedItem();
     GUILayout.EndHorizontal();
     creatinItemType = (Enums.ItemTypes)EditorGUILayout.EnumPopup(creatinItemType, GUILayout.MaxWidth(100));
     if (selectedItemIndex >= mItemsList.AllItems.Count)
         selectedItemIndex = mItemsList.AllItems.Count - 1;
     selectedItemIndex = GUILayout.SelectionGrid(selectedItemIndex, itemNames, 10,GUILayout.ExpandWidth(false));
     DrawSelectedItem();
 }
        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);
                        }
                    }
                }
            }
        }
        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);
                }
            }
        }