Beispiel #1
0
        public DailyBudgetMacroInfo ImportElguideServices()
        {
            try
            {
                DailyBudgetMacroInfo budgetInfo = new DailyBudgetMacroInfo();

                string[] listOfFiles = new string[] { "inegoAV.csv", "inegoTele.csv", "inegoComp.csv" };

                foreach (string file in listOfFiles)
                {
                    if (!File.Exists(main.appConfig.csvElguideExportFolder + file))
                    {
                        Log.n("Fant ikke " + file, Color.Red);
                        return null;
                    }
                    else if (File.GetLastWriteTime(main.appConfig.csvElguideExportFolder + file).Date != DateTime.Now.Date)
                    {
                        Log.n("Avbryter importering av " + file + " fordi filen er ikke oppdatert!", Color.Red);
                        return null;
                    }

                    string[] Lines = File.ReadAllLines(main.appConfig.csvElguideExportFolder + file);
                    string[] Fields;
                    Fields = Lines[0].Split(new char[] { ';' });
                    int Cols = Fields.GetLength(0);
                    DataTable dt = new DataTable();
                    //1st row must be column names; force lower case to ensure matching later on.
                    for (int i = 0; i < Cols; i++)
                        dt.Columns.Add(Fields[i].ToLower(), typeof(string));
                    DataRow Row;
                    for (int i = 1; i < Lines.GetLength(0); i++)
                    {
                        Fields = Lines[i].Split(new char[] { ';' });
                        Row = dt.NewRow();
                        for (int f = 0; f < Cols; f++)
                            Row[f] = Fields[f];
                        dt.Rows.Add(Row);
                    }

                    if (dt.Rows.Count < 2)
                    {
                        Log.n("Sales CSV fil (" + file + ") var for kort. " + dt.Rows.Count + " linjer.", Color.Red);
                        return null;
                    }

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {

                        if (dt.Rows[i][0].ToString().Contains("580"))
                        {
                            DailyBudgetMacroInfoItem salg = new DailyBudgetMacroInfoItem();
                            salg.Type = "Computing";
                            salg.Antall = Convert.ToInt32(dt.Rows[i][1].ToString());
                            salg.Btokr = Convert.ToDouble(dt.Rows[i][4].ToString());
                            salg.Salgspris = Convert.ToDouble(dt.Rows[i][2].ToString());
                            budgetInfo.Salg.Add(salg);
                            Log.d("Fant " + salg.Type + ": " + salg.Antall + " - " + salg.Btokr + " - " + salg.Salgspris);
                            continue;
                        }

                        if (dt.Rows[i][0].ToString().Contains("480"))
                        {
                            DailyBudgetMacroInfoItem salg = new DailyBudgetMacroInfoItem();
                            salg.Type = "Telecom";
                            salg.Antall = Convert.ToInt32(dt.Rows[i][1].ToString());
                            salg.Btokr = Convert.ToDouble(dt.Rows[i][4].ToString());
                            salg.Salgspris = Convert.ToDouble(dt.Rows[i][2].ToString());
                            budgetInfo.Salg.Add(salg);
                            Log.d("Fant " + salg.Type + ": " + salg.Antall + " - " + salg.Btokr + " - " + salg.Salgspris);
                            continue;
                        }

                        if (dt.Rows[i][0].ToString().Contains("280"))
                        {
                            DailyBudgetMacroInfoItem salg = new DailyBudgetMacroInfoItem();
                            salg.Type = "AudioVideo";
                            salg.Antall = Convert.ToInt32(dt.Rows[i][1].ToString());
                            salg.Btokr = Convert.ToDouble(dt.Rows[i][4].ToString());
                            salg.Salgspris = Convert.ToDouble(dt.Rows[i][2].ToString());
                            budgetInfo.Salg.Add(salg);
                            Log.d("Fant " + salg.Type + ": " + salg.Antall + " - " + salg.Btokr + " - " + salg.Salgspris);
                            continue;
                        }
                    }
                }
                return budgetInfo;
            }
            catch (Exception ex)
            {
                Log.Unhandled(ex);
                Log.n("Feil oppstod under importering av tjeneste CSV fra Elguide", Color.Red);
            }
            return null;
        }
