Beispiel #1
0
        private void FormatTextInput(TextBox box, BudgetValueType type)
        {
            decimal value = 0;
            if (!decimal.TryParse(box.Text, out value))
            {
                box.Text = "";
                return;
            }

            if (type == BudgetValueType.Omsetning || type == BudgetValueType.Inntjening)
                box.Text = Math.Round(value, 0).ToString("#,##0");
            else if (type == BudgetValueType.SoM || type == BudgetValueType.SoB)
                box.Text = Math.Round(value, 2).ToString("#,##0.00");
            else
                box.Text = value.ToString();
        }
Beispiel #2
0
        private void FormatTextKeyEnter(TextBox box, KeyEventArgs e, BudgetValueType type)
        {
            if (e.KeyCode == Keys.Enter)
            {
                FormatTextInput(box, type);

                if (box.Text.Length > 0)
                {
                    box.SelectionStart = box.Text.Length;
                    box.SelectionLength = 0;
                }

                e.Handled = true;
                e.SuppressKeyPress = true;
            }
        }
Beispiel #3
0
 public KgsaBudgetProduct(BudgetType product, BudgetValueType type)
 {
     this.product = product;
     this.mainType = type;
     fields = new List<KgsaBudgetField>() { };
 }
Beispiel #4
0
        private DataTable MakeTableBudgetProduct(BudgetCategory cat, BudgetType product, BudgetValueType type)
        {
            try
            {
                DataTable dtWork = ReadyTableProductNew();

                sqlce = main.database.CallMonthTable(dtTil, main.appConfig.Avdeling);
                if (sqlce.Rows.Count == 0)
                    return dtWork;

                string strSel = ""; DataRow[] rowsSel;
                for (int i = 0; i < budgetInfo.selgere.Count; i++)
                    strSel += " OR Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'";
                strSel = strSel.Substring(4, strSel.Length - 4);
                rowsSel = sqlce.Select(strSel + " AND (Dato >= '" + dtFra.ToString("yyy-MM-dd") + "' AND Dato <= '" + dtTil.ToString("yyy-MM-dd") + "')");
                DataTable dtSel = rowsSel.Any() ? rowsSel.CopyToDataTable() : sqlce.Clone();

                object r;
                decimal omset_total = 0, inntjen_total = 0, omsetExMva_total = 0;
                int d = 0;
                if (cat == BudgetCategory.MDA)
                    d = 1;
                else if (cat == BudgetCategory.AudioVideo)
                    d = 2;
                else if (cat == BudgetCategory.SDA)
                    d = 3;
                else if (cat == BudgetCategory.Tele)
                    d = 4;
                else if (cat == BudgetCategory.Data)
                    d = 5;
                decimal target_value = 0;
                if (product == BudgetType.Acc)
                    target_value = budgetInfo.acc;
                else if (product == BudgetType.Finans)
                    target_value = budgetInfo.finans;
                else if (product == BudgetType.Rtgsa)
                    target_value = budgetInfo.rtgsa;
                else if (product == BudgetType.Strom)
                    target_value = budgetInfo.strom;
                else if (product == BudgetType.TA)
                    target_value = budgetInfo.ta;
                else if (product == BudgetType.Vinnprodukt)
                    target_value = budgetInfo.vinn;

                inntjen_total = Compute(dtSel, "Sum(Btokr)");
                omset_total = Compute(dtSel, "Sum(Salgspris)");
                omsetExMva_total = Compute(dtSel, "Sum(SalgsprisExMva)");

                DataRow dtRowAvd = dtWork.NewRow();
                dtRowAvd["Kategori"] = product;
                dtRowAvd["Selgerkode"] = "Totalt";

                dtRowAvd["Actual_inntjen"] = inntjen_total;
                dtRowAvd["Actual_omset"] = omset_total;
                dtRowAvd["Actual_omsetExMva"] = omsetExMva_total;
                if (omsetExMva_total != 0)
                    dtRowAvd["Actual_margin"] = Math.Round(inntjen_total / omsetExMva_total, 2);
                else
                    dtRowAvd["Actual_margin"] = 0;

                if (sqlce.Rows.Count > 0)
                {
                    decimal inntjen_prod = 0, antall_prod = 0, omset_prod = 0, hovedprod_antall = 0, vinnprodukt_poeng = 0;
                    KgsaBudgetProduct Actual = new KgsaBudgetProduct(product, type);
                    KgsaBudgetField actual_1 = new KgsaBudgetField();
                    KgsaBudgetField actual_2 = new KgsaBudgetField();
                    KgsaBudgetField actual_3 = new KgsaBudgetField();

                    KgsaBudgetProduct Target = new KgsaBudgetProduct(product, type);
                    KgsaBudgetField target_1 = new KgsaBudgetField();
                    KgsaBudgetField target_2 = new KgsaBudgetField();

                    KgsaBudgetProduct Difference = new KgsaBudgetProduct(product, type);
                    KgsaBudgetField difference_1 = new KgsaBudgetField();
                    KgsaBudgetField difference_2 = new KgsaBudgetField();

                    if (product == BudgetType.Vinnprodukt)
                    {
                        decimal antall = 0;
                        List<VinnproduktItem> items = main.vinnprodukt.GetList();
                        foreach (VinnproduktItem item in items)
                        {
                            inntjen_prod += Compute(dtSel, "Sum(Btokr)", "[Varekode] = '" + item.varekode + "'");
                            omset_prod += Compute(dtSel, "Sum(Salgspris)", "[Varekode] = '" + item.varekode + "'");
                            antall = Compute(dtSel, "Sum(Antall)", "[Varekode] = '" + item.varekode + "'");
                            antall_prod += antall;
                            vinnprodukt_poeng += item.poeng * antall;
                        }
                    }
                    else if (product == BudgetType.Acc)
                    {
                        int[] accessoriesGrpList = main.appConfig.GetAccessorieGroups(0);
                        foreach (int ac in accessoriesGrpList)
                        {
                            inntjen_prod += Compute(dtSel, "Sum(Btokr)", "[Varegruppe] = " + ac);
                            omset_prod += Compute(dtSel, "Sum(Salgspris)", "[Varegruppe] = " + ac);
                            antall_prod += Compute(dtSel, "Sum(Antall)", "[Varegruppe] = " + ac);
                        }
                    }
                    else if (product == BudgetType.Finans)
                    {
                        var rowf = dtSel.Select("[Varegruppe] = 961");
                        for (int f = 0; f < rowf.Length; f++)
                        {
                            var rows2 = sqlce.Select("[Bilagsnr] = " + rowf[f]["Bilagsnr"]);
                            DataTable dtFinans = rows2.Any() ? rows2.CopyToDataTable() : sqlce.Clone();
                            dtFinans.DefaultView.Sort = "Salgspris DESC";
                            int gruppe = Convert.ToInt32(dtFinans.Rows[0]["Varegruppe"].ToString().Substring(0, 1));
                            if (gruppe == d || d == 0)
                            {
                                r = sqlce.Compute("Sum(Btokr)", "[Varegruppe] = 961 AND [Bilagsnr] = " + dtFinans.Rows[0]["Bilagsnr"].ToString());
                                if (!DBNull.Value.Equals(r))
                                    inntjen_prod += Convert.ToDecimal(r);

                                r = sqlce.Compute("Sum(Antall)", "[Varegruppe] = 961 AND [Bilagsnr] = " + dtFinans.Rows[0]["Bilagsnr"].ToString());
                                if (!DBNull.Value.Equals(r))
                                    antall_prod += Convert.ToInt32(r);
                            }
                        }
                    }
                    else if (product == BudgetType.Rtgsa)
                    {
                        r = dtSel.Compute("Sum(Antall)", "([Varegruppe]=531 OR [Varegruppe]=533 OR [Varegruppe]=534 OR [Varegruppe]=224 OR [Varegruppe]=431)");
                        if (!DBNull.Value.Equals(r))
                            hovedprod_antall = Convert.ToInt32(r);

                        foreach (var varekode in varekoderAlle)
                        {
                            r = dtSel.Compute("Sum(Btokr)", "[Varekode]='" + varekode.kode + "'");
                            if (!DBNull.Value.Equals(r))
                                inntjen_prod += Convert.ToDecimal(r);

                            r = dtSel.Compute("Sum(Salgspris)", "[Varekode]='" + varekode.kode + "'");
                            if (!DBNull.Value.Equals(r))
                                omset_prod += Convert.ToDecimal(r);

                            if (varekode.synlig)
                            {
                                r = dtSel.Compute("Sum(Antall)", "[Varekode]='" + varekode.kode + "'");
                                if (!DBNull.Value.Equals(r))
                                    antall_prod += Convert.ToInt32(r);
                            }
                        }
                    }
                    else if (product == BudgetType.Strom)
                    {
                        r = dtSel.Compute("Sum(Btokr)", "[Varekode] LIKE 'ELSTROM*' OR [Varekode] LIKE 'ELRABATT*'");
                        if (!DBNull.Value.Equals(r))
                            inntjen_prod = Convert.ToDecimal(r);

                        r = dtSel.Compute("Sum(Salgspris)", "[Varekode] LIKE 'ELSTROM*' OR [Varekode] LIKE 'ELRABATT*'");
                        if (!DBNull.Value.Equals(r))
                            omset_prod = Convert.ToDecimal(r);

                        r = dtSel.Compute("Sum(Antall)", "[Varekode] LIKE 'ELSTROM*'");
                        if (!DBNull.Value.Equals(r))
                            antall_prod = Convert.ToInt32(r);
                    }
                    else if (product == BudgetType.TA)
                    {
                        r = dtSel.Compute("Sum(Btokr)", "[Varegruppe] % 100 = 83 AND [Varekode] LIKE 'MOD*'");
                        if (!DBNull.Value.Equals(r))
                            inntjen_prod = Convert.ToDecimal(r);

                        r = dtSel.Compute("Sum(Salgspris)", "[Varegruppe] % 100 = 83 AND [Varekode] LIKE 'MOD*'");
                        if (!DBNull.Value.Equals(r))
                            omset_prod = Convert.ToDecimal(r);

                        r = dtSel.Compute("Sum(Antall)", "[Varegruppe] % 100 = 83 AND [Varekode] LIKE 'MOD*'");
                        if (!DBNull.Value.Equals(r))
                            antall_prod = Convert.ToInt32(r);
                    }

                    if (type == BudgetValueType.Poeng)
                    {
                        actual_1.value = vinnprodukt_poeng;
                        actual_1.type = BudgetValueType.Poeng;
                        actual_2.value = antall_prod;
                        actual_2.type = BudgetValueType.Antall;
                        actual_3.value = inntjen_prod;
                        actual_3.type = BudgetValueType.Inntjening;

                        target_1.value = target_value * budgetInfo.timeElapsedCoefficient;
                        target_1.type = BudgetValueType.Poeng;
                        target_2.value = (target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed;
                        target_2.type = BudgetValueType.AntallPerDag;

                        difference_1.value = actual_1.value - target_1.value;
                        difference_1.type = BudgetValueType.Poeng;
                        difference_2.value = ((antall_prod * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) - target_2.value;
                        difference_2.type = BudgetValueType.AntallPerDag;
                    }
                    else if (type == BudgetValueType.Hitrate)
                    {
                        if (hovedprod_antall != 0)
                            actual_1.value = antall_prod / hovedprod_antall;
                        else
                            actual_1.value = 0;
                        actual_1.type = BudgetValueType.Hitrate;
                        actual_2.value = antall_prod;
                        actual_2.type = BudgetValueType.Antall;
                        actual_3.value = inntjen_prod;
                        actual_3.type = BudgetValueType.Inntjening;

                        target_1.value = target_value;
                        target_1.type = BudgetValueType.Hitrate;
                        target_2.value = (hovedprod_antall * target_value) / budgetInfo.daysElapsed;
                        target_2.type = BudgetValueType.AntallPerDag;

                        difference_1.value = actual_1.value - target_1.value;
                        difference_1.type = BudgetValueType.Hitrate;
                        difference_2.value = ((hovedprod_antall * actual_1.value) / budgetInfo.daysElapsed) - target_2.value;
                        difference_2.type = BudgetValueType.AntallPerDag;
                    }
                    else if (type == BudgetValueType.Antall)
                    {
                        actual_1.value = antall_prod;
                        actual_1.type = BudgetValueType.Antall;
                        actual_2.value = inntjen_prod;
                        actual_2.type = BudgetValueType.Inntjening;
                        if (inntjen_total != 0)
                            actual_3.value = inntjen_prod / inntjen_total;
                        else
                            actual_3.value = 0;
                        actual_3.type = BudgetValueType.SoM;

                        target_1.value = target_value * budgetInfo.timeElapsedCoefficient;
                        target_1.type = BudgetValueType.Antall;
                        target_2.value = (target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed;
                        target_2.type = BudgetValueType.AntallPerDag;

                        difference_1.value = actual_1.value - target_1.value;
                        difference_1.type = BudgetValueType.Antall;
                        difference_2.value = ((antall_prod * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) - target_2.value;
                        difference_2.type = BudgetValueType.AntallPerDag;
                    }
                    if (type == BudgetValueType.Inntjening)
                    {
                        actual_1.value = antall_prod;
                        actual_1.type = BudgetValueType.Antall;
                        actual_2.value = inntjen_prod;
                        actual_2.type = BudgetValueType.Inntjening;
                        if (inntjen_total != 0)
                            actual_3.value = inntjen_prod / inntjen_total;
                        else
                            actual_3.value = 0;
                        actual_3.type = BudgetValueType.SoM;

                        target_1.value = target_value * budgetInfo.timeElapsedCoefficient;
                        target_1.type = BudgetValueType.Inntjening;
                        target_2.value = (target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed;
                        target_2.type = BudgetValueType.InntjeningPerDag;

                        difference_1.value = actual_2.value - target_1.value;
                        difference_1.type = BudgetValueType.Inntjening;
                        difference_2.value = (inntjen_prod / budgetInfo.daysElapsed) - target_2.value;
                        difference_2.type = BudgetValueType.InntjeningPerDag;
                    }
                    if (type == BudgetValueType.Omsetning)
                    {
                        actual_1.value = antall_prod;
                        actual_1.type = BudgetValueType.Antall;
                        actual_2.value = omset_prod;
                        actual_2.type = BudgetValueType.Omsetning;
                        if (omset_prod != 0)
                            actual_3.value = omset_total / omset_prod;
                        else
                            actual_3.value = 0;
                        actual_3.type = BudgetValueType.SoB;

                        target_1.value = target_value * budgetInfo.timeElapsedCoefficient;
                        target_1.type = BudgetValueType.Omsetning;
                        target_2.value = (target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed;
                        target_2.type = BudgetValueType.OmsetningPerDag;

                        difference_1.value = actual_2.value - target_1.value;
                        difference_1.type = BudgetValueType.Omsetning;
                        difference_2.value = (omset_prod / budgetInfo.daysElapsed) - target_2.value;
                        difference_2.type = BudgetValueType.OmsetningPerDag;
                    }
                    if (type == BudgetValueType.SoB)
                    {
                        actual_1.value = antall_prod;
                        actual_1.type = BudgetValueType.Antall;
                        actual_2.value = omset_prod;
                        actual_2.type = BudgetValueType.Omsetning;
                        if (omset_total != 0)
                            actual_3.value = omset_prod / omset_total;
                        else
                            actual_3.value = 0;
                        actual_3.type = BudgetValueType.SoB;

                        target_1.value = target_value;
                        target_1.type = BudgetValueType.SoB;
                        target_2.value = omset_total * target_value;
                        target_2.type = BudgetValueType.Omsetning;

                        difference_1.value = actual_3.value - target_1.value;
                        difference_1.type = BudgetValueType.SoB;
                        difference_2.value = actual_2.value - target_2.value;
                        difference_2.type = BudgetValueType.Omsetning;
                    }
                    if (type == BudgetValueType.SoM)
                    {
                        actual_1.value = antall_prod;
                        actual_1.type = BudgetValueType.Antall;
                        actual_2.value = inntjen_prod;
                        actual_2.type = BudgetValueType.Inntjening;
                        if (inntjen_total != 0)
                            actual_3.value = inntjen_prod / inntjen_total;
                        else
                            actual_3.value = 0;
                        actual_3.type = BudgetValueType.SoM;

                        target_1.value = target_value;
                        target_1.type = BudgetValueType.SoM;
                        target_2.value = target_1.value * inntjen_total;
                        target_2.type = BudgetValueType.Inntjening;

                        difference_1.value = actual_3.value - target_1.value;
                        difference_1.type = BudgetValueType.SoM;
                        difference_2.value = actual_2.value - target_2.value;
                        difference_2.type = BudgetValueType.Inntjening;
                    }

                    Actual.fields.Add(actual_1); // kolonne 1 av 3
                    Actual.fields.Add(actual_2); // kolonne 2 av 3
                    Actual.fields.Add(actual_3); // kolonne 3 av 3

                    Target.fields.Add(target_1); // kolonne 1 av 3
                    Target.fields.Add(target_2); // kolonne 2 av 3

                    Difference.fields.Add(difference_1); // kolonne 1 av 3
                    Difference.fields.Add(difference_2); // kolonne 2 av 3

                    dtRowAvd["Field1"] = PrepFields(Actual, false, true);
                    dtRowAvd["Field2"] = PrepFields(Target);
                    dtRowAvd["Field3"] = PrepFields(Difference, true);

                    dtRowAvd["Sort_value"] = -9999999;
                }

                budgetInfo.chartdata = new List<BudgetChartData>() { };

                for (int i = 0; i < budgetInfo.selgere.Count; i++)
                {
                    decimal omset_sel = 0, inntjen_sel = 0, omsetExMva_sel = 0;

                    inntjen_sel = Compute(sqlce, "Sum(Btokr)", "Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                    omset_sel = Compute(sqlce, "Sum(Salgspris)", "Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                    omsetExMva_sel = Compute(sqlce, "Sum(SalgsprisExMva)", "Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");

                    DataRow dtRowSel = dtWork.NewRow();
                    dtRowSel["Kategori"] = product;
                    dtRowSel["Selgerkode"] = budgetInfo.selgere[i].selgerkode;

                    dtRowSel["Actual_inntjen"] = inntjen_sel;
                    dtRowSel["Actual_omset"] = omset_sel;
                    dtRowSel["Actual_omsetExMva"] = omsetExMva_sel;
                    if (omsetExMva_sel != 0)
                        dtRowSel["Actual_margin"] = Math.Round(inntjen_sel / omsetExMva_sel, 2);
                    else
                        dtRowSel["Actual_margin"] = 0;

                    if (sqlce.Rows.Count > 0)
                    {
                        decimal inntjen_prod = 0, antall_prod = 0, omset_prod = 0, hovedprod_antall = 0, vinnprodukt_poeng = 0;
                        KgsaBudgetProduct Actual = new KgsaBudgetProduct(product, type);
                        KgsaBudgetField actual_1 = new KgsaBudgetField();
                        KgsaBudgetField actual_2 = new KgsaBudgetField();
                        KgsaBudgetField actual_3 = new KgsaBudgetField();
                        KgsaBudgetProduct Target = new KgsaBudgetProduct(product, type);
                        KgsaBudgetField target_1 = new KgsaBudgetField();
                        KgsaBudgetField target_2 = new KgsaBudgetField();
                        KgsaBudgetProduct Difference = new KgsaBudgetProduct(product, type);
                        KgsaBudgetField diff_1 = new KgsaBudgetField();
                        KgsaBudgetField diff_2 = new KgsaBudgetField();

                        if (product == BudgetType.Vinnprodukt)
                        {
                            decimal antall = 0;
                            List<VinnproduktItem> items = main.vinnprodukt.GetList();
                            foreach (VinnproduktItem item in items)
                            {
                                inntjen_prod += Compute(sqlce, "Sum(Btokr)", "[Varekode] = '" + item.varekode + "' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                                omset_prod += Compute(sqlce, "Sum(Salgspris)", "[Varekode] = '" + item.varekode + "' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                                antall = Compute(sqlce, "Sum(Antall)", "[Varekode] = '" + item.varekode + "' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                                antall_prod += antall;
                                vinnprodukt_poeng += item.poeng * antall;
                            }
                        }
                        else if (product == BudgetType.Acc)
                        {
                            int[] accessoriesGrpList = main.appConfig.GetAccessorieGroups(0);
                            foreach (int ac in accessoriesGrpList)
                            {
                                r = sqlce.Compute("Sum(Antall)", "[Varegruppe] = " + ac + " AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                                if (!DBNull.Value.Equals(r))
                                    antall_prod += Convert.ToInt32(r);

                                r = sqlce.Compute("Sum(Btokr)", "[Varegruppe] = " + ac + " AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                                if (!DBNull.Value.Equals(r))
                                    inntjen_prod += Convert.ToDecimal(r);

                                r = sqlce.Compute("Sum(Salgspris)", "[Varegruppe] = " + ac + " AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                                if (!DBNull.Value.Equals(r))
                                    omset_prod += Convert.ToDecimal(r);
                            }
                        }
                        else if (product == BudgetType.Finans)
                        {
                            var rowf = sqlce.Select("[Varegruppe] = 961 AND [Selgerkode] = '" + budgetInfo.selgere[i].selgerkode + "'");
                            for (int f = 0; f < rowf.Length; f++)
                            {
                                var rows2 = sqlce.Select("[Bilagsnr] = " + rowf[f]["Bilagsnr"]);
                                DataTable dtFinans = rows2.Any() ? rows2.CopyToDataTable() : sqlce.Clone();
                                dtFinans.DefaultView.Sort = "Salgspris DESC";
                                int gruppe = Convert.ToInt32(dtFinans.Rows[0]["Varegruppe"].ToString().Substring(0, 1));
                                if (gruppe == d || d == 0)
                                {
                                    r = sqlce.Compute("Sum(Btokr)", "[Varegruppe] = 961 AND [Selgerkode] = '" + budgetInfo.selgere[i].selgerkode + "' AND [Bilagsnr] = " + dtFinans.Rows[0]["Bilagsnr"].ToString());
                                    if (!DBNull.Value.Equals(r))
                                        inntjen_prod += Convert.ToDecimal(r);

                                    r = sqlce.Compute("Sum(Antall)", "[Varegruppe] = 961 AND [Selgerkode] = '" + budgetInfo.selgere[i].selgerkode + "' AND [Bilagsnr] = " + dtFinans.Rows[0]["Bilagsnr"].ToString());
                                    if (!DBNull.Value.Equals(r))
                                        antall_prod += Convert.ToInt32(r);
                                }
                            }
                        }
                        else if (product == BudgetType.Rtgsa)
                        {
                            r = sqlce.Compute("Sum(Antall)", "([Varegruppe]=531 OR [Varegruppe]=533 OR [Varegruppe]=534 OR [Varegruppe]=224 OR [Varegruppe]=431) AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                            if (!DBNull.Value.Equals(r))
                                hovedprod_antall = Convert.ToInt32(r);

                            foreach (var varekode in varekoderAlle)
                            {
                                r = sqlce.Compute("Sum(Salgspris)", "[Varekode]='" + varekode.kode + "' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                                if (!DBNull.Value.Equals(r))
                                    omset_prod += Convert.ToDecimal(r);

                                r = sqlce.Compute("Sum(Btokr)", "[Varekode]='" + varekode.kode + "' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                                if (!DBNull.Value.Equals(r))
                                    inntjen_prod += Convert.ToDecimal(r);

                                if (varekode.synlig)
                                {
                                    r = sqlce.Compute("Sum(Antall)", "[Varekode]='" + varekode.kode + "' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                                    if (!DBNull.Value.Equals(r))
                                        antall_prod += Convert.ToInt32(r);
                                }
                            }
                        }
                        else if (product == BudgetType.Strom)
                        {
                            r = sqlce.Compute("Sum(Btokr)", "([Varekode] LIKE 'ELSTROM*' OR [Varekode] LIKE 'ELRABATT*') AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                            if (!DBNull.Value.Equals(r))
                                inntjen_prod = Convert.ToDecimal(r);

                            r = sqlce.Compute("Sum(Salgspris)", "([Varekode] LIKE 'ELSTROM*' OR [Varekode] LIKE 'ELRABATT*') AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                            if (!DBNull.Value.Equals(r))
                                omset_prod = Convert.ToDecimal(r);

                            r = sqlce.Compute("Sum(Antall)", "[Varekode] LIKE 'ELSTROM*' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                            if (!DBNull.Value.Equals(r))
                                antall_prod = Convert.ToInt32(r);
                        }
                        else if (product == BudgetType.TA)
                        {
                            r = sqlce.Compute("Sum(Btokr)", "[Varegruppe] % 100 = 83 AND [Varekode] LIKE 'MOD*' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                            if (!DBNull.Value.Equals(r))
                                inntjen_prod = Convert.ToDecimal(r);

                            r = sqlce.Compute("Sum(Salgspris)", "[Varegruppe] % 100 = 83 AND [Varekode] LIKE 'MOD*' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                            if (!DBNull.Value.Equals(r))
                                omset_prod = Convert.ToDecimal(r);

                            r = sqlce.Compute("Sum(Antall)", "[Varegruppe] % 100 = 83 AND [Varekode] LIKE 'MOD*' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                            if (!DBNull.Value.Equals(r))
                                antall_prod = Convert.ToInt32(r);
                        }

                        if (type == BudgetValueType.Poeng)
                        {
                            actual_1.value = vinnprodukt_poeng;
                            actual_1.type = BudgetValueType.Poeng;
                            actual_2.value = antall_prod;
                            actual_2.type = BudgetValueType.Antall;
                            actual_3.value = inntjen_prod;
                            actual_3.type = BudgetValueType.Inntjening;

                            target_1.value = target_value * budgetInfo.timeElapsedCoefficient * budgetInfo.selgere[i].weight;
                            target_1.type = BudgetValueType.Poeng;
                            target_2.value = ((target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) * budgetInfo.selgere[i].weight;
                            target_2.type = BudgetValueType.AntallPerDag;

                            diff_1.value = actual_1.value - target_1.value;
                            diff_1.type = BudgetValueType.Poeng;
                            diff_2.value = ((antall_prod * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) - target_2.value;
                            diff_2.type = BudgetValueType.AntallPerDag;
                        }
                        else  if (type == BudgetValueType.Hitrate)
                        {
                            if (hovedprod_antall != 0)
                                actual_1.value = antall_prod / hovedprod_antall;
                            else
                                actual_1.value = 0;
                            actual_1.type = BudgetValueType.Hitrate;
                            actual_2.value = antall_prod;
                            actual_2.type = BudgetValueType.Antall;
                            actual_3.value = inntjen_prod;
                            actual_3.type = BudgetValueType.Inntjening;

                            target_1.value = target_value;
                            target_1.type = BudgetValueType.Hitrate;
                            target_2.value = (hovedprod_antall * target_value) / budgetInfo.daysElapsed;
                            target_2.type = BudgetValueType.AntallPerDag;

                            diff_1.value = actual_1.value - target_1.value;
                            diff_1.type = BudgetValueType.Hitrate;
                            diff_2.value = ((hovedprod_antall * actual_1.value) / budgetInfo.daysElapsed) - target_2.value;
                            diff_2.type = BudgetValueType.AntallPerDag;
                        }
                        else if (type == BudgetValueType.Antall)
                        {
                            actual_1.value = antall_prod;
                            actual_1.type = BudgetValueType.Antall;
                            actual_2.value = inntjen_prod;
                            actual_2.type = BudgetValueType.Inntjening;
                            if (inntjen_sel != 0)
                                actual_3.value = inntjen_prod / inntjen_sel;
                            else
                                actual_3.value = 0;
                            actual_3.type = BudgetValueType.SoM;

                            target_1.value = target_value * budgetInfo.timeElapsedCoefficient * budgetInfo.selgere[i].weight;
                            target_1.type = BudgetValueType.Antall;
                            target_2.value = ((target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) * budgetInfo.selgere[i].weight;
                            target_2.type = BudgetValueType.AntallPerDag;

                            diff_1.value = actual_1.value - target_1.value;
                            diff_1.type = BudgetValueType.Antall;
                            diff_2.value = antall_prod / budgetInfo.daysElapsed - target_2.value;
                            diff_2.type = BudgetValueType.AntallPerDag;
                        }
                        else if (type == BudgetValueType.Inntjening)
                        {
                            actual_1.value = antall_prod;
                            actual_1.type = BudgetValueType.Antall;
                            actual_2.value = inntjen_prod;
                            actual_2.type = BudgetValueType.Inntjening;
                            if (inntjen_sel != 0)
                                actual_3.value = inntjen_prod / inntjen_sel;
                            else
                                actual_3.value = 0;
                            actual_3.type = BudgetValueType.SoM;

                            target_1.value = target_value * budgetInfo.timeElapsedCoefficient * budgetInfo.selgere[i].weight;
                            target_1.type = BudgetValueType.Inntjening;
                            target_2.value = ((target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) * budgetInfo.selgere[i].weight;
                            target_2.type = BudgetValueType.InntjeningPerDag;

                            diff_1.value = actual_2.value - target_1.value;
                            diff_1.type = BudgetValueType.Inntjening;
                            diff_2.value = inntjen_prod / budgetInfo.daysElapsed - target_2.value;
                            diff_2.type = BudgetValueType.InntjeningPerDag;
                        }
                        else if (type == BudgetValueType.Omsetning)
                        {
                            actual_1.value = antall_prod;
                            actual_1.type = BudgetValueType.Antall;
                            actual_2.value = omset_prod;
                            actual_2.type = BudgetValueType.Omsetning;
                            if (omset_sel != 0)
                                actual_3.value = omset_prod / omset_sel;
                            else
                                actual_3.value = 0;
                            actual_3.type = BudgetValueType.SoB;

                            target_1.value = target_value * budgetInfo.timeElapsedCoefficient * budgetInfo.selgere[i].weight;
                            target_1.type = BudgetValueType.Omsetning;
                            target_2.value = ((target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) * budgetInfo.selgere[i].weight;
                            target_2.type = BudgetValueType.OmsetningPerDag;

                            diff_1.value = actual_2.value - target_1.value;
                            diff_1.type = BudgetValueType.Omsetning;
                            diff_2.value = omset_prod / budgetInfo.daysElapsed - target_2.value;
                            diff_2.type = BudgetValueType.OmsetningPerDag;
                        }
                        else if (type == BudgetValueType.SoB)
                        {
                            actual_1.value = antall_prod;
                            actual_1.type = BudgetValueType.Antall;
                            actual_2.value = omset_prod;
                            actual_2.type = BudgetValueType.Omsetning;
                            if (omset_sel != 0)
                                actual_3.value = omset_prod / omset_sel;
                            else
                                actual_3.value = 0;
                            actual_3.type = BudgetValueType.SoB;

                            target_1.value = target_value;
                            target_1.type = BudgetValueType.SoB;
                            target_2.value = omset_sel * target_value;
                            target_2.type = BudgetValueType.Omsetning;

                            diff_1.value = actual_3.value - target_1.value;
                            diff_1.type = BudgetValueType.SoB;
                            diff_2.value = actual_2.value - target_2.value;
                            diff_2.type = BudgetValueType.Omsetning;
                        }
                        else if (type == BudgetValueType.SoM)
                        {
                            actual_1.value = antall_prod;
                            actual_1.type = BudgetValueType.Antall;
                            actual_2.value = inntjen_prod;
                            actual_2.type = BudgetValueType.Inntjening;
                            if (inntjen_sel != 0)
                                actual_3.value = inntjen_prod / inntjen_sel;
                            else
                                actual_3.value = 0;
                            actual_3.type = BudgetValueType.SoM;

                            target_1.value = target_value;
                            target_1.type = BudgetValueType.SoM;
                            target_2.value = inntjen_sel * target_value;
                            target_2.type = BudgetValueType.Inntjening;

                            diff_1.value = actual_3.value - target_1.value;
                            diff_1.type = BudgetValueType.SoM;
                            diff_2.value = actual_2.value - target_2.value;
                            diff_2.type = BudgetValueType.Inntjening;
                        }
                        Actual.fields.Add(actual_1); // kolonne 1 av 3
                        Actual.fields.Add(actual_2); // kolonne 2 av 3
                        Actual.fields.Add(actual_3); // kolonne 3 av 3

                        Target.fields.Add(target_1); // kolonne 1 av 2
                        Target.fields.Add(target_2); // kolonne 2 av 2

                        Difference.fields.Add(diff_1); // kolonne 1 av 2
                        Difference.fields.Add(diff_2); // kolonne 2 av 2

                        dtRowSel["Field1"] = PrepFields(Actual, false, true);
                        dtRowSel["Field2"] = PrepFields(Target);
                        dtRowSel["Field3"] = PrepFields(Difference, true);

                        if (type == BudgetValueType.Antall || type == BudgetValueType.Poeng)
                        {
                            dtRowSel["Sort_value"] = actual_1.value;
                            budgetInfo.chartdata.Add(new BudgetChartData(budgetInfo.selgere[i].selgerkode, target_1.value, actual_1.value));
                        }
                        else if (type == BudgetValueType.Inntjening || type == BudgetValueType.Omsetning)
                        {
                            dtRowSel["Sort_value"] = actual_2.value;
                            budgetInfo.chartdata.Add(new BudgetChartData(budgetInfo.selgere[i].selgerkode, target_1.value, actual_2.value));
                        }
                        else if (type == BudgetValueType.SoM || type == BudgetValueType.SoB)
                        {
                            dtRowSel["Sort_value"] = actual_3.value;
                            budgetInfo.chartdata.Add(new BudgetChartData(budgetInfo.selgere[i].selgerkode, target_1.value, actual_3.value));
                        }
                        else if (type == BudgetValueType.Hitrate)
                        {
                            dtRowSel["Sort_value"] = actual_1.value;
                            budgetInfo.chartdata.Add(new BudgetChartData(budgetInfo.selgere[i].selgerkode, target_1.value, actual_1.value));
                        }
                    }
                    dtWork.Rows.Add(dtRowSel);
                }

                dtWork.Rows.Add(dtRowAvd);
                DataView dv = dtWork.DefaultView;
                dv.Sort = "Sort_value desc";

                budgetInfo.chartdata = budgetInfo.chartdata.OrderByDescending(x => x.actual).ToList();

                return dv.ToTable();
            }
            catch (Exception ex)
            {
                Log.Unhandled(ex);
                return null;
            }
        }
Beispiel #5
0
 public void SaveChartImage(int argX, int argY, string argFilename, BudgetValueType type, BudgetType product, List<BudgetChartData> list)
 {
     Bitmap graphBitmap = DrawChartData(argX, argY, type, product, list);
     if (graphBitmap != null)
     {
         graphBitmap.Save(argFilename, ImageFormat.Png);
         graphBitmap.Dispose();
     }
 }
Beispiel #6
0
        public string ValueToDisplay(string strArg, BudgetValueType type, bool green = false)
        {
            try
            {
                decimal value = 0;
                if (!decimal.TryParse(strArg, out value))
                    return main.appConfig.visningNull;

                string filter = "";
                string suffix = "";
                if (type == BudgetValueType.Hitrate || type == BudgetValueType.SoB || type == BudgetValueType.SoM)
                {
                    value = Math.Round(value, 2);
                    suffix = " %";
                }
                else
                {
                    value = Math.Round(value, 0);
                    filter = "#,##0";
                }
                string valueStr = main.appConfig.visningNull;

                if (value < 0)
                    valueStr = "<span style='color:red'>" + value.ToString(filter) + suffix + "</span>";
                if (value > 0)
                {
                    if (green)
                        valueStr = "<span style='color:green'>" + value.ToString(filter) + suffix + "</span>";
                    else
                        valueStr = value.ToString(filter) + suffix;
                }

                return valueStr;
            }
            catch (Exception ex)
            {
                Log.Unhandled(ex);
            }
            return main.appConfig.visningNull;
        }
Beispiel #7
0
        public string GetValueTypeSuffix(BudgetValueType type)
        {
            if (type == BudgetValueType.Poeng)
                return "poeng";
            if (type == BudgetValueType.Antall)
                return "stk";
            if (type == BudgetValueType.AntallPerDag)
                return "stk /dag";
            if (type == BudgetValueType.Hitrate)
                return "%";
            if (type == BudgetValueType.Inntjening)
                return "kr";
            if (type == BudgetValueType.InntjeningPerDag)
                return "kr /dag";
            if (type == BudgetValueType.Omsetning)
                return "kr";
            if (type == BudgetValueType.OmsetningPerDag)
                return "kr /dag";
            if (type == BudgetValueType.SoB)
                return "%";
            if (type == BudgetValueType.SoM)
                return "%";

            return "";
        }
Beispiel #8
0
 public string ValueToString(decimal value, BudgetValueType type)
 {
     if (type == BudgetValueType.Antall)
         return value.ToString("#,##0") + GetSufix(type);
     else if (type == BudgetValueType.Hitrate)
         return value.ToString("#,##0.00") + GetSufix(type);
     else if (type == BudgetValueType.Inntjening)
         return value.ToString("#,##0") + GetSufix(type);
     else if (type == BudgetValueType.Omsetning)
         return value.ToString("#,##0") + GetSufix(type);
     else if (type == BudgetValueType.SoB)
         return (value * 100).ToString("#,##0.00") + GetSufix(type);
     else if (type == BudgetValueType.SoM)
         return (value * 100).ToString("#,##0.00") + GetSufix(type);
     else
         return value.ToString();
 }
Beispiel #9
0
 public string TypeToString(BudgetValueType type)
 {
     if (type == BudgetValueType.Poeng)
         return "Poeng";
     if (type == BudgetValueType.Antall)
         return "Antall";
     else if (type == BudgetValueType.Hitrate)
         return "Hitrate";
     else if (type == BudgetValueType.Inntjening)
         return "Inntjen";
     else if (type == BudgetValueType.Omsetning)
         return "Omset";
     else if (type == BudgetValueType.SoB)
         return "SoB";
     else if (type == BudgetValueType.SoM)
         return "SoM";
     else
         return "";
 }
Beispiel #10
0
 public string GetSufix(BudgetValueType type)
 {
     if (type == BudgetValueType.Antall)
         return " stk";
     else if (type == BudgetValueType.Hitrate)
         return " %";
     else if (type == BudgetValueType.Inntjening)
         return " kr";
     else if (type == BudgetValueType.Omsetning)
         return " kr";
     else if (type == BudgetValueType.SoB)
         return " %";
     else if (type == BudgetValueType.SoM)
         return " %";
     else
         return "";
 }
Beispiel #11
0
        private Bitmap DrawChartData(int argX, int argY, BudgetValueType type, BudgetType product, List<BudgetChartData> list)
        {
            Bitmap b = new Bitmap(argX, argY);
            using (Graphics g = Graphics.FromImage(b))
            {
                try
                {
                    float dpi = 1;

                    g.SmoothingMode = SmoothingMode.AntiAlias;
                    g.Clear(Color.White);
                    if (list.Count == 0)
                    {
                        g.DrawString("Mangler info!", new Font("Verdana", 30, FontStyle.Bold), new SolidBrush(Color.Red), 400, 0);
                        return b;
                    }

                    float offsetTop = 20;
                    float offsetLeft = 25;
                    float offsetBottom = 35;
                    float X = argX;
                    float Y = argY;

                    PointF p1, p2;
                    SolidBrush bBrush = new SolidBrush(Color.Gray);
                    Pen pen = new Pen(Color.Black, 3 * dpi);
                    Font fontNormal = new Font("Helvetica", 22 * dpi, FontStyle.Regular);
                    Color resultColor = System.Drawing.ColorTranslator.FromHtml(GetProductColor(product));
                    Color resultColorDark = Tint(System.Drawing.ColorTranslator.FromHtml(GetProductColor(product)), Color.Black, 0.5M);

                    Color targetColor = System.Drawing.ColorTranslator.FromHtml("#1163b0");
                    Color targetColorDark = System.Drawing.ColorTranslator.FromHtml("#004586");

                    int count = list.Count;
                    if (count < main.appConfig.budgetChartMinPosts)
                        count = main.appConfig.budgetChartMinPosts;

                    int maxI = 0, mI = 0;
                    for (int i = 0; i < list.Count; i++)
                    {
                        mI = Convert.ToInt32(list[i].actual);
                        if (mI > maxI)
                            maxI = mI;

                        mI = Convert.ToInt32(list[i].target);
                        if (mI > maxI)
                            maxI = mI;
                    }

                    float innject = 200 * dpi;
                    float maxW = X - (X / 8) - innject;
                    float Vstep = (Y - 100) / count;

                    int roundTo = 1000;

                    if (maxI > 1000000)
                        roundTo = 125000;
                    else if (maxI > 500000)
                        roundTo = 100000;
                    else if (maxI > 100000)
                        roundTo = 40000;
                    else if (maxI > 50000)
                        roundTo = 10000;
                    else if (maxI > 25000)
                        roundTo = 5000;
                    else if (maxI > 5000)
                        roundTo = 1000;
                    else if (maxI > 1000)
                        roundTo = 500;
                    else if (maxI > 250)
                        roundTo = 50;
                    else if (maxI > 150)
                        roundTo = 25;
                    else if (maxI > 100)
                        roundTo = 20;
                    else if (maxI > 50)
                        roundTo = 10;
                    else if (maxI > 25)
                        roundTo = 5;
                    else if (maxI > 10)
                        roundTo = 2;
                    else if (maxI > 1)
                        roundTo = 1;

                    for (int i = 0; i < 100; i++)
                    {
                        float someNumber = maxI - (roundTo * i);
                        int closest = (int)((someNumber + (0.5 * roundTo)) / roundTo) * roundTo;
                        float wI = maxW * ((float)closest / (float)maxI);
                        if (float.IsNaN(wI) || float.IsInfinity(wI))
                            wI = 1;
                        if (closest < 0)
                            break;

                        g.DrawLine(new Pen(Color.LightGray, 5 * dpi), new PointF(wI + offsetLeft + innject, 0 + offsetTop), new PointF(wI + offsetLeft + innject, Y - offsetBottom));
                        g.DrawString(ForkortTallBudget(closest) + " " + GetValueTypeSuffix(type), new Font("Verdana", 20 * dpi, FontStyle.Regular), new SolidBrush(Color.Black), wI + offsetLeft + innject, Y - offsetBottom);
                    }

                    System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(StringFormatFlags.DirectionVertical);
                    g.DrawString(ProductToString(product), new Font("Verdana", 38 * dpi, FontStyle.Bold), new SolidBrush(Color.Gray), X - (100 * dpi), 30, drawFormat);

                    for (int i = 0; i < count; i++)
                    {
                        if (list.Count > i)
                        {
                            string selger = list[i].selgerkode;
                            decimal actual = list[i].actual;
                            decimal target = list[i].target;

                            float x = offsetLeft + innject;
                            float y = Vstep * i + offsetTop;
                            float y2 = Vstep * i + offsetTop + (Vstep / 5);

                            p1 = new PointF(x, y);
                            p2 = new PointF(x, y2);

                            float wI = maxW * ((float)actual / (float)maxI);
                            float wIT = maxW * ((float)target / (float)maxI);

                            if (float.IsNaN(wI) || float.IsInfinity(wI))
                                wI = 1;
                            if (float.IsNaN(wIT) || float.IsInfinity(wIT))
                                wIT = 1;

                            g.DrawString(main.salesCodes.GetNavn(selger), fontNormal, new SolidBrush(Color.Black), new PointF(x + 10 - innject, Vstep * i + offsetTop + (Vstep / 10)));

                            if (type != BudgetValueType.Hitrate && type != BudgetValueType.SoB && type != BudgetValueType.SoM)
                            {
                                g.FillRectangle(new SolidBrush(targetColor), new RectangleF(p2, new SizeF(wIT, Vstep / 1.5f)));
                                g.DrawRectangle(new Pen(targetColorDark, 3 * dpi), x, y2, wIT, Vstep / 1.5f);
                            }

                            g.FillRectangle(new SolidBrush(resultColor), new RectangleF(p1, new SizeF(wI, Vstep / 1.5f)));
                            g.DrawRectangle(new Pen(resultColorDark, 3 * dpi), x, y, wI, Vstep / 1.5f);
                            if (actual > 0)
                            {

                                GraphicsPath path = new GraphicsPath();

                                string strTall = "";
                                if (type != BudgetValueType.Hitrate && type != BudgetValueType.SoB && type != BudgetValueType.SoM)
                                    strTall = ForkortTallBudget(actual) + " " + GetValueTypeSuffix(type);
                                else
                                    strTall = Math.Round(actual, 2).ToString() + " %";

                                path.AddString(strTall, new FontFamily("Helvetica"), (int)FontStyle.Bold, 28f * dpi, new PointF(wI + innject + offsetLeft + (5 * dpi), Vstep * i + offsetTop + (Vstep / 10)), StringFormat.GenericDefault);

                                for (int c = 1; c < 8; ++c)
                                {
                                    Pen pen3 = new Pen(Color.FromArgb(32, 255, 255, 255), c);
                                    pen3.LineJoin = LineJoin.Round;
                                    g.DrawPath(pen3, path);
                                    pen3.Dispose();
                                }

                                SolidBrush brush = new SolidBrush(Color.FromArgb(0, 0, 0));
                                g.FillPath(brush, path);
                            }
                        }
                        else // Hvis ingen flere selgere, vis tomme felt
                        {
                            // Nothing to do..
                        }
                    }

                    if (type == BudgetValueType.Hitrate || type == BudgetValueType.SoB || type == BudgetValueType.SoM)
                    {
                        float wI = maxW * ((float)list[0].target / (float)maxI);
                        g.DrawLine(new Pen(Color.Red, 10 * dpi), new PointF(wI + offsetLeft + innject, 0 + offsetTop), new PointF(wI + offsetLeft + innject, Y - offsetBottom));
                    }

                }
                catch
                {
                }
            }
            return b;
        }