Пример #1
0
        private void LoadData()
        {
            _dataTable = new DataTable();

            int.TryParse(MainWnd._mouseOverMachineNumber, out var machine);
            if (machine <= 0 || machine > 210)
            {
                MessageBox.Show("Invalid machine number.", "Sinotico", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            using (var con = new SqlConnection(MainWnd.conString))
            {
                var cmd = new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "[getcleanersonmachine]";
                cmd.Connection  = con;

                cmd.Parameters.Add("@startdate", SqlDbType.DateTime).Value   = MainWnd.Get_from_date();
                cmd.Parameters.Add("@enddate", SqlDbType.DateTime).Value     = MainWnd.Get_to_date();
                cmd.Parameters.Add("@machine", SqlDbType.Int).Value          = machine;
                cmd.Parameters.Add("@shiftArray", SqlDbType.NVarChar).Value  = MainWnd.Get_shift_array().ToString();
                cmd.Parameters.Add("@puliziaType", SqlDbType.NVarChar).Value = _puliziaType;

                con.Open();
                var dr = cmd.ExecuteReader();
                _dataTable.Load(dr);
                con.Close();
                dr.Close();
            }

            dgvReport.DataSource = _dataTable;

            dgvReport.Columns[0].Visible = false;
        }
Пример #2
0
 private void LoadProcedure(DataTable dt, int idm)
 {
     using (var con = new SqlConnection(MainWnd.conString))
     {
         var cmd = new SqlCommand();
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Connection  = con;
         cmd.CommandText = "[getscartirammendireportdata]";
         cmd.Parameters.Add("@machine", SqlDbType.Int).Value       = idm;
         cmd.Parameters.Add("@fromDate", SqlDbType.DateTime).Value = MainWnd.Get_from_date();
         cmd.Parameters.Add("@toDate", SqlDbType.DateTime).Value   = MainWnd.Get_to_date();
         cmd.Parameters.Add("@shift", SqlDbType.NVarChar).Value    = MainWnd.Get_shift_array().ToString();
         con.Open();
         var dr = cmd.ExecuteReader();
         dt.Load(dr);
         con.Close();
         dr.Close();
     }
 }
Пример #3
0
        private void GetData()
        {
            CreateColumns();
            var dt = new DataTable();

            if (dgvReport.DataSource != null)
            {
                dgvReport.DataSource = null;
            }
            //var oper = cbOperat.SelectedIndex <= -1 ? string.Empty : cbOperat.Text;
            using (var con = new System.Data.SqlClient.SqlConnection(MainWnd.conString))
            {
                var cmd = new System.Data.SqlClient.SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Connection  = con;
                if (Mode != "cquality")
                {
                    cmd.CommandText = "[getcleanersticks]";
                }
                else
                {
                    cmd.CommandText = "[getcqualityticks]";
                }
                DateTime startDate = new DateTime();
                DateTime endDate   = new DateTime();
                if (SingleMachineSelected)
                {
                    dtpEndDate.Visible   = false;
                    dtpStartDate.Visible = false;
                    cmd.Parameters.Add("@idm", SqlDbType.NVarChar).Value = Machine;
                    startDate = MainWnd.Get_from_date();
                    endDate   = MainWnd.Get_to_date();
                }
                else
                {
                    startDate = new DateTime(dtpStartDate.Value.Year, dtpStartDate.Value.Month, dtpStartDate.Value.Day);
                    endDate   = new DateTime(dtpEndDate.Value.Year, dtpEndDate.Value.Month, dtpEndDate.Value.Day);
                }
                if ((tbColore.Text != string.Empty || tbCommessa.Text != string.Empty ||
                     tbCotta.Text != string.Empty || tbComponente.Text != string.Empty) && Mode == "cquality")
                {
                    cmd.Parameters.Add("@startdate", SqlDbType.DateTime).Value = new DateTime(2019, 1, 1);
                    cmd.Parameters.Add("@enddate", SqlDbType.DateTime).Value   = DateTime.Now;
                }
                else
                {
                    cmd.Parameters.Add("@startdate", SqlDbType.DateTime).Value = startDate;
                    cmd.Parameters.Add("@enddate", SqlDbType.DateTime).Value   = endDate;
                }

                if (tbColore.Text != string.Empty && Mode == "cquality")
                {
                    cmd.Parameters.Add("@colorValue", SqlDbType.NVarChar).Value = tbColore.Text;
                }
                if (tbCommessa.Text != string.Empty && Mode == "cquality")
                {
                    cmd.Parameters.Add("@commessaValue", SqlDbType.NVarChar).Value = tbCommessa.Text;
                }
                if (tbCotta.Text != string.Empty && Mode == "cquality")
                {
                    cmd.Parameters.Add("@cottaValue", SqlDbType.NVarChar).Value = tbCotta.Text;
                }
                if (tbComponente.Text != string.Empty && Mode == "cquality")
                {
                    cmd.Parameters.Add("@componenteValue", SqlDbType.NVarChar).Value = tbComponente.Text;
                }

                con.Open();
                var dr = cmd.ExecuteReader();
                dt.Load(dr);
                con.Close();
                dr.Close();
            }
            var nr           = 0;
            var lastOperator = string.Empty;
            var lastEndTime  = DateTime.MinValue;
            var mediaWork    = 0.0;
            var mediaPause   = 0.0;

            if (dt.Rows.Count <= 0)
            {
                try
                {
                    if (_filtersList.Count > 0)
                    {
                        foreach (ComboBox c in _filtersList)
                        {
                            c.Hide();
                        }
                    }
                    if (_media_labels.Length > 0)
                    {
                        foreach (Label l in _media_labels)
                        {
                            l.Hide();
                        }
                    }
                }
                catch
                {
                    //dgvReport.Controls.Clear();
                    MessageBox.Show("No data.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                return;
            }
            var puliziaMachines = new List <int>();

            foreach (DataRow row in dt.Rows)
            {
                //2019-02-20 17:29:36.707	10	test user	1	Pulizia Fronture	2019-02-20 17:29:36.723	2019-02-20 17:29:57.190
                nr++;
                int.TryParse(row[1].ToString(), out var machine);
                var      operat     = row[2].ToString();
                var      prog       = row[3].ToString();
                var      note       = string.Empty;
                var      commessa   = string.Empty;
                var      articolo   = string.Empty;
                var      componente = string.Empty;
                var      taglia     = string.Empty;
                var      colore     = string.Empty;
                var      cotta      = string.Empty;
                var      type       = string.Empty;
                int      cqId       = 0;
                DateTime dtstart    = new DateTime();
                DateTime dtend      = new DateTime();
                bool     alarm      = false;
                if (Mode == "cquality")
                {
                    dtstart    = Convert.ToDateTime(row[4]);
                    dtend      = Convert.ToDateTime(row[5]);
                    note       = row[6].ToString();
                    commessa   = row[7].ToString();
                    articolo   = row[8].ToString();
                    componente = row[9].ToString();
                    taglia     = row[10].ToString();
                    colore     = row[11].ToString();
                    cotta      = row[12].ToString();
                    int.TryParse(row[13].ToString(), out cqId);
                }
                else
                {
                    type = row[4].ToString();
                    bool.TryParse(row[8].ToString(), out alarm);
                    dtstart = Convert.ToDateTime(row[5]);
                    dtend   = Convert.ToDateTime(row[6]);
                    note    = row[7].ToString();
                }
                var newRow = _table.NewRow();
                if (!puliziaMachines.Contains(machine))
                {
                    puliziaMachines.Add(machine);
                }
                if (operat != lastOperator)
                {
                    lastEndTime = DateTime.MinValue;
                }
                newRow[0] = nr.ToString();
                if (Mode == "cquality")
                {
                    Tuple <string, string> info = GetLineSquadra(machine);
                    newRow[1] = info.Item1;
                    newRow[2] = info.Item2;
                    newRow[3] = machine;
                    newRow[4] = operat.ToString();
                    newRow[5] = prog.ToString();
                    newRow[6] = dtstart.ToString("dd/MM/yyyy HH:mm:ss");
                    newRow[7] = dtend.ToString("dd/MM/yyyy HH:mm:ss");
                }
                else
                {
                    newRow[1] = machine;
                    newRow[2] = operat.ToString();
                    newRow[3] = prog.ToString();
                    newRow[4] = "";
                    newRow[5] = type.ToString();
                    newRow[6] = dtstart.ToString("dd/MM/yyyy HH:mm:ss");
                    newRow[7] = dtend.ToString("dd/MM/yyyy HH:mm:ss");
                }
                var currDate   = new DateTime(dtstart.Year, dtstart.Month, dtstart.Day);
                var tmpControl = dtend.Subtract(dtstart).TotalSeconds;
                var controlSec = TimeSpan.FromSeconds(tmpControl);
                mediaWork += tmpControl;
                var tmpPause     = 0.0;
                var controlPause = new TimeSpan(0, 0, 0);
                if (lastEndTime == DateTime.MinValue)
                {
                    controlPause = new TimeSpan(0, 0, 0);
                }
                else
                {
                    tmpPause     = dtstart.Subtract(lastEndTime).TotalSeconds;
                    controlPause = TimeSpan.FromSeconds(tmpPause);

                    mediaPause += tmpPause;
                }
                if (Mode == "cquality")
                {
                    newRow[8]  = controlSec.ToString(@"hh\:mm\:ss");
                    newRow[9]  = controlPause.ToString(@"hh\:mm\:ss");
                    newRow[10] = note;
                    newRow[11] = commessa;
                    newRow[12] = articolo;
                    newRow[13] = componente;
                    newRow[14] = taglia;
                    newRow[15] = colore;
                    newRow[16] = cotta;
                    newRow[17] = cqId;
                }
                else
                {
                    newRow[8]  = controlSec.ToString(@"hh\:mm\:ss");
                    newRow[9]  = controlPause.ToString(@"hh\:mm\:ss");
                    newRow[10] = alarm ? "1" : "0";
                    newRow[11] = note;
                }
                _table.Rows.Add(newRow);
                lastEndTime  = dtend;
                lastOperator = operat;
            }
            mediaWork  = mediaWork / nr;
            mediaPause = mediaPause / nr;
            var mediaWorkTime  = TimeSpan.FromSeconds(mediaWork);
            var mediaPauseTime = TimeSpan.FromSeconds(mediaPause);

            days = Convert.ToInt32(dtpEndDate.Value.Subtract(dtpStartDate.Value).TotalDays) + 1;
            dgvReport.DataSource = _table;
            long _tot_pause     = 0;
            long _tot_controllo = 0;

            foreach (DataGridViewRow row in dgvReport.Rows)
            {
                TimeSpan.TryParse(row.Cells["Durata controllo"].Value.ToString(), out var durata_controllo);
                TimeSpan.TryParse(row.Cells["Durata pausa"].Value.ToString(), out var durata_pausa);
                _tot_pause     += durata_pausa.Ticks;
                _tot_controllo += durata_controllo.Ticks;
            }
            TimeSpan totTsTime = TimeSpan.FromTicks(_tot_controllo + _tot_pause);
            string   totalTime = string.Format("{0}:{1}:{2}",
                                               (int)totTsTime.TotalHours,
                                               totTsTime.Minutes,
                                               totTsTime.Seconds);
            TimeSpan controlloTsTime = TimeSpan.FromTicks(_tot_controllo);
            string   controlloTime   = string.Format("{0}:{1}:{2}",
                                                     (int)controlloTsTime.TotalHours,
                                                     controlloTsTime.Minutes,
                                                     controlloTsTime.Seconds);
            TimeSpan pausaTsTime = TimeSpan.FromTicks(_tot_pause);
            string   pausaTime   = string.Format("{0}:{1}:{2}",
                                                 (int)pausaTsTime.TotalHours,
                                                 pausaTsTime.Minutes,
                                                 pausaTsTime.Seconds);

            lblMedia.Text = "Giorni " + days + "     " //Media " + ""
                                                       //+ mediaWorkTime.ToString(@"hh\:mm\:ss") + "   |   "
                                                       //+ mediaPauseTime.ToString(@"hh\:mm\:ss")
                            + "     Tot. durata controllo:  " + controlloTime
                            + "  |  " + "Tot. durata pausa:  " + pausaTime
                            + " | Tot. time: " + totalTime;
            totMachines = puliziaMachines.Count;
            string txt = Mode == "cquality" ? "Tot. CQ: " : "Tot. pulizie:  ";

            lblPuliziaJob.Text = txt + nr +
                                 "  Tot. machines:  " + totMachines.ToString();
            if (Mode == "cquality")
            {
                dgvReport.Columns["Linea"].Width      = 65;
                dgvReport.Columns["Squadra"].Width    = 65;
                dgvReport.Columns["Note"].Width       = 180;
                dgvReport.Columns["Commessa"].Width   = 70;
                dgvReport.Columns["Articolo"].Width   = 70;
                dgvReport.Columns["Taglia"].Width     = 50;
                dgvReport.Columns["Componente"].Width = 70;
                dgvReport.Columns["Colore"].Width     = 50;
                dgvReport.Columns["Cotta"].Width      = 50;
                dgvReport.Columns["idjob"].Visible    = false;
                dgvReport.Columns["Operatore"].Width  = 130;
            }
            else
            {
                dgvReport.Columns["Note"].Width      = 360;
                dgvReport.Columns["Operatore"].Width = 130;
                dgvReport.Columns["Squadra"].Width   = 50;
                dgvReport.Columns["Alarme"].Width    = 60;
            }
            dgvReport.Columns["Nr"].Width               = 50;
            dgvReport.Columns["Mac"].Width              = 50;
            dgvReport.Columns["Progr"].Width            = 40;
            dgvReport.Columns["Data Inizio"].Width      = 130;
            dgvReport.Columns["Data Fine"].Width        = 130;
            dgvReport.Columns["Durata controllo"].Width = 70;
            dgvReport.Columns["Durata pausa"].Width     = 70;
            dgvReport.Sort(dgvReport.Columns["Operatore"], ListSortDirection.Ascending);
            int _current_row = 1;

            foreach (DataGridViewRow row in dgvReport.Rows)
            {
                row.Cells["Nr"].Value = _current_row;
                _current_row++;
            }
            if (Mode == "cquality")
            {
                var operators     = 1;
                var operatorsName = dgvReport.Rows[0].Cells[4].Value.ToString();
                foreach (DataGridViewRow row in dgvReport.Rows)
                {
                    var currentOperator = row.Cells[4].Value.ToString();
                    if (currentOperator != operatorsName)
                    {
                        operators++;
                        operatorsName = currentOperator;
                    }
                }
                double.TryParse(operators.ToString(), out var numOfOperators);
                TimeSpan tmpOtherTime   = TimeSpan.FromHours(numOfOperators * 7.5);
                var      otherTimeTicks = tmpOtherTime.Ticks;
                TimeSpan otherTime      = TimeSpan.FromTicks(otherTimeTicks - (_tot_controllo + _tot_pause));
                string   frmtOtherTime  = string.Format("{0}:{1}:{2}",
                                                        (int)otherTime.TotalHours,
                                                        otherTime.Minutes,
                                                        otherTime.Seconds);
                lblMedia.Text += "    Tot. ore disponsibili " + frmtOtherTime;
            }
            if (dgvReport.Rows.Count >= 1)
            {
                if (dgvReport.Controls.OfType <ComboBox>().Count() <= 0)
                {
                    CreateFilters();
                    _media_labels[0].Text = mediaWorkTime.ToString(@"hh\:mm\:ss");
                    _media_labels[1].Text = mediaPauseTime.ToString(@"hh\:mm\:ss");
                    PopulateFiltersData();
                }
                else
                {
                    PopulateFiltersData();
                    foreach (ComboBox c in _filtersList)
                    {
                        c.Show();
                    }
                    foreach (Label l in _media_labels)
                    {
                        l.Show();
                    }
                }
            }
        }
Пример #4
0
        private void GetData(int idm)
        {
            _repData = new DataTable();
            _repData.Columns.Add("Machine");
            _repData.Columns.Add("Articolo");
            _repData.Columns.Add("Commessa");
            _repData.Columns.Add("Componente");
            _repData.Columns.Add("Taglia");
            _repData.Columns.Add("Colore");
            _repData.Columns.Add("Cotta");
            _repData.Columns.Add("Data Inizio");
            _repData.Columns.Add("Data Fine");
            _repData.Columns.Add("Durata CQ");
            _repData.Columns.Add("Operatore");
            _repData.Columns.Add("Note");
            var tmpTable = new DataTable();

            using (var con = new SqlConnection(MainWnd.conString))
            {
                var cmd = new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Connection  = con;
                cmd.CommandText = "[getcqreportdata]";
                cmd.Parameters.Add("@idm", SqlDbType.Int).Value           = idm;
                cmd.Parameters.Add("@fromDate", SqlDbType.DateTime).Value = MainWnd.Get_from_date();
                cmd.Parameters.Add("@toDate", SqlDbType.DateTime).Value   = MainWnd.Get_to_date();
                con.Open();
                var dr = cmd.ExecuteReader();
                tmpTable.Load(dr);
                con.Close();
                dr.Close();
            }
            if (tmpTable.Rows.Count <= 0)
            {
                dgvReport.DataSource = _repData;
                return;
            }
            foreach (DataRow row in tmpTable.Rows)
            {
                var machine  = row[0].ToString();
                var art      = row[1].ToString();
                var commessa = row[2].ToString();
                var comp     = row[3].ToString();
                var taglia   = row[4].ToString();
                var col      = row[5].ToString();
                var cotta    = row[6].ToString();
                DateTime.TryParse(row[7].ToString(), out var startTime);
                DateTime.TryParse(row[8].ToString(), out var endTime);
                var tsStart      = TimeSpan.FromTicks(startTime.Ticks);
                var tsEnd        = TimeSpan.FromTicks(endTime.Ticks);
                var durationTime = TimeSpan.FromTicks(tsEnd.Ticks - tsStart.Ticks);
                var note         = row[9].ToString();
                var op           = row[10].ToString();
                var newRow       = _repData.NewRow();

                newRow[0]  = machine;
                newRow[1]  = art;
                newRow[2]  = commessa;
                newRow[3]  = comp;
                newRow[4]  = taglia;
                newRow[5]  = col;
                newRow[6]  = cotta;
                newRow[7]  = startTime;
                newRow[8]  = endTime;
                newRow[9]  = durationTime;
                newRow[10] = op;
                newRow[11] = note;
                _repData.Rows.Add(newRow);
            }
            dgvReport.DataSource                   = _repData;
            dgvReport.Columns["Note"].Width        = 330;
            dgvReport.Columns["Data Inizio"].Width = 130;
            dgvReport.Columns["Data Fine"].Width   = 130;
            dgvReport.Columns["Taglia"].Width      = 50;
            dgvReport.Columns["Machine"].Width     = 60;
            dgvReport.Columns["Commessa"].Width    = 70;
            dgvReport.Columns["Taglia"].Width      = 60;
            dgvReport.Columns["Cotta"].Width       = 50;
            dgvReport.Columns["Operatore"].Width   = 170;
            dgvReport.Columns["Colore"].Width      = 60;
        }
Пример #5
0
        public void PopulateChartData()
        {
            var global      = new Globals();
            var chart_data  = new DataTable();
            var table_data  = new DataTable();
            var cbArray     = new CheckBox[] { MainWnd._sqOne, MainWnd._sqTwo, MainWnd._sqThree };
            var currentCb   = 0;
            var processedCb = 0;
            var checks      = 0;
            var checksDone  = 0;
            var gridIndex   = 0;

            foreach (var cb in cbArray)
            {
                if (cb.Checked)
                {
                    checks++;
                }
            }

            foreach (var chart in new System.Windows.Forms.DataVisualization.Charting.Chart[] { chart1, chart2, chart3 })
            {
                table_data = new DataTable();

                var machinesArray = string.Empty;

                if (processedCb >= 3 || checks <= checksDone)
                {
                    return;
                }

                while (processedCb < 3)
                {
                    if (cbArray[processedCb].Checked)
                    {
                        currentCb = processedCb;
                        processedCb++;
                        break;
                    }
                    processedCb++;
                }

                if (currentCb == 0)
                {
                    machinesArray = string.Empty;
                    machinesArray = ",1,2,3,4,5,6,7,8,9,10,11,12,13,14" +
                                    ",15,16,17,18,19,20,21,22,23,24,25,26,27,28" +
                                    ",29,30,31,32,33,34,35,36,37,38,39,40,41,42" +
                                    ",43,44,45,46,47,48,49,50,51,52,53,54,55,56" +
                                    ",57,58,59,60,61,62,63,64,65,66,67,68,69,70,";
                    checksDone++;
                }
                else if (currentCb == 1)
                {
                    machinesArray = string.Empty;
                    machinesArray = ",71,72,73,74,75,76,77,78,79,80,81,82,83,84" +
                                    ",85,86,87,88,89,90,91,92,93,94,95,96,97,98" +
                                    ",99,100,101,102,103,104,105,106,107,108,109,110,111,112" +
                                    ",113,114,115,116,117,118,119,120,121,122,123,124,125,126" +
                                    ",127,128,129,130,131,132,133,134,135,136,137,138,139,140,";
                    checksDone++;
                }
                else if (currentCb == 2)
                {
                    machinesArray = string.Empty;
                    machinesArray = ",141,142,143,144,145,146,147,148,149,150,151,152,153,154" +
                                    ",155,156,157,158,159,160,161,162,163,164,165,166,167,168" +
                                    ",169,170,171,172,173,174,175,176,177,178,179,180,181,182" +
                                    ",183,184,185,186,187,188,189,190,191,192,193,194,195,196" +
                                    ",197,198,199,200,201,202,203,204,205,206,207,208,209,210,";
                    checksDone++;
                }
                else
                {
                    continue;
                }

                chart.Visible = true;
                _dgvTables[gridIndex].Visible = true;

                using (var con = new SqlConnection(MainWnd.conString))
                {
                    var cmd = new SqlCommand("get_data_in_hold_per_hour", con);
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add("@from_date", SqlDbType.DateTime).Value = MainWnd.Get_to_date();
                    cmd.Parameters.Add("@to_date", SqlDbType.DateTime).Value   = MainWnd.Get_to_date();
                    cmd.Parameters.Add("@machine", SqlDbType.VarChar).Value    = machinesArray;

                    chart_data = new DataTable();

                    con.Open();
                    var dr = cmd.ExecuteReader();
                    chart_data.Load(dr);
                    con.Close();
                    dr.Close();
                    cmd = null;

                    cmd             = new SqlCommand("get_data_in_hold_per_shift", con);
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add("@from_date", SqlDbType.DateTime).Value = MainWnd.Get_from_date();
                    cmd.Parameters.Add("@to_date", SqlDbType.DateTime).Value   = MainWnd.Get_to_date();
                    cmd.Parameters.Add("@shift", SqlDbType.VarChar).Value      = MainWnd.Get_shift_array().ToString();
                    cmd.Parameters.Add("@machine", SqlDbType.VarChar).Value    = machinesArray;

                    con.Open();
                    dr = cmd.ExecuteReader();
                    table_data.Load(dr);
                    con.Close();
                    dr.Close();
                    cmd = null;
                }

                chart.ChartAreas.Clear();
                chart.Series.Clear();

                chart.ChartAreas.Add("hold");
                chart.ChartAreas[0].AxisX.MajorGrid.LineColor      = SystemColors.Control;
                chart.ChartAreas[0].AxisY.MajorGrid.LineColor      = SystemColors.Control;
                chart.ChartAreas[0].AxisX.MajorGrid.IntervalOffset = 20;
                chart.ChartAreas[0].BackColor = SystemColors.Control;
                chart.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.Gray;
                chart.ChartAreas[0].AxisY.LineColor            = Color.FromArgb(158, 158, 158);
                chart.ChartAreas[0].AxisX.LineColor            = Color.FromArgb(158, 158, 158);
                chart.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.Gray;
                chart.ChartAreas[0].AxisY.Maximum = 30000;

                chart.Series.Add("knitt");
                chart.Series.Add("manual");
                chart.Series.Add("yarn");
                chart.Series.Add("generic");

                chart.Series["knitt"].Color   = Color.FromArgb(0, 191, 254);
                chart.Series["manual"].Color  = Color.FromArgb(255, 2, 0);
                chart.Series["yarn"].Color    = Color.FromArgb(131, 0, 125);
                chart.Series["generic"].Color = Color.Gold;

                for (var i = 0; i <= chart.Series.Count - 1; i++)
                {
                    chart.Series[i].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn;
                }

                List <int> shiftHours = new List <int>();
                int[]      legendValues = new int[4];
                int        _knitt = 0, _manual = 0, _yarn = 0, _generics = 0;
                foreach (var shift in MainWnd.ListOfSelectedShifts)
                {
                    shiftHours.Clear();

                    if (shift == "cbMorning")
                    {
                        for (int i = 7; i <= 14; i++)
                        {
                            shiftHours.Add(i);
                        }
                    }
                    else if (shift == "cbAfternoon")
                    {
                        for (int i = 15; i <= 22; i++)
                        {
                            shiftHours.Add(i);
                        }
                    }
                    else if (shift == "cbNight")
                    {
                        for (int i = 0; i <= 6; i++)
                        {
                            shiftHours.Add(i);
                        }
                        shiftHours.Add(23);
                    }

                    legendValues[3] += _generics;
                    legendValues[2] += _yarn;
                    legendValues[1] += _manual;
                    legendValues[0] += _knitt;

                    _knitt    = 0;
                    _manual   = 0;
                    _yarn     = 0;
                    _generics = 0;

                    foreach (DataRow row in chart_data.Rows)
                    {
                        var hour = Convert.ToInt32(row[0]);

                        int knit, comb, manual, yarn, needle, shock, roller, other;

                        if (shiftHours.Contains(hour))
                        {
                            knit   = Convert.ToInt32(row[1]) > 0 ? Convert.ToInt32(row[1]) : knit = 0;
                            comb   = Convert.ToInt32(row[3]) > 0 ? Convert.ToInt32(row[3]) : comb = 0;
                            manual = Convert.ToInt32(row[4]) > 0 ? Convert.ToInt32(row[4]) : manual = 0;
                            yarn   = Convert.ToInt32(row[5]) > 0 ? Convert.ToInt32(row[5]) : yarn = 0;
                            needle = Convert.ToInt32(row[6]) > 0 ? Convert.ToInt32(row[6]) : needle = 0;
                            shock  = Convert.ToInt32(row[7]) > 0 ? Convert.ToInt32(row[7]) : shock = 0;
                            roller = Convert.ToInt32(row[8]) > 0 ? Convert.ToInt32(row[8]) : roller = 0;
                            other  = Convert.ToInt32(row[9]) > 0 ? Convert.ToInt32(row[9]) : other = 0;

                            _knitt    += knit;
                            _manual   += manual;
                            _yarn     += yarn;
                            _generics += comb + needle + shock + roller + other;
                        }
                    }
                    chart.Series["knitt"].Points.AddXY(shift.Remove(0, 2), _knitt.ToString());
                    chart.Series["manual"].Points.AddXY(shift.Remove(0, 2), _manual.ToString());
                    chart.Series["yarn"].Points.AddXY(shift.Remove(0, 2), _yarn.ToString());
                    chart.Series["generic"].Points.AddXY(shift.Remove(0, 2), _generics.ToString());

                    chart.Titles[chart.Name + "Title"].Visible = true;
                    chart.Titles[chart.Name + "Title"].Text    = "SQUADRA " + (currentCb + 1).ToString() + ":";

                    int position = 0;
                    foreach (var serie in chart.Series)
                    {
                        serie.IsVisibleInLegend = true;
                        serie.LegendText        = " = " + legendValues[position];
                        position++;
                    }
                    position = 0;
                }

                var conv_table_data = new DataTable();

                double stopTime    = 0;
                double total       = 0;
                double genericStop = 0;
                double allStops    = 0;

                foreach (DataColumn dc in table_data.Columns)
                {
                    if (dc.ColumnName == "stop_time" || dc.ColumnName == "Color" || dc.ColumnName == "Size" ||
                        dc.ColumnName == "Component")
                    {
                        continue;
                    }

                    conv_table_data.Columns.Add(dc.ColumnName); //copies datacolumns
                }

                conv_table_data.Columns.Add("Generic Stops");
                conv_table_data.Columns.Add("TOTAL");

                var newRow       = conv_table_data.NewRow();
                var grid_col_idx = 5;

                TimeSpan formatedTs = new TimeSpan();

                for (var col_idx = 8; col_idx < 16; col_idx++)
                {
                    double current_cell_value = 0;
                    for (var row_idx = 0; row_idx < table_data.Rows.Count; row_idx++)
                    {
                        current_cell_value += Convert.ToDouble(table_data.Rows[row_idx][col_idx]);
                    }

                    formatedTs = TimeSpan.FromSeconds(current_cell_value);
                    string time = string.Format("{0}:{1}",
                                                (int)formatedTs.TotalHours < 10 ?
                                                "0" + ((int)formatedTs.TotalHours).ToString() :
                                                ((int)formatedTs.TotalHours).ToString(),
                                                (int)formatedTs.Minutes < 10 ?
                                                "0" + ((int)formatedTs.Minutes).ToString() :
                                                ((int)formatedTs.Minutes).ToString());
                    newRow[grid_col_idx] = time;
                    grid_col_idx++;
                    total += current_cell_value;

                    if (col_idx == 8)
                    {
                        continue;
                    }
                    else
                    {
                        allStops += current_cell_value;
                    }
                }

                for (var row_idx = 0; row_idx < table_data.Rows.Count; row_idx++)
                {
                    stopTime += Convert.ToInt32(table_data.Rows[row_idx][16]);
                }

                genericStop = stopTime - allStops;

                if (genericStop < 0)
                {
                    genericStop = 0;
                }
                total += genericStop;

                formatedTs = TimeSpan.FromSeconds(genericStop);
                string generic_time = string.Format("{0}:{1}",
                                                    (int)formatedTs.TotalHours < 10 ?
                                                    "0" + ((int)formatedTs.TotalHours).ToString() :
                                                    ((int)formatedTs.TotalHours).ToString(),
                                                    (int)formatedTs.Minutes < 10 ?
                                                    "0" + ((int)formatedTs.Minutes).ToString() :
                                                    ((int)formatedTs.Minutes).ToString());
                newRow[13] = generic_time;
                formatedTs = TimeSpan.FromSeconds(total);
                string total_time = string.Format("{0}:{1}",
                                                  (int)formatedTs.TotalHours < 10 ?
                                                  "0" + ((int)formatedTs.TotalHours).ToString() :
                                                  ((int)formatedTs.TotalHours).ToString(),
                                                  (int)formatedTs.Minutes < 10 ?
                                                  "0" + ((int)formatedTs.Minutes).ToString() :
                                                  ((int)formatedTs.Minutes).ToString());
                newRow[14] = total_time;
                conv_table_data.Rows.Add(newRow);

                StyleGridView(_dgvTables[gridIndex]);
                _dgvTables[gridIndex].DataSource = conv_table_data;

                gridIndex++;
            }
        }
Пример #6
0
        private void CreateMachinesReport()
        {
            LoadingInfo.InfoText = "Loading chart...";
            LoadingInfo.ShowLoading();

            /*
             **Create controls based on shifts selection
             */

            var global = new Globals();

            var chart_data = new DataTable();
            var table_data = new DataTable();

            // Loads charts data

            using (var con = new SqlConnection(MainWnd.conString))
            {
                var cmd = new SqlCommand("get_data_in_hold_per_hour", con);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@from_date", SqlDbType.DateTime).Value = MainWnd.Get_to_date();
                cmd.Parameters.Add("@to_date", SqlDbType.DateTime).Value   = MainWnd.Get_to_date();
                cmd.Parameters.Add("@machine", SqlDbType.VarChar).Value    = _machines_array.ToString();

                con.Open();
                var dr = cmd.ExecuteReader();
                chart_data.Load(dr);
                con.Close();
                dr.Close();
                cmd = null;

                // Loads table data

                cmd             = new SqlCommand("get_data_in_hold_per_shift", con);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@from_date", SqlDbType.DateTime).Value = MainWnd.Get_from_date();
                cmd.Parameters.Add("@to_date", SqlDbType.DateTime).Value   = MainWnd.Get_to_date();
                cmd.Parameters.Add("@shift", SqlDbType.VarChar).Value      = MainWnd.Get_shift_array().ToString();
                cmd.Parameters.Add("@machine", SqlDbType.VarChar).Value    = _machines_array.ToString();

                con.Open();
                dr = cmd.ExecuteReader();
                table_data.Load(dr);
                con.Close();
                dr.Close();
                cmd = null;
            }

            // Creates controls with data structure

            var topObjLocation  = 20;
            var leftObjLocation = 17;
            var objW            = Width - 50;

            _panel_shift            = new Panel();
            _panel_shift.Dock       = DockStyle.Fill;
            _panel_shift.AutoScroll = true;
            Controls.Add(_panel_shift);
            _panel_shift.BringToFront();

            foreach (var shift in MainWnd.ListOfSelectedShifts)
            {
                // Add shift title

                _lbl_shfit           = new Label();
                _lbl_shfit.AutoSize  = true;
                _lbl_shfit.Font      = new Font("Microsoft Sans Serif", 15);
                _lbl_shfit.ForeColor = Color.Black;

                var shf     = "";
                var upShift = string.Empty;

                if (shift.Remove(0, 2) == "Night")
                {
                    shf     = "Turno 1";
                    upShift = "NIGHT";
                }
                else if (shift.Remove(0, 2) == "Morning")
                {
                    shf     = "Turno 2";
                    upShift = "MORNING";
                }
                else if (shift.Remove(0, 2) == "Afternoon")
                {
                    shf     = "Turno 3";
                    upShift = "AFTERNOON";
                }

                _lbl_shfit.Text = shf;

                var lblW = _lbl_shfit.Width;
                var locX = (Width / 2 - lblW / 2);

                _lbl_shfit.Location = new Point(locX - 20, topObjLocation + 10);

                _panel_shift.Controls.Add(_lbl_shfit);

                topObjLocation += _lbl_shfit.Height;

                // Convert table data
                var conv_table_data = new DataTable();

                foreach (DataColumn dc in table_data.Columns)
                {
                    if (dc.ColumnName == "stop_time")
                    {
                        continue;
                    }

                    conv_table_data.Columns.Add(dc.ColumnName); //copies datacolumns
                }

                conv_table_data.Columns.Add("Generic Stops");
                conv_table_data.Columns.Add("TOTAL");

                foreach (DataRow row in table_data.Rows)
                {
                    var newRow = conv_table_data.NewRow();

                    if (row[1].ToString() != upShift)
                    {
                        continue;
                    }

                    var knitTime = Convert.ToInt32(row[8]);
                    var stopTime = Convert.ToInt32(row[16]);

                    var total = 0;

                    for (var i = 0; i <= 7; i++)
                    {
                        if (i == 0)
                        {
                            newRow[i] = Convert.ToDateTime(row[i]).ToShortDateString();
                        }
                        else
                        {
                            newRow[i] = row[i].ToString();
                        }
                    }

                    for (var i = 8; i <= 15; i++)
                    {
                        newRow[i] = ConvertSecondsToHHmm(Convert.ToInt32(row[i]));

                        total += Convert.ToInt32(row[i]);
                    }

                    var genericStop = 0;
                    var allStops    = 0;

                    for (var i = 9; i <= 15; i++)
                    {
                        allStops += Convert.ToInt32(row[i]);
                    }

                    genericStop = stopTime - allStops;

                    if (genericStop < 0)
                    {
                        genericStop = 0;
                    }
                    total += genericStop;

                    newRow[16] = ConvertSecondsToHHmm(genericStop);
                    newRow[17] = ConvertSecondsToHHmm(total);
                    conv_table_data.Rows.Add(newRow);
                }

                //Add chart

                _chart           = new System.Windows.Forms.DataVisualization.Charting.Chart();
                _chart.Size      = new Size(objW, 400);
                _chart.Location  = new Point(leftObjLocation, topObjLocation + 20);
                _chart.BackColor = Color.WhiteSmoke;
                topObjLocation  += _chart.Height;

                _chart.ChartAreas.Clear();
                _chart.Series.Clear();

                _chart.ChartAreas.Add("hold");

                _chart.ChartAreas[0].AxisX.MajorGrid.LineColor      = Color.Gainsboro;
                _chart.ChartAreas[0].AxisY.MajorGrid.LineColor      = Color.Gainsboro;
                _chart.ChartAreas[0].AxisX.MajorGrid.IntervalOffset = 20;
                _chart.ChartAreas[0].BackColor                  = Color.WhiteSmoke;
                _chart.ChartAreas[0].AxisX.LineColor            = Color.WhiteSmoke;
                _chart.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.Gray;
                _chart.ChartAreas[0].AxisY.LineColor            = Color.Silver;
                _chart.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.Gray;
                _chart.ChartAreas[0].AxisY.Maximum              = 60;
                //_chart.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Hours;
                //_chart.ChartAreas[0].AxisX.LabelAutoFitMinFontSize = 15;

                _chart.Series.Add("knitt");
                _chart.Series.Add("comb");
                _chart.Series.Add("manual");
                _chart.Series.Add("yarn");
                _chart.Series.Add("needle");
                _chart.Series.Add("shock");
                _chart.Series.Add("roller");
                _chart.Series.Add("other");
                _chart.Series.Add("generic");

                _chart.Legends.Clear();

                _chart.Series["knitt"].Color  = global.GetStopColors()[0];
                _chart.Series["comb"].Color   = global.GetStopColors()[1];
                _chart.Series["manual"].Color = global.GetStopColors()[2];
                _chart.Series["yarn"].Color   = global.GetStopColors()[3];
                _chart.Series["needle"].Color = global.GetStopColors()[4];
                _chart.Series["shock"].Color  = global.GetStopColors()[5];
                _chart.Series["roller"].Color = global.GetStopColors()[6];
                _chart.Series["other"].Color  = global.GetStopColors()[7];

                _chart.Series["generic"].Color = Color.Gold;

                foreach (DataRow row in chart_data.Rows)
                {
                    var hour = Convert.ToInt32(row[0]);

                    int knit   = Convert.ToInt32(row[1]) > 0 ? Convert.ToInt32(row[1]) : knit = 0;
                    int comb   = Convert.ToInt32(row[3]) > 0 ? Convert.ToInt32(row[3]) : comb = 0;
                    int manual = Convert.ToInt32(row[4]) > 0 ? Convert.ToInt32(row[4]) : manual = 0;
                    int yarn   = Convert.ToInt32(row[5]) > 0 ? Convert.ToInt32(row[5]) : yarn = 0;
                    int needle = Convert.ToInt32(row[6]) > 0 ? Convert.ToInt32(row[6]) : needle = 0;
                    int shock  = Convert.ToInt32(row[7]) > 0 ? Convert.ToInt32(row[7]) : shock = 0;
                    int roller = Convert.ToInt32(row[8]) > 0 ? Convert.ToInt32(row[8]) : roller = 0;
                    int other  = Convert.ToInt32(row[9]) > 0 ? Convert.ToInt32(row[9]) : other = 0;

                    if (knit > 60)
                    {
                        knit = 60;
                    }

                    if (shift == "cbNight" && hour == 23)
                    {
                        _chart.Series["knitt"].Points.AddXY(hour.ToString(), knit);
                        _chart.Series["comb"].Points.AddXY(hour.ToString(), comb);
                        _chart.Series["manual"].Points.AddXY(hour.ToString(), manual);
                        _chart.Series["yarn"].Points.AddXY(hour.ToString(), yarn);
                        _chart.Series["needle"].Points.AddXY(hour.ToString(), needle);
                        _chart.Series["shock"].Points.AddXY(hour.ToString(), shock);
                        _chart.Series["roller"].Points.AddXY(hour.ToString(), roller);
                        _chart.Series["other"].Points.AddXY(hour.ToString(), other);

                        var stopTime  = Convert.ToInt32(row[2]);
                        var otherTime = 0;

                        for (var i = 3; i <= chart_data.Columns.Count - 9; i++)
                        {
                            otherTime += Convert.ToInt32(row[i]);
                        }

                        var unknow = stopTime - otherTime;

                        if (unknow > 60)
                        {
                            unknow = 60;
                        }
                        else if (unknow < 0)
                        {
                            unknow = 0;
                        }

                        if ((knit + unknow) > 60)
                        {
                            unknow = 60 - knit;
                        }

                        _chart.Series["generic"].Points.AddXY(hour.ToString(), unknow);
                    }

                    if (shift == "cbNight" && hour >= 0 && hour <= 6 || shift == "cbMorning" && hour >= 7 && hour <= 14 ||
                        shift == "cbAfternoon" && hour >= 15 && hour <= 22)
                    {
                        _chart.Series["knitt"].Points.AddXY(hour.ToString(), knit);
                        _chart.Series["comb"].Points.AddXY(hour.ToString(), comb);
                        _chart.Series["manual"].Points.AddXY(hour.ToString(), manual);
                        _chart.Series["yarn"].Points.AddXY(hour.ToString(), yarn);
                        _chart.Series["needle"].Points.AddXY(hour.ToString(), needle);
                        _chart.Series["shock"].Points.AddXY(hour.ToString(), shock);
                        _chart.Series["roller"].Points.AddXY(hour.ToString(), roller);
                        _chart.Series["other"].Points.AddXY(hour.ToString(), other);

                        var stopTime  = Convert.ToInt32(row[2]);
                        var otherTime = 0;

                        for (var i = 3; i <= 9; i++)
                        {
                            otherTime += Convert.ToInt32(row[i]);
                        }

                        var unknow = stopTime - otherTime;

                        if (unknow > 60)
                        {
                            unknow = 60;
                        }
                        else if (unknow < 0)
                        {
                            unknow = 0;
                        }

                        if ((knit + unknow) > 60)
                        {
                            unknow = 60 - knit;
                        }

                        _chart.Series["generic"].Points.AddXY(hour.ToString(), unknow);
                    }
                }

                foreach (var s in _chart.Series)
                {
                    s.ChartType           = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn;
                    s.Font                = new Font("Tahoma", 8, FontStyle.Bold);
                    s.LabelForeColor      = Color.Black;
                    s.IsValueShownAsLabel = true;

                    foreach (var d in s.Points)
                    {
                        if (d.YValues[0] < 1)
                        {
                            d.IsValueShownAsLabel = false;
                        }
                    }
                }

                _panel_shift.Controls.Add(_chart);

                _dgv          = new DataGridView();
                _dgv.Size     = new Size(objW, 150);
                _dgv.Location = new Point(leftObjLocation, topObjLocation + 20);

                topObjLocation += _dgv.Height + 20;

                _dgv.EnableHeadersVisualStyles = false;
                _dgv.DoubleBufferedDataGridView(true);

                _dgv.AllowUserToAddRows          = false;
                _dgv.AllowUserToDeleteRows       = false;
                _dgv.AllowUserToResizeColumns    = false;
                _dgv.AllowUserToResizeRows       = false;
                _dgv.AllowUserToOrderColumns     = false;
                _dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
                _dgv.ReadOnly        = true;
                _dgv.BackgroundColor = Color.WhiteSmoke;
                _dgv.BorderStyle     = BorderStyle.None;
                _dgv.MultiSelect     = false;
                _dgv.SelectionMode   = DataGridViewSelectionMode.CellSelect;
                _dgv.Font            = new Font("Microsoft Sans Serif", 9);
                _dgv.ForeColor       = Color.FromArgb(60, 60, 60);
                _dgv.CellBorderStyle = DataGridViewCellBorderStyle.None;

                _dgv.DataSource = conv_table_data;

                _dgv.DataBindingComplete += delegate
                {
                    _dgv.Columns[1].Visible = false;

                    for (var c = 8; c <= _dgv.Columns.Count - 3; c++)
                    {
                        _dgv.Columns[c].HeaderCell.Style.BackColor = global.GetStopColors()[c - 8];

                        _dgv.Columns[c].HeaderCell.Style.ForeColor = Color.White;
                        _dgv.Columns[c].HeaderCell.Style.Font      = new Font("Microsoft Sans Serif", 8, FontStyle.Bold);

                        _dgv.Columns[c].HeaderText = global.StopReasonsIt[c - 8];
                    }

                    _dgv.Columns["Generic Stops"].HeaderCell.Style.BackColor = Color.Gold;
                    _dgv.Columns["Generic Stops"].HeaderCell.Style.ForeColor = Color.White;
                    _dgv.Columns["Generic Stops"].HeaderCell.Style.Font      = new Font("Microsoft Sans Serif", 8, FontStyle.Bold);

                    foreach (DataGridViewColumn c in _dgv.Columns)
                    {
                        _dgv.AutoResizeColumn(c.DisplayIndex);
                    }
                };

                _panel_shift.Controls.Add(_dgv);
            }

            LoadingInfo.CloseLoading();
        }