Beispiel #2
0
        private void MakeDailyBudgetFromElguide(DailyBudgetMacroInfo budgetInfo)
        {
            try
            {
                if (main.tableMacroQuick == null || main.tableMacroQuick.Rows.Count < 5)
                {
                    AddWarning("Mangler tall fra Elguide eller CSV er gammel. Eksporter på nytt fra meny 136 i Elguide og prøv igjen");
                    return;
                }

                for (int f = 0; f < main.tableMacroQuick.Rows.Count; f++)
                {
                    int intAvd = Convert.ToInt32(main.tableMacroQuick.Rows[f][0]);

                    AddTable_Start("Dagens tall for " + main.avdeling.Get(Convert.ToInt32(main.tableMacroQuick.Rows[f]["Favoritt"].ToString()))
                        + " - " + DateTime.Now.ToString("dddd d. MMMM yyyy  HH:mm", FormMain.norway) + ")");

                    AddTable_Header_Start();
                    AddTable_Header_Name("Category", 95, "", Sorter_Type_Text);

                    AddTable_Header_Name("Salg", 60, "", Sorter_Type_Text);
                    AddTable_Header_Name("Omset", 60, "", Sorter_Type_Digit);
                    AddTable_Header_Name("Fritt", 60, "", Sorter_Type_Digit);

                    AddTable_Header_Name("Inntjen.", 60, "", Sorter_Type_Digit);
                    AddTable_Header_Name("Margin", 60, "", Sorter_Type_Procent);
                    AddTable_Header_Name("Rabatt", 60, "", Sorter_Type_Digit);

                    if (main.appConfig.macroImportQuickSales
                        && intAvd == main.appConfig.Avdeling
                        && budgetInfo != null
                        && budgetInfo.Salg != null)
                    {
                        if (budgetInfo.Salg.Count > 0)
                        {
                            AddTable_Header_Name("RTG/SA", 60, "background:#80c34a;", Sorter_Type_Digit);
                            AddTable_Header_Name("Omset.", 60, "background:#80c34a;", Sorter_Type_Digit);
                            AddTable_Header_Name("Inntjen.", 60, "background:#80c34a;", Sorter_Type_Digit);
                            AddTable_Header_Name("%", 60, "background:#80c34a;", Sorter_Type_Digit, "Btokr. inntjen. Tjenester / Btokr. inntjen. alle varer");
                        }
                    }

                    AddTable_Header_End();

                    AddTable_Body_Start();

                    double KgsaAntallTot = 0, KgsaBtokrTot = 0, KgsaSalgsprisTot = 0;
                    for (int i = f; i < main.tableMacroQuick.Rows.Count; i++)
                    {
                        if (intAvd != (Convert.ToInt32(main.tableMacroQuick.Rows[i][0])))
                        {
                            f--;
                            break;
                        }
                        f++;

                        if (main.tableMacroQuick.Rows.Count == i + 1 || main.tableMacroQuick.Rows[i]["Avdeling"].ToString() == "TOTALT") // siste row
                        {
                            AddTable_Body_End();
                            AddTable_Footer_Start();
                        }

                        AddTable_Row_Cell(main.tableMacroQuick.Rows[i]["Avdeling"].ToString(), "", Class_Style_Text_Cat);

                        AddTable_Row_Cell(main.tools.NumberStyle_Normal(main.tableMacroQuick.Rows[i]["Salg"], 0, "", true), "", Class_Style_Small);
                        AddTable_Row_Cell(main.tools.NumberStyle_Normal(main.tableMacroQuick.Rows[i]["Omsetn"], 0, "", true), "", Class_Style_Generic);
                        AddTable_Row_Cell(main.tools.NumberStyle_Normal(main.tableMacroQuick.Rows[i]["Fritt"], 0, "", true), "", Class_Style_Generic);

                        AddTable_Row_Cell(main.tools.NumberStyle_Normal(main.tableMacroQuick.Rows[i]["Fortjeneste"], 0, "", true), "", Class_Style_Generic);
                        AddTable_Row_Cell(main.tools.NumberStyle_Percent(main.tableMacroQuick.Rows[i]["Margin"], 100, true, false, 0), "", Class_Style_Percent);
                        AddTable_Row_Cell(main.tools.NumberStyle_Normal(main.tableMacroQuick.Rows[i]["Rabatt"], 0, "", true), "", Class_Style_Generic);

                        if (main.appConfig.macroImportQuickSales
                            && intAvd == main.appConfig.Avdeling
                            && budgetInfo != null
                            && budgetInfo.Salg != null)
                        {
                            try
                            {
                                if (budgetInfo.Salg.Count > 0)
                                {
                                    if ("TOTALT" == main.tableMacroQuick.Rows[i]["Avdeling"].ToString())
                                    {
                                        AddTable_Row_Cell(main.tools.NumberStyle_Normal(KgsaAntallTot, 0), "", Class_Style_Small);
                                        AddTable_Row_Cell(main.tools.NumberStyle_Normal(KgsaSalgsprisTot, 0), "", Class_Style_Generic);
                                        AddTable_Row_Cell(main.tools.NumberStyle_Normal(KgsaBtokrTot, 0), "", Class_Style_Generic);
                                        AddTable_Row_Cell(main.tools.NumberStyle_Percent(KgsaBtokrTot, main.tableMacroQuick.Rows[i]["Fortjeneste"]), "", Class_Style_Percent);
                                    }
                                    else
                                    {
                                        bool found = false;
                                        foreach (DailyBudgetMacroInfoItem item in budgetInfo.Salg)
                                        {
                                            if (item.Type == main.tableMacroQuick.Rows[i]["Avdeling"].ToString())
                                            {
                                                AddTable_Row_Cell(main.tools.NumberStyle_Normal(item.Antall, 0), "", Class_Style_Small);
                                                KgsaAntallTot += item.Antall;
                                                AddTable_Row_Cell(main.tools.NumberStyle_Normal(item.Salgspris, 0), "", Class_Style_Generic);
                                                KgsaSalgsprisTot += item.Salgspris;
                                                AddTable_Row_Cell(main.tools.NumberStyle_Normal(item.Btokr, 0), "", Class_Style_Generic);
                                                KgsaBtokrTot += item.Btokr;
                                                AddTable_Row_Cell(main.tools.NumberStyle_Percent((decimal)item.Btokr, Convert.ToDecimal(main.tableMacroQuick.Rows[i]["Fortjeneste"]),
                                                        true, false, 0), "", Class_Style_Percent);

                                                found = true;
                                                break;
                                            }
                                        }
                                        if (!found)
                                        {
                                            AddTable_Row_Cell(main.tools.NumberStyle_Normal(0, 0), "", Class_Style_Small);
                                            AddTable_Row_Cell(main.tools.NumberStyle_Normal(0, 0), "", Class_Style_Generic);
                                            AddTable_Row_Cell(main.tools.NumberStyle_Normal(0, 0), "", Class_Style_Generic);
                                            AddTable_Row_Cell(main.tools.NumberStyle_Percent(0, 100), "", Class_Style_Percent);
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Log.Unhandled(ex);
                                Log.n("Unntak ved skriving av RTGSA salg: " + ex.Message, Color.Red);
                            }
                        }

                        AddTable_Row_End();

                        if (main.tableMacroQuick.Rows.Count == i + 1 || main.tableMacroQuick.Rows[i]["Avdeling"].ToString() == "TOTALT") // siste row
                            AddTable_Footer_End();

                    }

                    AddTable_End();
                }
            }
            catch (Exception ex)
            {
                Log.Unhandled(ex);
                Log.n("Uventet feil oppstod under generering av daglig budsjett tabellen", Color.Red);
            }
        }