/// <summary>
        /// Generates the charts one by one.
        /// </summary>
        /// <param name="du"></param>
        private void GenerateCharts(int du)
        {
            Balance bal = new Balance();
            GeneralInfo info = new GeneralInfo();
            info.LoadAll();
            DataTable dtList = new DataTable();
            DataTable dtAmc = new DataTable();
            DataTable dtMOS = new DataTable();
            DataTable dtIss = new DataTable();
            DataTable dtRec = new DataTable();
            DataTable dtBB = new DataTable();
            //CALENDAR:
            //  DataTable dtCons = new DataTable();
            string[] co = { "Ham", "Neh", "Mes", "Tek", "Hed", "Tah", "Tir", "Yek", "Meg", "Miz", "Gen", "Sen" };

            //foreach(string s in co)
            //{
            dtList.Columns.Add("Month");
            dtList.Columns.Add("Value");
            dtList.Columns[1].DataType = typeof(Int64);

            dtMOS.Columns.Add("Month");
            dtMOS.Columns.Add("Value");
            dtMOS.Columns[1].DataType = typeof(decimal);

            dtAmc.Columns.Add("Month");
            dtAmc.Columns.Add("Value");
            dtAmc.Columns[1].DataType = typeof(Int64);

            dtIss.Columns.Add("Month");
            dtIss.Columns.Add("Value");
            dtIss.Columns[1].DataType = typeof(Int64);

            dtRec.Columns.Add("Month");
            dtRec.Columns.Add("Value");
            dtRec.Columns[1].DataType = typeof(Int64);

            dtBB.Columns.Add("Month");
            dtBB.Columns.Add("Value");
            dtBB.Columns[1].DataType = typeof(Int64);

            int[] mon = { 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            long[] cons = new long[12];
            double[] amc = new double[12];
            long[] con = new long[12];
            long[] issval = new long[12];
            DataTable dtBal = new DataTable();
            IssueDoc issd = new IssueDoc();
            Items recd = new Items();
            YearEnd yEnd = new YearEnd();
            Int64 bb = yEnd.GetBBalance(_year, _storeId, _itemId, 10);
            object[] objBB = { "Ham", bb };
            dtBB.Rows.Add(objBB);
            //dtDate.Value = DateTime.Now;
            //dtDate.CustomFormat = "MM/dd/yyyy";
            //DateTime dtCurrent = ConvertDate.DateConverter(dtDate.Text);

            for (int i = 0; i < mon.Length; i++)
            {
                int cMonth = _dtCurrent.Month;
                //if (!(year == dtCurrent.Year && mon[i] > dtCurrent.Month && mon[i] < 11))
                if (((mon[i] == 11 || mon[i] == 12) && (mon[i] <= cMonth || _year == _dtCurrent.Year)) || (mon[i] < 11 && mon[i] <= cMonth && _year == _dtCurrent.Year))
                {
                    int yr = (mon[i] < 11) ? _year : _year - 1;
                    // dtBal = bal.GetSOH(itemId,storeId,mon[i],yr);
                    con[i] = ((du == 0) ? bal.GetSOH(_itemId, _storeId, mon[i], yr) : bal.GetDUSOH(_itemId, du, mon[i], yr));
                    object xSOH = null;
                    if (con[i] == 0)
                    {
                        for (int li = i; li >= 0; li--)
                        {
                            if (con[li] != 0)
                            {
                                xSOH = 0;
                                break;
                            }
                        }
                    }
                    else
                        xSOH = con[i];
                    object[] str = { co[i], xSOH };
                    amc[i] = ((du == 0) ? Builder.CalculateAverageConsumption(_itemId, _storeId, _dtCurrent.Subtract(TimeSpan.FromDays(180)), _dtCurrent, CalculationOptions.Monthly) : bal.CalculateDUAMC(_itemId, du, mon[i], yr, 0));//bal.CalculateAMC(_itemId, _storeId, mon[i], yr)
                    object xAmc = null;
                    if (amc[i] == 0)
                    {
                        for (int li = i; li >= 0; li--)
                        {
                            if (amc[li] != 0)
                            {
                                xAmc = 0;
                                break;
                            }
                        }
                    }
                    else
                        xAmc = amc[i];
                    object[] objAmc = { co[i], xAmc };

                    // for mos check the diff b/n null and zero
                    // And also mos = soh/amc right???
                    decimal mos = (amc[i] > 0) ? (Convert.ToDecimal(con[i]) / Convert.ToDecimal(amc[i])) : 0;
                    object[] objMos = { co[i], mos };
                    int fYear = (mon[i] < 11) ? yr : yr - 1;

                    issval[i] = ((du == 0) ? issd.GetIssuedQuantityByMonth(_itemId, _storeId, mon[i], yr) : issd.GetDUConsumptionByMonth(_itemId, du, mon[i], yr));
                    object xIss = null;
                    if (issval[i] == 0)
                    {
                        for (int li = i; li >= 0; li--)
                        {
                            if (issval[li] != 0)
                            {
                                xIss = 0;
                                break;
                            }
                        }
                    }
                    else
                        xIss = issval[i];
                    object[] objIss = { co[i], xIss };

                    Int64 recVal = ((du == 0) ? recd.GetQuantityReceiveByItemPerMonth(mon[i], _itemId, _storeId, yr) : issd.GetDUReceiveByMonth(_itemId, du, mon[i], yr));
                    object[] objrec = { co[i], recVal };

                    dtList.Rows.Add(str);
                    dtAmc.Rows.Add(objAmc);
                    dtMOS.Rows.Add(objMos);
                    dtIss.Rows.Add(objIss);
                    dtRec.Rows.Add(objrec);
                }
            }

            // string[] str = { ((cons[0] != 0) ? cons[0].ToString("") : "0"), ((cons[1] != 0) ? cons[1].ToString() : "0"), ((cons[2] != 0) ? cons[2].ToString() : "0"), ((cons[3] != 0) ? cons[3].ToString() : "0"), ((cons[4] != 0) ? cons[4].ToString() : "0"), ((cons[5] != 0) ? cons[5].ToString() : "0"), ((cons[6] != 0) ? cons[6].ToString() : "0"), ((cons[7] != 0) ? cons[7].ToString() : "0"), ((cons[8] != 0) ? cons[8].ToString() : "0"), ((cons[9] != 0) ? cons[9].ToString() : "0"), ((cons[10] != 0) ? cons[10].ToString() : "0"), ((cons[11] != 0) ? cons[11].ToString() : "0")};
            chartAmc.Series.Clear(); //AMC
            chartComp.Series.Clear();//Activity
            chartBar.Series.Clear(); //SOH
            chartMOS.Series.Clear(); // MOS
            consuTrend.Series.Clear();

            Series ser = new Series("Stock On Hand", ViewType.Line);
            ser.DataSource = dtList;
            ser.ArgumentScaleType = ScaleType.Qualitative;
            ser.ArgumentDataMember = "Month";
            ser.ValueScaleType = ScaleType.Numerical;
            ser.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
            ser.PointOptions.ValueNumericOptions.Precision = 0;
            ser.ValueDataMembers.AddRange(new string[] { "Value" });

            chartBar.Series.Add(ser);
            ((XYDiagram)chartBar.Diagram).AxisY.NumericOptions.Format = NumericFormat.Number;
            ((XYDiagram)chartBar.Diagram).AxisY.NumericOptions.Precision = 0;

            Series serB = new Series("Begining Balance", ViewType.Bar);
            serB.DataSource = dtBB;
            serB.ArgumentScaleType = ScaleType.Qualitative;
            serB.ArgumentDataMember = "Month";
            serB.ValueScaleType = ScaleType.Numerical;
            serB.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
            serB.PointOptions.ValueNumericOptions.Precision = 0;
            serB.ValueDataMembers.AddRange(new string[] { "Value" });
            chartComp.Series.Add(serB);

            Series serRec = new Series("Received Qty", ViewType.Bar);
            serRec.DataSource = dtRec;
            serRec.ArgumentScaleType = ScaleType.Qualitative;
            serRec.ArgumentDataMember = "Month";
            serRec.ValueScaleType = ScaleType.Numerical;
            serRec.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
            serRec.PointOptions.ValueNumericOptions.Precision = 0;
            serRec.ValueDataMembers.AddRange(new string[] { "Value" });
            chartComp.Series.Add(serRec);

            Series serAmc = new Series("AMC", ViewType.Line);
            serAmc.DataSource = dtAmc;
            serAmc.ArgumentScaleType = ScaleType.Qualitative;
            serAmc.ArgumentDataMember = "Month";
            serAmc.ValueScaleType = ScaleType.Numerical;
            serAmc.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
            serAmc.PointOptions.ValueNumericOptions.Precision = 0;
            serAmc.ValueDataMembers.AddRange(new string[] { "Value" });
            chartAmc.Series.Add(serAmc);
            ((XYDiagram)chartAmc.Diagram).AxisY.NumericOptions.Format = NumericFormat.Number;
            ((XYDiagram)chartAmc.Diagram).AxisY.NumericOptions.Precision = 0;

            Series serIss = new Series("Issue Qty", ViewType.Bar);
            serIss.DataSource = dtIss;
            serIss.ArgumentScaleType = ScaleType.Qualitative;
            serIss.ArgumentDataMember = "Month";
            serIss.ValueScaleType = ScaleType.Numerical;
            serIss.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
            serIss.PointOptions.ValueNumericOptions.Precision = 0;
            serIss.ValueDataMembers.AddRange(new string[] { "Value" });
            chartComp.Series.Add(serIss);

            //Int64 amcCurent = bal.CalculateAMC(_itemId, _storeId, _dtCurrent.Month, _dtCurrent.Year);
            double amcCurent = Builder.CalculateAverageConsumption(_itemId, _storeId,
                                                                   _dtCurrent.Subtract(TimeSpan.FromDays(180)),
                                                                   _dtCurrent, CalculationOptions.Monthly);
            double min = info.Min * amcCurent;
            double max = info.Max * amcCurent;
            Int64 nearEOP = Convert.ToInt64(amcCurent * (info.EOP + 0.25));
            ConstantLine target = new ConstantLine();
            ConstantLine targetEOP = new ConstantLine();
            target.AxisValue = min;
            //which min and max to show month
            ((XYDiagram)chartComp.Diagram).AxisY.ConstantLines.Clear();
            target.Visible = true;
            target.Title.Text = "Current Min value is " + Convert.ToInt64(target.AxisValue).ToString("#,###") + " " + lblBUnit.Text;
            target.Color = Color.Red;
            target.LineStyle.Thickness = 2;
            target.LegendText = "Min";
            ((XYDiagram)chartComp.Diagram).AxisY.ConstantLines.Add(target);

            targetEOP = new ConstantLine();
            targetEOP.AxisValue = nearEOP;
            //which min and max to show month
            //((XYDiagram)chartBar.Diagram).AxisY.ConstantLines.Clear();
            targetEOP.Visible = true;
            targetEOP.Title.Text = "Current EOP value is " + Convert.ToInt64(targetEOP.AxisValue).ToString("#,###") + " " + lblBUnit.Text;
            targetEOP.Color = Color.Yellow;
            targetEOP.LineStyle.Thickness = 2;
            targetEOP.LegendText = "EOP";
            ((XYDiagram)chartComp.Diagram).AxisY.ConstantLines.Add(targetEOP);

            ConstantLine targetMax = new ConstantLine();
            targetMax.AxisValue = max;
            //which min and max to show month
            targetMax.Visible = true;
            targetMax.Title.Text = "Current Max value is " + Convert.ToInt64(targetMax.AxisValue).ToString("#,###") + " " + lblBUnit.Text;
            targetMax.Color = Color.Blue;
            targetMax.LineStyle.Thickness = 2;
            targetMax.LegendText = "Max";
            ((XYDiagram)chartComp.Diagram).AxisY.ConstantLines.Add(targetMax);

            Series sercons = new Series("Consumption", ViewType.Line);
            sercons.DataSource = dtIss;
            sercons.ArgumentScaleType = ScaleType.Qualitative;
            sercons.ArgumentDataMember = "Month";
            sercons.ValueScaleType = ScaleType.Numerical;
            sercons.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
            sercons.PointOptions.ValueNumericOptions.Precision = 0;
            sercons.ValueDataMembers.AddRange(new string[] { "Value" });
            consuTrend.Series.Add(sercons);
            ((XYDiagram)consuTrend.Diagram).AxisY.NumericOptions.Format = NumericFormat.Number;
            ((XYDiagram)consuTrend.Diagram).AxisY.NumericOptions.Precision = 0;

            Series serSOH = new Series("SOH", ViewType.Bar);
            serSOH.DataSource = dtList;
            serSOH.ArgumentScaleType = ScaleType.Qualitative;
            serSOH.ArgumentDataMember = "Month";
            serSOH.ValueScaleType = ScaleType.Numerical;
            serSOH.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
            ((XYDiagram)chartComp.Diagram).AxisY.NumericOptions.Format = NumericFormat.Number;
            ((XYDiagram)chartComp.Diagram).AxisY.NumericOptions.Precision = 0;
            serSOH.PointOptions.ValueNumericOptions.Precision = 0;

            serSOH.ValueDataMembers.AddRange(new string[] { "Value" });
            chartComp.Series.Add(serSOH);

            Series serMos = new Series("Month Of Stock", ViewType.Line);
            serMos.DataSource = dtMOS;
            serMos.ArgumentScaleType = ScaleType.Qualitative;
            serMos.ArgumentDataMember = "Month";
            serMos.ValueScaleType = ScaleType.Numerical;
            serMos.PointOptions.ValueNumericOptions.Format = NumericFormat.FixedPoint;
            serMos.PointOptions.ValueNumericOptions.Precision = 1;
            serMos.ValueDataMembers.AddRange(new string[] { "Value" });

            chartMOS.Series.Add(serMos);
            if (Convert.ToInt32(((XYDiagram)chartMOS.Diagram).AxisY.Range.MaxValue) <= 12)
            {
                ((XYDiagram)chartMOS.Diagram).AxisY.Range.MaxValue = 12;
            }

            //Int64 soh = bal.GetSOH(itemId,storeId,dtCurrent.Month,year);
            //if (bal.RowCount > 0)
            //{
            //Int64 amcCurent = bal.CalculateAMC(_itemId, _storeId, _dtCurrent.Month, _year);
            amcCurent = Builder.CalculateAverageConsumption(_itemId, _storeId,
                                                                  _dtCurrent.Subtract(TimeSpan.FromDays(180)),
                                                                  _dtCurrent, CalculationOptions.Monthly);
            min = info.Min * amcCurent;
            max = info.Max * amcCurent;
            nearEOP = Convert.ToInt64(amcCurent * (info.EOP + 0.25));
            target = new ConstantLine();
            target.AxisValue = min;
            //which min and max to show month
            ((XYDiagram)chartBar.Diagram).AxisY.ConstantLines.Clear();
            target.Visible = true;
            target.Title.Text = "Current Min value is " + Convert.ToInt64(target.AxisValue).ToString("#,###") + " " + lblBUnit.Text;
            target.Color = Color.Red;
            target.LineStyle.Thickness = 2;
            target.LegendText = "Min";
            ((XYDiagram)chartBar.Diagram).AxisY.ConstantLines.Add(target);

            targetEOP = new ConstantLine();
            targetEOP.AxisValue = nearEOP;
            //which min and max to show month
            //((XYDiagram)chartBar.Diagram).AxisY.ConstantLines.Clear();
            targetEOP.Visible = true;
            targetEOP.Title.Text = "Current EOP value is " + Convert.ToInt64(targetEOP.AxisValue).ToString("#,###") + " " + lblBUnit.Text;
            targetEOP.Color = Color.Yellow;
            targetEOP.LineStyle.Thickness = 2;
            targetEOP.LegendText = "EOP";
            ((XYDiagram)chartBar.Diagram).AxisY.ConstantLines.Add(targetEOP);

            targetMax = new ConstantLine();
            targetMax.AxisValue = max;
            //which min and max to show month
            targetMax.Visible = true;
            targetMax.Title.Text = "Current Max value is " + Convert.ToInt64(targetMax.AxisValue).ToString("#,###") + " " + lblBUnit.Text;
            targetMax.Color = Color.Blue;
            targetMax.LineStyle.Thickness = 2;
            targetMax.LegendText = "Max";
            ((XYDiagram)chartBar.Diagram).AxisY.ConstantLines.Add(targetMax);

            ConstantLine targetMos = new ConstantLine();
            ConstantLine targetMosMin = new ConstantLine();
            ((XYDiagram)chartMOS.Diagram).AxisY.ConstantLines.Clear();
            targetMos = new ConstantLine();
            targetMos.AxisValue = info.Max;
            //which min and max to show month
            targetMos.Visible = true;
            targetMos.Title.Text = "Current Max is " + info.Max.ToString() + " months";
            targetMos.Color = Color.Blue;
            targetMos.LineStyle.Thickness = 2;
            targetMos.LegendText = "Max";
            ((XYDiagram)chartMOS.Diagram).AxisY.ConstantLines.Add(targetMos);

            targetMosMin = new ConstantLine();
            targetMosMin.AxisValue = info.Min;
            //which min and max to show month
            targetMosMin.Visible = true;
            targetMosMin.Title.Text = "Current Min is " + info.Min.ToString() + " months";
            targetMosMin.Color = Color.Red;
            targetMosMin.LineStyle.Thickness = 2;
            targetMosMin.LegendText = "Max";
            ((XYDiagram)chartMOS.Diagram).AxisY.ConstantLines.Add(targetMosMin);
            //}

            // Generate the pie Chart for the Current SOH and EXpired Drugs

            ReceiveDoc rec = new ReceiveDoc();
            chartPie.Series.Clear();
            Items itm = new Items();
            object[] objExp = itm.GetExpiredQtyAmountItemsByID(_itemId, _storeId);
            Int64 expAmount = Convert.ToInt64(objExp[0]);
            Double expCost = Convert.ToDouble(objExp[1]);

            object[] nearObj = itm.GetNearlyExpiredQtyAmountItemsByID(_itemId, _storeId);
            Int64 nearExpAmount = Convert.ToInt64(nearObj[0]);
            double nearExpCost = Convert.ToDouble(nearObj[1]);

            Int64 soh = bal.GetSOH(_itemId, _storeId, _dtCurrent.Month, _dtCurrent.Year);
            double sohPrice = bal.GetSOHAmount(_itemId, _storeId, _dtCurrent.Month, _dtCurrent.Year);

            Int64 normal = (soh - nearExpAmount - expAmount);
            Int64 nearExpiry = nearExpAmount;
            Int64 expired = expAmount;

            object[] obj = { normal, nearExpiry, expired };

            DataTable dtSOHList = new DataTable();
            dtSOHList.Columns.Add("Type");
            dtSOHList.Columns.Add("Value");
            dtSOHList.Columns[1].DataType = typeof(Int64);
            double normalPrice = (sohPrice - nearExpCost - expAmount);

            object[] oo = { "Normal : " + normalPrice.ToString("C"), obj[0] };
            dtSOHList.Rows.Add(oo);

            object[] oo3 = { "Expired : " + expCost.ToString("C"), obj[2] };
            dtSOHList.Rows.Add(oo3);

            object[] oo2 = { "Near Expiry : " + nearExpCost.ToString("C"), obj[1] };
            dtSOHList.Rows.Add(oo2);

            Series serExpired = new Series("pie", ViewType.Pie3D);
            if (!(Convert.ToInt32(obj[0]) == 0 && Convert.ToInt32(obj[1]) == 0 && Convert.ToInt32(obj[2]) == 0))
            {
                serExpired.DataSource = dtSOHList;

                serExpired.ArgumentScaleType = ScaleType.Qualitative;
                serExpired.ArgumentDataMember = "Type";
                serExpired.ValueScaleType = ScaleType.Numerical;
                serExpired.ValueDataMembers.AddRange(new string[] { "Value" });
                serExpired.PointOptions.PointView = PointView.ArgumentAndValues;
                serExpired.LegendText = "Key";
                serExpired.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
                serExpired.PointOptions.ValueNumericOptions.Precision = 0;
                ((PieSeriesLabel)serExpired.Label).Position = PieSeriesLabelPosition.TwoColumns;
                // ((PieSeriesLabel)serExpired.Label).ColumnIndent = 2;
                ((PiePointOptions)serExpired.PointOptions).PointView = PointView.ArgumentAndValues;
                // ((PiePointOptions)serExpired.PointOptions).Separator = " , ";
                chartPie.Series.Add(serExpired);
                chartPie.Size = new System.Drawing.Size(1000, 500);
            }
        }
        /// <summary>
        /// Generates Past 12 Months charts
        /// </summary>
        private void GenerateChartsPastMonths()
        {
            Balance bal = new Balance();
            GeneralInfo info = new GeneralInfo();
            info.LoadAll();
            DataTable dtList = new DataTable();
            DataTable dtAmc = new DataTable();
            DataTable dtMOS = new DataTable();
            DataTable dtIss = new DataTable();
            DataTable dtRec = new DataTable();
            DataTable dtBB = new DataTable();

            //foreach(string s in co)
            //{
            dtList.Columns.Add("Month");
            dtList.Columns.Add("Value");
            dtList.Columns[1].DataType = typeof(Int64);

            dtMOS.Columns.Add("Month");
            dtMOS.Columns.Add("Value");
            dtMOS.Columns[1].DataType = typeof(Int32);

            dtAmc.Columns.Add("Month");
            dtAmc.Columns.Add("Value");
            dtAmc.Columns[1].DataType = typeof(Int64);

            dtIss.Columns.Add("Month");
            dtIss.Columns.Add("Value");
            dtIss.Columns[1].DataType = typeof(Int64);

            dtRec.Columns.Add("Month");
            dtRec.Columns.Add("Value");
            dtRec.Columns[1].DataType = typeof(Int64);

            dtBB.Columns.Add("Month");
            dtBB.Columns.Add("Value");
            dtBB.Columns[1].DataType = typeof(Int64);

            //dtDate.Value = DateTime.Now;
            //dtDate.CustomFormat = "MM/dd/yyyy";
            //DateTime dtCurrent = ConvertDate.DateConverter(dtDate.Text);
            DateTime dtPast = _dtCurrent.AddMonths(-11);
            //CALENDAR:
            string[] wer = { "Mes", "Tek", "Hed", "Tah", "Tir", "Yek", "Meg", "Miz", "Gen", "Sen", "Ham", "Neh" };
            string[] co = new string[12];
            int[] mon = new int[12];
            int[] yr = new int[12];
            int intialM = dtPast.Month;
            int j = 0;
            while (dtPast <= _dtCurrent && j < 12)
            {
                //mon[j] = intialM;
                //co[j] = wer[intialM-1];
                //yr[j] = (intialM < 11)?dtPast.Year: dtPast.Year +1;
                //dtPast = dtPast.AddMonths(1);
                //intialM = dtPast.Month;
                mon[j] = dtPast.Month;
                co[j] = wer[intialM - 1];
                yr[j] = dtPast.Year;
                dtPast = dtPast.AddMonths(1);
                intialM = dtPast.Month;
                j++;
            }
            //{ 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            long[] cons = new long[12];
            long[] amc = new long[12];
            DataTable dtBal = new DataTable();
            IssueDoc issd = new IssueDoc();
            Items recd = new Items();

            YearEnd yEnd = new YearEnd();
            Int64 bb = yEnd.GetBBalance(_year, _storeId, _itemId, 10);
            object[] objBB = { "Ham", bb };
            dtBB.Rows.Add(objBB);

            for (int i = 0; i < mon.Length; i++)
            {
                Int64 con = bal.GetSOH(_itemId, _storeId, mon[i], yr[i]);
                object[] str = { co[i], con };
                amc[i] = bal.CalculateAMC(_itemId, _storeId, mon[i], yr[i]);
                object[] objAmc = { co[i], amc[i] };
                decimal mos = (amc[i] > 0) ? (Convert.ToDecimal(con) / Convert.ToDecimal(amc[i])) : 0;
                mos = Decimal.Round(mos, 1);

                object[] objMos = { co[i], mos };
                Int64 issval = issd.GetIssuedQuantityByMonth(_itemId, _storeId, mon[i], yr[i]);
                object[] objIss = { co[i], issval };

                Int64 recVal = recd.GetQuantityReceiveByItemPerMonth(mon[i], _itemId, _storeId, yr[i]);
                object[] objrec = { co[i], recVal };

                dtList.Rows.Add(str);
                dtAmc.Rows.Add(objAmc);
                dtMOS.Rows.Add(objMos);
                dtIss.Rows.Add(objIss);
                dtRec.Rows.Add(objrec);
                //}
            }
            // string[] str = { ((cons[0] != 0) ? cons[0].ToString("") : "0"), ((cons[1] != 0) ? cons[1].ToString() : "0"), ((cons[2] != 0) ? cons[2].ToString() : "0"), ((cons[3] != 0) ? cons[3].ToString() : "0"), ((cons[4] != 0) ? cons[4].ToString() : "0"), ((cons[5] != 0) ? cons[5].ToString() : "0"), ((cons[6] != 0) ? cons[6].ToString() : "0"), ((cons[7] != 0) ? cons[7].ToString() : "0"), ((cons[8] != 0) ? cons[8].ToString() : "0"), ((cons[9] != 0) ? cons[9].ToString() : "0"), ((cons[10] != 0) ? cons[10].ToString() : "0"), ((cons[11] != 0) ? cons[11].ToString() : "0")};
            chartAmc.Series.Clear();
            chartComp.Series.Clear();
            chartBar.Series.Clear();
            chartMOS.Series.Clear();
            consuTrend.Series.Clear();

            Series ser = new Series("Stock On Hand", ViewType.Line);
            ser.DataSource = dtList;
            ser.ArgumentScaleType = ScaleType.Qualitative;
            ser.ArgumentDataMember = "Month";
            ser.ValueScaleType = ScaleType.Numerical;
            ser.ValueDataMembers.AddRange(new string[] { "Value" });
            chartBar.Series.Add(ser);

            Series serB = new Series("Begining Balance", ViewType.Bar);
            serB.DataSource = dtBB;
            serB.ArgumentScaleType = ScaleType.Qualitative;
            serB.ArgumentDataMember = "Month";
            serB.ValueScaleType = ScaleType.Numerical;
            serB.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
            serB.PointOptions.ValueNumericOptions.Precision = 0;
            serB.ValueDataMembers.AddRange(new string[] { "Value" });
            chartComp.Series.Add(serB);

            Series serRec = new Series("Received Qty", ViewType.Bar);
            serRec.DataSource = dtRec;
            serRec.ArgumentScaleType = ScaleType.Qualitative;
            serRec.ArgumentDataMember = "Month";
            serRec.ValueScaleType = ScaleType.Numerical;
            serRec.ValueDataMembers.AddRange(new string[] { "Value" });
            chartComp.Series.Add(serRec);

            Series serAmc = new Series("Average Monthly Consumption", ViewType.Line);
            serAmc.DataSource = dtAmc;
            serAmc.ArgumentScaleType = ScaleType.Qualitative;
            serAmc.ArgumentDataMember = "Month";
            serAmc.ValueScaleType = ScaleType.Numerical;
            serAmc.ValueDataMembers.AddRange(new string[] { "Value" });
            chartAmc.Series.Add(serAmc);

            Series serIss = new Series("Issue Qty", ViewType.Bar);
            serIss.DataSource = dtIss;
            serIss.ArgumentScaleType = ScaleType.Qualitative;
            serIss.ArgumentDataMember = "Month";
            serIss.ValueScaleType = ScaleType.Numerical;
            serIss.ValueDataMembers.AddRange(new string[] { "Value" });
            chartComp.Series.Add(serIss);

            Series serSOH = new Series("SOH", ViewType.Bar);
            serSOH.DataSource = dtList;
            serSOH.ArgumentScaleType = ScaleType.Qualitative;
            serSOH.ArgumentDataMember = "Month";
            serSOH.ValueScaleType = ScaleType.Numerical;
            serSOH.ValueDataMembers.AddRange(new string[] { "Value" });
            chartComp.Series.Add(serSOH);

            Series sercons = new Series("Consumption Trend", ViewType.Line);
            sercons.DataSource = dtIss;
            sercons.ArgumentScaleType = ScaleType.Qualitative;
            sercons.ArgumentDataMember = "Month";
            sercons.ValueScaleType = ScaleType.Numerical;
            sercons.ValueDataMembers.AddRange(new string[] { "Value" });
            consuTrend.Series.Add(sercons);

            Series serMos = new Series("Month Of Stock", ViewType.Line);
            serMos.DataSource = dtMOS;
            serMos.ArgumentScaleType = ScaleType.Qualitative;
            serMos.ArgumentDataMember = "Month";
            serMos.ValueScaleType = ScaleType.Numerical;
            serMos.ValueDataMembers.AddRange(new string[] { "Value" });

            chartMOS.Series.Add(serMos);
            ((XYDiagram)chartMOS.Diagram).AxisY.Range.MaxValue = 12;

            Int64 amcCurent = bal.CalculateAMC(_itemId, _storeId, _dtCurrent.Month, _year);
            //Int64 soh = bal.GetSOH(itemId,storeId,dtCurrent.Month,year);
            //if (bal.RowCount > 0)
            //{
            Int64 min = info.Min * amcCurent;
            Int64 max = info.Max * amcCurent;
            ConstantLine target = new ConstantLine();
            target.AxisValue = min;
            //which min and max to show month
            ((XYDiagram)chartBar.Diagram).AxisY.ConstantLines.Clear();
            target.Visible = true;
            target.Title.Text = "Current Min value is " + target.AxisValue.ToString() + " " + lblBUnit.Text;
            target.Color = Color.Red;
            target.LineStyle.Thickness = 2;
            // ((XYDiagram)chartBar.Diagram).AxisY.ConstantLines.Add(target);

            ConstantLine targetMax = new ConstantLine();
            targetMax.AxisValue = max;
            //which min and max to show month
            targetMax.Visible = true;
            targetMax.Title.Text = "Current Max value is " + targetMax.AxisValue.ToString() + " " + lblBUnit.Text;
            targetMax.Color = Color.Blue;
            targetMax.LineStyle.Thickness = 2;
            //((XYDiagram)chartBar.Diagram).AxisY.ConstantLines.Add(targetMax);
            //}
        }
        public void PopulateItemList(DataTable dtItem)
        {
            progressBar1.Visible = true;
            progressBar1.Minimum = 1;
            progressBar1.Value = 1;
            progressBar1.Maximum = dtItem.Rows.Count;

            GeneralInfo pipline = new GeneralInfo();
            pipline.LoadAll();
            int min = pipline.Min;
            int max = pipline.Max;
            int storeId = (cboStores.SelectedValue != null)?Convert.ToInt32(cboStores.SelectedValue): 1;
            lstItem.Items.Clear();
            int col = 0;
            int count = 1;
            Balance bal = new Balance();
            Items itmIssues = new Items();

            dtDate.Value = DateTime.Now;
            dtDate.CustomFormat = "MM/dd/yyyy";
            DateTime dtCurrent = Convert.ToDateTime(dtDate.Text);
            int year = dtCurrent.Year;

            foreach (DataRow dr in dtItem.Rows)
            {
                int itemId = Convert.ToInt32(dr["ID"]);
                string itemName = dr["ItemName"].ToString() + " - " + dr["DosageForm"].ToString() + " - " + dr["Strength"].ToString();
                DataTable dtBal = bal.GetLastBalance(Convert.ToInt32(dr["ID"]),storeId);
                double AMC = Builder.CalculateAverageConsumption(itemId, storeId, dtCurrent.Subtract(TimeSpan.FromDays(180)), dtCurrent, CalculationOptions.Monthly);//(dtBal.Rows.Count <= 0) ? 0 : ((dtBal.Rows[0]["AMC"].ToString() != "")?Convert.ToInt64(dtBal.Rows[0]["AMC"]): 0);
                double MinCon =  AMC * min;
                double maxCon = AMC * max;
                Int64 SOH = (dtBal.Rows.Count > 0) ? Convert.ToInt64(dtBal.Rows[0]["SOH"]) : 0;
                decimal MOS = (AMC != 0)? (Convert.ToDecimal(SOH )/ Convert.ToDecimal(AMC)) : 0;
                MOS = Decimal.Round(MOS, 1);
                int[] mon = {11, 12, 1, 2, 3, 4, 5, 6 ,7, 8,9, 10 };
                long[] cons = new long[12];
                for (int i = 0; i < mon.Length; i++)
                {
                    int yr = (i < 11)?year:year-1;
                    cons[i] = itmIssues.GetQuantityReceiveByItemPerMonth(mon[i], itemId,storeId,yr);
                }
                string[] str = { count.ToString(), itemName, ((SOH != 0) ? SOH.ToString("#,###") : "0"), ((cons[0] != 0) ? cons[0].ToString("#,###") : "0"), ((cons[1] != 0) ? cons[1].ToString("#,###") : "0"), ((cons[2] != 0) ? cons[2].ToString("#,###") : "0"), ((cons[3] != 0) ? cons[3].ToString("#,###") : "0"), ((cons[4] != 0) ? cons[4].ToString("#,###") : "0"), ((cons[5] != 0) ? cons[5].ToString("#,###") : "0"), ((cons[6] != 0) ? cons[6].ToString("#,###") : "0"), ((cons[7] != 0) ? cons[7].ToString("#,###") : "0"), ((cons[8] != 0) ? cons[8].ToString("#,###") : "0"), ((cons[9] != 0) ? cons[9].ToString("#,###") : "0"), ((cons[10] != 0) ? cons[10].ToString("#,###") : "0"), ((cons[11] != 0) ? cons[11].ToString("#,###") : "0") };

                //string[] str = { count.ToString(), itemName, ((SOH != 0)?SOH.ToString("#,###") :"0"), itmIssues.GetQuantityReceiveByItemPerMonth(9, itemId).ToString(), itmIssues.GetQuantityReceiveByItemPerMonth(10, itemId).ToString(), itmIssues.GetQuantityReceiveByItemPerMonth(11, itemId).ToString(), itmIssues.GetQuantityReceiveByItemPerMonth(12, itemId).ToString(), itmIssues.GetQuantityReceiveByItemPerMonth(1, itemId).ToString(), itmIssues.GetQuantityReceiveByItemPerMonth(2, itemId).ToString(), itmIssues.GetQuantityReceiveByItemPerMonth(3, itemId).ToString(), itmIssues.GetQuantityReceiveByItemPerMonth(4, itemId).ToString(), itmIssues.GetQuantityReceiveByItemPerMonth(5, itemId).ToString(), itmIssues.GetQuantityReceiveByItemPerMonth(6, itemId).ToString(), itmIssues.GetQuantityReceiveByItemPerMonth(7, itemId).ToString(), itmIssues.GetQuantityReceiveByItemPerMonth(8, itemId).ToString() };
                ListViewItem listItem = new ListViewItem(str);
                listItem.ToolTipText = itemName;
                listItem.Tag = dr["ID"];
                if (col != 0)
                {
                    listItem.BackColor = Color.FromArgb(233, 247, 248);
                    col = 0;
                }
                else
                {
                    col++;
                }
                lstItem.Items.Add(listItem);
                count++;
                progressBar1.PerformStep();
            }
            progressBar1.Visible = false;
        }