private void button_Save_Click(object sender, EventArgs e)
        {
            var custom1 = new Dashboard_CustomGroup();
            custom1.groupName = "Custom_1";
            custom1.lineId_1 = (comboBox_Custom1_1.SelectedItem ?? "").ToString();
            custom1.lineId_2 = (comboBox_Custom1_2.SelectedItem ?? "").ToString();
            custom1.lineId_3 = (comboBox_Custom1_3.SelectedItem ?? "").ToString();
            custom1.lineId_4 = (comboBox_Custom1_4.SelectedItem ?? "").ToString();
            custom1.lineId_5 = (comboBox_Custom1_5.SelectedItem ?? "").ToString();
            custom1.lineId_6 = (comboBox_Custom1_6.SelectedItem ?? "").ToString();
            custom1.lineId_7 = (comboBox_Custom1_7.SelectedItem ?? "").ToString();
            custom1.lineId_8 = (comboBox_Custom1_8.SelectedItem ?? "").ToString();

            var custom2 = new Dashboard_CustomGroup();
            custom2.groupName = "Custom_2";
            custom2.lineId_1 = (comboBox_Custom2_1.SelectedItem ?? "").ToString();
            custom2.lineId_2 = (comboBox_Custom2_2.SelectedItem ?? "").ToString();
            custom2.lineId_3 = (comboBox_Custom2_3.SelectedItem ?? "").ToString();
            custom2.lineId_4 = (comboBox_Custom2_4.SelectedItem ?? "").ToString();
            custom2.lineId_5 = (comboBox_Custom2_5.SelectedItem ?? "").ToString();
            custom2.lineId_6 = (comboBox_Custom2_6.SelectedItem ?? "").ToString();
            custom2.lineId_7 = (comboBox_Custom2_7.SelectedItem ?? "").ToString();
            custom2.lineId_8 = (comboBox_Custom2_8.SelectedItem ?? "").ToString();

            var custom3 = new Dashboard_CustomGroup();
            custom3.groupName = "Custom_3";
            custom3.lineId_1 = (comboBox_Custom3_1.SelectedItem ?? "").ToString();
            custom3.lineId_2 = (comboBox_Custom3_2.SelectedItem ?? "").ToString();
            custom3.lineId_3 = (comboBox_Custom3_3.SelectedItem ?? "").ToString();
            custom3.lineId_4 = (comboBox_Custom3_4.SelectedItem ?? "").ToString();
            custom3.lineId_5 = (comboBox_Custom3_5.SelectedItem ?? "").ToString();
            custom3.lineId_6 = (comboBox_Custom3_6.SelectedItem ?? "").ToString();
            custom3.lineId_7 = (comboBox_Custom3_7.SelectedItem ?? "").ToString();
            custom3.lineId_8 = (comboBox_Custom3_8.SelectedItem ?? "").ToString();

            try
            {
                // Custom 1
                var checkCustom1 = db.Dashboard_CustomGroup.AsNoTracking()
                                    .Where(x => x.groupName == "Custom_1")
                                    .Select(x => x.ID).FirstOrDefault();
                if(checkCustom1 == 0)
                {
                    db.Dashboard_CustomGroup.Add(custom1);
                }
                else
                {
                    var domain = db.Dashboard_CustomGroup.Find(checkCustom1);
                    domain.lineId_1 = custom1.lineId_1;
                    domain.lineId_2 = custom1.lineId_2;
                    domain.lineId_3 = custom1.lineId_3;
                    domain.lineId_4 = custom1.lineId_4;
                    domain.lineId_5 = custom1.lineId_5;
                    domain.lineId_6 = custom1.lineId_6;
                    domain.lineId_7 = custom1.lineId_7;
                    domain.lineId_8 = custom1.lineId_8;
                    var entry = db.Entry(domain);
                    entry.State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }

                // Custom 2
                var checkCustom2 = db.Dashboard_CustomGroup.AsNoTracking()
                                    .Where(x => x.groupName == "Custom_2")
                                    .Select(x => x.ID).FirstOrDefault();
                if (checkCustom2 == 0)
                {
                    db.Dashboard_CustomGroup.Add(custom2);
                    db.SaveChanges();
                }
                else
                {
                    var domain = db.Dashboard_CustomGroup.Find(checkCustom2);
                    domain.lineId_1 = custom2.lineId_1;
                    domain.lineId_2 = custom2.lineId_2;
                    domain.lineId_3 = custom2.lineId_3;
                    domain.lineId_4 = custom2.lineId_4;
                    domain.lineId_5 = custom2.lineId_5;
                    domain.lineId_6 = custom2.lineId_6;
                    domain.lineId_7 = custom2.lineId_7;
                    domain.lineId_8 = custom2.lineId_8;
                    var entry = db.Entry(domain);
                    entry.State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }

                // Custom 3
                var checkCustom3 = db.Dashboard_CustomGroup.AsNoTracking()
                                    .Where(x => x.groupName == "Custom_3")
                                    .Select(x => x.ID).FirstOrDefault();
                if (checkCustom3 == 0)
                {
                    db.Dashboard_CustomGroup.Add(custom3);
                    db.SaveChanges();
                }
                else
                {
                    var domain = db.Dashboard_CustomGroup.Find(checkCustom3);
                    domain.lineId_1 = custom3.lineId_1;
                    domain.lineId_2 = custom3.lineId_2;
                    domain.lineId_3 = custom3.lineId_3;
                    domain.lineId_4 = custom3.lineId_4;
                    domain.lineId_5 = custom3.lineId_5;
                    domain.lineId_6 = custom3.lineId_6;
                    domain.lineId_7 = custom3.lineId_7;
                    domain.lineId_8 = custom3.lineId_8;
                    var entry = db.Entry(domain);
                    entry.State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }

            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.InnerException.ToString());
            }

            this.Close();
        }
        // Submit button
        private void button2_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            bool chkConn = bwk.testConnection();

            LineName[0] = "";
            LineName[1] = "";
            LineName[2] = "";
            LineName[3] = "";
            LineName[4] = "";
            LineName[5] = "";
            LineName[6] = "";
            LineName[7] = "";
            Lbl_Line_1.Text = "";
            Lbl_Line_2.Text = "";
            Lbl_Line_3.Text = "";
            Lbl_Line_4.Text = "";
            Lbl_Line_5.Text = "";
            Lbl_Line_6.Text = "";
            Lbl_Line_7.Text = "";
            Lbl_Line_8.Text = "";

            if (chkConn == true)
            {
                // Added by Wimok 2014/08/04
                if (LineGroup == "Cube Benhil")
                {
                    LineName[0] = "Benh_1";
                    LineName[1] = "Benh_2";
                    LineName[2] = "Benh_3";
                    LineName[3] = "Benh_4";
                    LineName[4] = "Benh_5";
                    LineName[5] = "Benh_6";
                    LineName[6] = "";
                    LineName[7] = "";
                    Lbl_Line_1.Text = "Benhil 1";
                    Lbl_Line_2.Text = "Benhil 2";
                    Lbl_Line_3.Text = "Benhil 3";
                    Lbl_Line_4.Text = "Benhil 4";
                    Lbl_Line_5.Text = "Benhil 5";
                    Lbl_Line_6.Text = "Benhil 6";
                    Lbl_Line_7.Text = "";
                    Lbl_Line_8.Text = "";
                }
                else if (LineGroup == "Cube Corazza")
                {
                    LineName[0] = "Corz_1";
                    LineName[1] = "Corz_2";
                    LineName[2] = "Corz_3";
                    LineName[3] = "Corz_4";
                    LineName[4] = "";
                    LineName[5] = "";
                    LineName[6] = "";
                    LineName[7] = "";
                    Lbl_Line_1.Text = "Corazza 1";
                    Lbl_Line_2.Text = "Corazza 2";
                    Lbl_Line_3.Text = "Corazza 3";
                    Lbl_Line_4.Text = "Corazza 4";
                    Lbl_Line_5.Text = "";
                    Lbl_Line_6.Text = "";
                    Lbl_Line_7.Text = "";
                    Lbl_Line_8.Text = "";
                }
                else if (LineGroup == "Jok Cup")
                {
                    LineName[0] = "Cupf_2";
                    LineName[1] = "Cupf_3";
                    LineName[2] = "Cupf_4";
                    LineName[3] = "";
                    LineName[4] = "";
                    LineName[5] = "";
                    LineName[6] = "";
                    LineName[7] = "";
                    Lbl_Line_1.Text = "Cup Filler 2";
                    Lbl_Line_2.Text = "Cup Filler 3";
                    Lbl_Line_3.Text = "Cup Filler 4";
                    Lbl_Line_4.Text = "";
                    Lbl_Line_5.Text = "";
                    Lbl_Line_6.Text = "";
                    Lbl_Line_7.Text = "";
                    Lbl_Line_8.Text = "";
                }
                else if (LineGroup == "Jok Sachet")
                {
                    LineName[0] = "Bart_1";
                    LineName[1] = "Mesp_1";
                    LineName[2] = "Mesp_3";
                    LineName[3] = "Mesp_4";
                    LineName[4] = "";
                    LineName[5] = "";
                    LineName[6] = "";
                    LineName[7] = "";
                    Lbl_Line_1.Text = "Bartelt 1";
                    Lbl_Line_2.Text = "Mespack 1";
                    Lbl_Line_3.Text = "Mespack 3";
                    Lbl_Line_4.Text = "Mespack 4";
                    Lbl_Line_5.Text = "";
                    Lbl_Line_6.Text = "";
                    Lbl_Line_7.Text = "";
                    Lbl_Line_8.Text = "";
                }
                else if (LineGroup == "Powder")
                {
                    LineName[0] = "Bart_2";
                    LineName[1] = "Bart_3";
                    LineName[2] = "Upkn_1";
                    LineName[3] = "Vffs_1";
                    LineName[4] = "ILpk_1";
                    LineName[5] = "Dema_2";
                    LineName[6] = "Mpck_2";
                    LineName[7] = "Mpck_4";
                    Lbl_Line_1.Text = "Bartelt 2";
                    Lbl_Line_2.Text = "Bartelt 3";
                    Lbl_Line_3.Text = "UP KN 1";
                    Lbl_Line_4.Text = "VFFS 1";
                    Lbl_Line_5.Text = "Ilapak 1";
                    Lbl_Line_6.Text = "Demar 2";
                    Lbl_Line_7.Text = "MP 2";
                    Lbl_Line_8.Text = "MP 4";
                }
                else if (LineGroup == "Dry Mix")
                {
                    LineName[0] = "G2h_1";
                    LineName[1] = "Updm_1";
                    LineName[2] = "Mpdm_1";
                    LineName[3] = "";
                    LineName[4] = "";
                    LineName[5] = "";
                    LineName[6] = "";
                    LineName[7] = "";
                    Lbl_Line_1.Text = "G2H";
                    Lbl_Line_2.Text = "UP DM 1";
                    Lbl_Line_3.Text = "MP DM 1";
                    Lbl_Line_4.Text = "";
                    Lbl_Line_5.Text = "";
                    Lbl_Line_6.Text = "";
                    Lbl_Line_7.Text = "";
                    Lbl_Line_8.Text = "";
                }
                else if (LineGroup == "Custom 1")
                {
                    var qry = from x in db.Dashboard_CustomGroup where x.groupName == "Custom_1" select x;
                    Dashboard_CustomGroup custom = new Dashboard_CustomGroup();
                    try
                    {
                        custom = qry.FirstOrDefault();
                        if (custom != null)
                        {
                            LineName[0] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_1 select x.line_id).FirstOrDefault();
                            LineName[1] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_2 select x.line_id).FirstOrDefault();
                            LineName[2] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_3 select x.line_id).FirstOrDefault();
                            LineName[3] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_4 select x.line_id).FirstOrDefault();
                            LineName[4] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_5 select x.line_id).FirstOrDefault();
                            LineName[5] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_6 select x.line_id).FirstOrDefault();
                            LineName[6] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_7 select x.line_id).FirstOrDefault();
                            LineName[7] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_8 select x.line_id).FirstOrDefault();
                            Lbl_Line_1.Text = custom.lineId_1;
                            Lbl_Line_2.Text = custom.lineId_2;
                            Lbl_Line_3.Text = custom.lineId_3;
                            Lbl_Line_4.Text = custom.lineId_4;
                            Lbl_Line_5.Text = custom.lineId_5;
                            Lbl_Line_6.Text = custom.lineId_6;
                            Lbl_Line_7.Text = custom.lineId_7;
                            Lbl_Line_8.Text = custom.lineId_8;
                        }
                    }
                    catch(Exception ex) { }
                }
                else if (LineGroup == "Custom 2")
                {
                    var qry = from x in db.Dashboard_CustomGroup where x.groupName == "Custom_2" select x;
                    Dashboard_CustomGroup custom = new Dashboard_CustomGroup();
                    try
                    {
                        custom = qry.FirstOrDefault();
                        if (custom != null)
                        {
                            LineName[0] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_1 select x.line_id).FirstOrDefault();
                            LineName[1] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_2 select x.line_id).FirstOrDefault();
                            LineName[2] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_3 select x.line_id).FirstOrDefault();
                            LineName[3] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_4 select x.line_id).FirstOrDefault();
                            LineName[4] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_5 select x.line_id).FirstOrDefault();
                            LineName[5] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_6 select x.line_id).FirstOrDefault();
                            LineName[6] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_7 select x.line_id).FirstOrDefault();
                            LineName[7] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_8 select x.line_id).FirstOrDefault();
                            Lbl_Line_1.Text = custom.lineId_1;
                            Lbl_Line_2.Text = custom.lineId_2;
                            Lbl_Line_3.Text = custom.lineId_3;
                            Lbl_Line_4.Text = custom.lineId_4;
                            Lbl_Line_5.Text = custom.lineId_5;
                            Lbl_Line_6.Text = custom.lineId_6;
                            Lbl_Line_7.Text = custom.lineId_7;
                            Lbl_Line_8.Text = custom.lineId_8;
                        }
                    }
                    catch (Exception ex) { }
                }
                else if (LineGroup == "Custom 3")
                {
                    var qry = from x in db.Dashboard_CustomGroup where x.groupName == "Custom_3" select x;
                    Dashboard_CustomGroup custom = new Dashboard_CustomGroup();
                    try
                    {
                        custom = qry.FirstOrDefault();
                        if (custom != null)
                        {
                            LineName[0] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_1 select x.line_id).FirstOrDefault();
                            LineName[1] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_2 select x.line_id).FirstOrDefault();
                            LineName[2] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_3 select x.line_id).FirstOrDefault();
                            LineName[3] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_4 select x.line_id).FirstOrDefault();
                            LineName[4] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_5 select x.line_id).FirstOrDefault();
                            LineName[5] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_6 select x.line_id).FirstOrDefault();
                            LineName[6] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_7 select x.line_id).FirstOrDefault();
                            LineName[7] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_8 select x.line_id).FirstOrDefault();
                            Lbl_Line_1.Text = custom.lineId_1;
                            Lbl_Line_2.Text = custom.lineId_2;
                            Lbl_Line_3.Text = custom.lineId_3;
                            Lbl_Line_4.Text = custom.lineId_4;
                            Lbl_Line_5.Text = custom.lineId_5;
                            Lbl_Line_6.Text = custom.lineId_6;
                            Lbl_Line_7.Text = custom.lineId_7;
                            Lbl_Line_8.Text = custom.lineId_8;
                        }
                    }
                    catch (Exception ex) { }
                }

                Check_SHE_Line1 = "1";
                Check_SHE_Line2 = "1";
                Check_SHE_Line3 = "1";
                Check_SHE_Line4 = "1";
                Check_SHE_Line5 = "1";
                Check_SHE_Line6 = "1";
                Check_SHE_Line7 = "1";
                Check_SHE_Line8 = "1";
                Check_Quality_Line1 = "1";
                Check_Quality_Line2 = "1";
                Check_Quality_Line3 = "1";
                Check_Quality_Line4 = "1";
                Check_Quality_Line5 = "1";
                Check_Quality_Line6 = "1";
                Check_Quality_Line7 = "1";
                Check_Quality_Line8 = "1";

                tblPanel_r1_c1.Visible = true;
                tblPanel_r1_c2.Visible = true;
                tblPanel_r1_c3.Visible = true;
                tblPanel_r1_c4.Visible = true;
                tblPanel_r1_c5.Visible = true;
                tblPanel_r1_c6.Visible = true;
                tblPanel_r1_c7.Visible = true;
                tblPanel_r1_c8.Visible = true;
                tblPanel_r2_c1.Visible = true;
                tblPanel_r2_c2.Visible = true;
                tblPanel_r2_c3.Visible = true;
                tblPanel_r2_c4.Visible = true;
                tblPanel_r2_c5.Visible = true;
                tblPanel_r2_c6.Visible = true;
                tblPanel_r2_c7.Visible = true;
                tblPanel_r2_c8.Visible = true;
                tblPanel_rTotal_c1.Visible = true;
                tblPanel_rTotal_c2.Visible = true;
                tblPanel_rTotal_c3.Visible = true;
                tblPanel_rTotal_c4.Visible = true;
                tblPanel_rTotal_c5.Visible = true;
                tblPanel_rTotal_c6.Visible = true;
                tblPanel_rTotal_c7.Visible = true;
                tblPanel_rTotal_c8.Visible = true;

                //------------------------------------------------------------------------------------

                _getDataOther();

                GetData(1, LineName[0], date_data.Value, grid_r1_c1);
                GetData(1, LineName[1], date_data.Value, grid_r1_c2);
                GetData(1, LineName[2], date_data.Value, grid_r1_c3);
                GetData(1, LineName[3], date_data.Value, grid_r1_c4);
                GetData(1, LineName[4], date_data.Value, grid_r1_c5);
                GetData(1, LineName[5], date_data.Value, grid_r1_c6);
                GetData(1, LineName[6], date_data.Value, grid_r1_c7);
                GetData(1, LineName[7], date_data.Value, grid_r1_c8);

                GetData(2, LineName[0], date_data.Value, grid_r2_c1);
                GetData(2, LineName[1], date_data.Value, grid_r2_c2);
                GetData(2, LineName[2], date_data.Value, grid_r2_c3);
                GetData(2, LineName[3], date_data.Value, grid_r2_c4);
                GetData(2, LineName[4], date_data.Value, grid_r2_c5);
                GetData(2, LineName[5], date_data.Value, grid_r2_c6);
                GetData(2, LineName[6], date_data.Value, grid_r2_c7);
                GetData(2, LineName[7], date_data.Value, grid_r2_c8);

                GetSummaryData(1, LineName[0], date_data.Value, lblActual_r1_c1, lblDiff_r1_c1, yellow_r1_c1, tblPanel_r1_c1);
                GetSummaryData(1, LineName[1], date_data.Value, lblActual_r1_c2, lblDiff_r1_c2, yellow_r1_c2, tblPanel_r1_c2);
                GetSummaryData(1, LineName[2], date_data.Value, lblActual_r1_c3, lblDiff_r1_c3, yellow_r1_c3, tblPanel_r1_c3);
                GetSummaryData(1, LineName[3], date_data.Value, lblActual_r1_c4, lblDiff_r1_c4, yellow_r1_c4, tblPanel_r1_c4);
                GetSummaryData(1, LineName[4], date_data.Value, lblActual_r1_c5, lblDiff_r1_c5, yellow_r1_c5, tblPanel_r1_c5);
                GetSummaryData(1, LineName[5], date_data.Value, lblActual_r1_c6, lblDiff_r1_c6, yellow_r1_c6, tblPanel_r1_c6);
                GetSummaryData(1, LineName[6], date_data.Value, lblActual_r1_c7, lblDiff_r1_c7, yellow_r1_c7, tblPanel_r1_c7);
                GetSummaryData(1, LineName[7], date_data.Value, lblActual_r1_c8, lblDiff_r1_c8, yellow_r1_c8, tblPanel_r1_c8);

                GetSummaryData(2, LineName[0], date_data.Value, lblActual_r2_c1, lblDiff_r2_c1, yellow_r2_c1, tblPanel_r2_c1);
                GetSummaryData(2, LineName[1], date_data.Value, lblActual_r2_c2, lblDiff_r2_c2, yellow_r2_c2, tblPanel_r2_c2);
                GetSummaryData(2, LineName[2], date_data.Value, lblActual_r2_c3, lblDiff_r2_c3, yellow_r2_c3, tblPanel_r2_c3);
                GetSummaryData(2, LineName[3], date_data.Value, lblActual_r2_c4, lblDiff_r2_c4, yellow_r2_c4, tblPanel_r2_c4);
                GetSummaryData(2, LineName[4], date_data.Value, lblActual_r2_c5, lblDiff_r2_c5, yellow_r2_c5, tblPanel_r2_c5);
                GetSummaryData(2, LineName[5], date_data.Value, lblActual_r2_c6, lblDiff_r2_c6, yellow_r2_c6, tblPanel_r2_c6);
                GetSummaryData(2, LineName[6], date_data.Value, lblActual_r2_c7, lblDiff_r2_c7, yellow_r2_c7, tblPanel_r2_c7);
                GetSummaryData(2, LineName[7], date_data.Value, lblActual_r2_c8, lblDiff_r2_c8, yellow_r2_c8, tblPanel_r2_c8);

                GetTotalData(LineName[0], date_data.Value, grid_rTotal_c1);
                GetTotalData(LineName[1], date_data.Value, grid_rTotal_c2);
                GetTotalData(LineName[2], date_data.Value, grid_rTotal_c3);
                GetTotalData(LineName[3], date_data.Value, grid_rTotal_c4);
                GetTotalData(LineName[4], date_data.Value, grid_rTotal_c5);
                GetTotalData(LineName[5], date_data.Value, grid_rTotal_c6);
                GetTotalData(LineName[6], date_data.Value, grid_rTotal_c7);
                GetTotalData(LineName[7], date_data.Value, grid_rTotal_c8);

                GetSummaryTotal(LineName[0], date_data.Value, lblActual_rTotal_c1, lblDiff_rTotal_c1, yellow_rTotal_c1, tblPanel_rTotal_c1);
                GetSummaryTotal(LineName[1], date_data.Value, lblActual_rTotal_c2, lblDiff_rTotal_c2, yellow_rTotal_c2, tblPanel_rTotal_c2);
                GetSummaryTotal(LineName[2], date_data.Value, lblActual_rTotal_c3, lblDiff_rTotal_c3, yellow_rTotal_c3, tblPanel_rTotal_c3);
                GetSummaryTotal(LineName[3], date_data.Value, lblActual_rTotal_c4, lblDiff_rTotal_c4, yellow_rTotal_c4, tblPanel_rTotal_c4);
                GetSummaryTotal(LineName[4], date_data.Value, lblActual_rTotal_c5, lblDiff_rTotal_c5, yellow_rTotal_c5, tblPanel_rTotal_c5);
                GetSummaryTotal(LineName[5], date_data.Value, lblActual_rTotal_c6, lblDiff_rTotal_c6, yellow_rTotal_c6, tblPanel_rTotal_c6);
                GetSummaryTotal(LineName[6], date_data.Value, lblActual_rTotal_c7, lblDiff_rTotal_c7, yellow_rTotal_c7, tblPanel_rTotal_c7);
                GetSummaryTotal(LineName[7], date_data.Value, lblActual_rTotal_c8, lblDiff_rTotal_c8, yellow_rTotal_c8, tblPanel_rTotal_c8);

                _getDataChart();

                //GetDefectFactor();

                //GetDefect(Qua_Line1_G, Qua_Line1_R, LineName[0], ref Defect_Line1, Defect_Factor);
                //GetDefect(Qua_Line2_G, Qua_Line2_R, LineName[1], ref Defect_Line2, Defect_Factor);
                //GetDefect(Qua_Line3_G, Qua_Line3_R, LineName[2], ref Defect_Line3, Defect_Factor);
                //GetDefect(Qua_Line4_G, Qua_Line4_R, LineName[3], ref Defect_Line4, Defect_Factor);
                //GetDefect(Qua_Line5_G, Qua_Line5_R, LineName[4], ref Defect_Line5, Defect_Factor);
                //GetDefect(Qua_Line6_G, Qua_Line6_R, LineName[5], ref Defect_Line6, Defect_Factor);
                //GetDefect(Qua_Line7_G, Qua_Line7_R, LineName[6], ref Defect_Line7, Defect_Factor);
                //GetDefect(Qua_Line8_G, Qua_Line8_R, LineName[7], ref Defect_Line8, Defect_Factor);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            string DateSelect = dbc.CommonDt(date_data.Value);
            //string[] LineName = new string[8];

            initParam();

            if (LineGroup == 1)
            {
                LineName[0] = "Benh_1";
                LineName[1] = "Benh_2";
                LineName[2] = "Benh_3";
                LineName[3] = "Benh_4";
                LineName[4] = "Benh_5";
                LineName[5] = "Benh_6";
                LineName[6] = "";
                LineName[7] = "";
                Lbl_Line_1.Text = "Benhil 1";
                Lbl_Line_2.Text = "Benhil 2";
                Lbl_Line_3.Text = "Benhil 3";
                Lbl_Line_4.Text = "Benhil 4";
                Lbl_Line_5.Text = "Benhil 5";
                Lbl_Line_6.Text = "Benhil 6";
                Lbl_Line_7.Text = "";
                Lbl_Line_8.Text = "";
            }
            else if (LineGroup == 2)
            {
                LineName[0] = "Corz_1";
                LineName[1] = "Corz_2";
                LineName[2] = "Corz_3";
                LineName[3] = "Corz_4";
                LineName[4] = "";
                LineName[5] = "";
                LineName[6] = "";
                LineName[7] = "";
                Lbl_Line_1.Text = "Corazza 1";
                Lbl_Line_2.Text = "Corazza 2";
                Lbl_Line_3.Text = "Corazza 3";
                Lbl_Line_4.Text = "Corazza 4";
                Lbl_Line_5.Text = "";
                Lbl_Line_6.Text = "";
                Lbl_Line_7.Text = "";
                Lbl_Line_8.Text = "";
            }
            else if (LineGroup == 3)
            {
                LineName[0] = "Cupf_2";
                LineName[1] = "Cupf_3";
                LineName[2] = "Cupf_4";
                LineName[3] = "";
                LineName[4] = "";
                LineName[5] = "";
                LineName[6] = "";
                LineName[7] = "";
                Lbl_Line_1.Text = "Cup Filler 2";
                Lbl_Line_2.Text = "Cup Filler 3";
                Lbl_Line_3.Text = "Cup Filler 4";
                Lbl_Line_4.Text = "";
                Lbl_Line_5.Text = "";
                Lbl_Line_6.Text = "";
                Lbl_Line_7.Text = "";
                Lbl_Line_8.Text = "";
            }
            else if (LineGroup == 4)
            {
                LineName[0] = "Bart_1";
                LineName[1] = "Mesp_1";
                LineName[2] = "Mesp_3";
                LineName[3] = "Mesp_4";
                LineName[4] = "";
                LineName[5] = "";
                LineName[6] = "";
                LineName[7] = "";
                Lbl_Line_1.Text = "Bartelt 1";
                Lbl_Line_2.Text = "Mespack 1";
                Lbl_Line_3.Text = "Mespack 3";
                Lbl_Line_4.Text = "Mespack 4";
                Lbl_Line_5.Text = "";
                Lbl_Line_6.Text = "";
                Lbl_Line_7.Text = "";
                Lbl_Line_8.Text = "";
            }
            else if (LineGroup == 5)
            {
                LineName[0] = "Bart_2";
                LineName[1] = "Bart_3";
                LineName[2] = "Upkn_1";
                LineName[3] = "Vffs_1";
                LineName[4] = "ILpk_1";
                LineName[5] = "Dema_2";
                LineName[6] = "Mpck_2";
                LineName[7] = "Mpck_4";
                Lbl_Line_1.Text = "Bartelt 2";
                Lbl_Line_2.Text = "Bartelt 3";
                Lbl_Line_3.Text = "UP KN 1";
                Lbl_Line_4.Text = "VFFS 1";
                Lbl_Line_5.Text = "Ilapak 1";
                Lbl_Line_6.Text = "Demar 2";
                Lbl_Line_7.Text = "MP 2";
                Lbl_Line_8.Text = "MP 4";
            }
            else if (LineGroup == 6)
            {
                LineName[0] = "G2h_1";
                LineName[1] = "Updm_1";
                LineName[2] = "Mpdm_1";
                LineName[3] = "";
                LineName[4] = "";
                LineName[5] = "";
                LineName[6] = "";
                LineName[7] = "";
                Lbl_Line_1.Text = "G2H";
                Lbl_Line_2.Text = "UP DM 1";
                Lbl_Line_3.Text = "MP DM 1";
                Lbl_Line_4.Text = "";
                Lbl_Line_5.Text = "";
                Lbl_Line_6.Text = "";
                Lbl_Line_7.Text = "";
                Lbl_Line_8.Text = "";
            }
            else if (LineGroup == 7)
            {
                var qry = from x in db.Dashboard_CustomGroup where x.groupName == "Custom_1" select x;
                Dashboard_CustomGroup custom = new Dashboard_CustomGroup();
                try
                {
                    custom = qry.FirstOrDefault();
                    if (custom != null)
                    {
                        LineName[0] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_1 select x.line_id).FirstOrDefault();
                        LineName[1] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_2 select x.line_id).FirstOrDefault();
                        LineName[2] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_3 select x.line_id).FirstOrDefault();
                        LineName[3] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_4 select x.line_id).FirstOrDefault();
                        LineName[4] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_5 select x.line_id).FirstOrDefault();
                        LineName[5] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_6 select x.line_id).FirstOrDefault();
                        LineName[6] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_7 select x.line_id).FirstOrDefault();
                        LineName[7] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_8 select x.line_id).FirstOrDefault();
                        Lbl_Line_1.Text = custom.lineId_1;
                        Lbl_Line_2.Text = custom.lineId_2;
                        Lbl_Line_3.Text = custom.lineId_3;
                        Lbl_Line_4.Text = custom.lineId_4;
                        Lbl_Line_5.Text = custom.lineId_5;
                        Lbl_Line_6.Text = custom.lineId_6;
                        Lbl_Line_7.Text = custom.lineId_7;
                        Lbl_Line_8.Text = custom.lineId_8;
                    }
                }
                catch (Exception ex) { }
            }
            else if (LineGroup == 8)
            {
                var qry = from x in db.Dashboard_CustomGroup where x.groupName == "Custom_2" select x;
                Dashboard_CustomGroup custom = new Dashboard_CustomGroup();
                try
                {
                    custom = qry.FirstOrDefault();
                    if (custom != null)
                    {
                        LineName[0] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_1 select x.line_id).FirstOrDefault();
                        LineName[1] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_2 select x.line_id).FirstOrDefault();
                        LineName[2] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_3 select x.line_id).FirstOrDefault();
                        LineName[3] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_4 select x.line_id).FirstOrDefault();
                        LineName[4] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_5 select x.line_id).FirstOrDefault();
                        LineName[5] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_6 select x.line_id).FirstOrDefault();
                        LineName[6] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_7 select x.line_id).FirstOrDefault();
                        LineName[7] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_8 select x.line_id).FirstOrDefault();
                        Lbl_Line_1.Text = custom.lineId_1;
                        Lbl_Line_2.Text = custom.lineId_2;
                        Lbl_Line_3.Text = custom.lineId_3;
                        Lbl_Line_4.Text = custom.lineId_4;
                        Lbl_Line_5.Text = custom.lineId_5;
                        Lbl_Line_6.Text = custom.lineId_6;
                        Lbl_Line_7.Text = custom.lineId_7;
                        Lbl_Line_8.Text = custom.lineId_8;
                    }
                }
                catch (Exception ex) { }
            }
            else if (LineGroup == 9)
            {
                var qry = from x in db.Dashboard_CustomGroup where x.groupName == "Custom_3" select x;
                Dashboard_CustomGroup custom = new Dashboard_CustomGroup();
                try
                {
                    custom = qry.FirstOrDefault();
                    if (custom != null)
                    {
                        LineName[0] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_1 select x.line_id).FirstOrDefault();
                        LineName[1] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_2 select x.line_id).FirstOrDefault();
                        LineName[2] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_3 select x.line_id).FirstOrDefault();
                        LineName[3] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_4 select x.line_id).FirstOrDefault();
                        LineName[4] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_5 select x.line_id).FirstOrDefault();
                        LineName[5] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_6 select x.line_id).FirstOrDefault();
                        LineName[6] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_7 select x.line_id).FirstOrDefault();
                        LineName[7] = (from x in db.LINE_PRODUCTION where x.line_name == custom.lineId_8 select x.line_id).FirstOrDefault();
                        Lbl_Line_1.Text = custom.lineId_1;
                        Lbl_Line_2.Text = custom.lineId_2;
                        Lbl_Line_3.Text = custom.lineId_3;
                        Lbl_Line_4.Text = custom.lineId_4;
                        Lbl_Line_5.Text = custom.lineId_5;
                        Lbl_Line_6.Text = custom.lineId_6;
                        Lbl_Line_7.Text = custom.lineId_7;
                        Lbl_Line_8.Text = custom.lineId_8;
                    }
                }
                catch (Exception ex) { }
            }

            BWK bwk = new BWK();
            bool chkConn = bwk.testConnection();
            if(chkConn == true)
            {
                if(checkBox_RangeFilter.Checked)
                {

                    switch (comboBox_DateRange.Text)
                    {
                        case "Date":
                            _getDataRange_Date(LineName[0], dateRangePicker_1.Value.Date, dateRangePicker_2.Value.Date, ref grid_datalist_a);
                            _getDataRange_Date(LineName[1], dateRangePicker_1.Value.Date, dateRangePicker_2.Value.Date, ref grid_datalist_b1);
                            _getDataRange_Date(LineName[2], dateRangePicker_1.Value.Date, dateRangePicker_2.Value.Date, ref grid_datalist_b9);
                            _getDataRange_Date(LineName[3], dateRangePicker_1.Value.Date, dateRangePicker_2.Value.Date, ref grid_datalist_c);
                            _getDataRange_Date(LineName[4], dateRangePicker_1.Value.Date, dateRangePicker_2.Value.Date, ref grid_datalist_d);
                            _getDataRange_Date(LineName[5], dateRangePicker_1.Value.Date, dateRangePicker_2.Value.Date, ref grid_datalist_e);
                            _getDataRange_Date(LineName[6], dateRangePicker_1.Value.Date, dateRangePicker_2.Value.Date, ref grid_datalist_g);
                            _getDataRange_Date(LineName[7], dateRangePicker_1.Value.Date, dateRangePicker_2.Value.Date, ref grid_datalist_m);

                            _getPlanActualRange_Date();
                            _getPlanActualRange_Date_All();

                            break;
                        case "Week":
                            _getDataRange_Week(LineName[0], Convert.ToInt32(comboBox_Week_1.Text), Convert.ToInt32(comboBox_Year_1.Text), Convert.ToInt32(comboBox_Week_2.Text), Convert.ToInt32(comboBox_Year_2.Text), ref grid_datalist_a);
                            _getDataRange_Week(LineName[1], Convert.ToInt32(comboBox_Week_1.Text), Convert.ToInt32(comboBox_Year_1.Text), Convert.ToInt32(comboBox_Week_2.Text), Convert.ToInt32(comboBox_Year_2.Text), ref grid_datalist_b1);
                            _getDataRange_Week(LineName[2], Convert.ToInt32(comboBox_Week_1.Text), Convert.ToInt32(comboBox_Year_1.Text), Convert.ToInt32(comboBox_Week_2.Text), Convert.ToInt32(comboBox_Year_2.Text), ref grid_datalist_b9);
                            _getDataRange_Week(LineName[3], Convert.ToInt32(comboBox_Week_1.Text), Convert.ToInt32(comboBox_Year_1.Text), Convert.ToInt32(comboBox_Week_2.Text), Convert.ToInt32(comboBox_Year_2.Text), ref grid_datalist_c);
                            _getDataRange_Week(LineName[4], Convert.ToInt32(comboBox_Week_1.Text), Convert.ToInt32(comboBox_Year_1.Text), Convert.ToInt32(comboBox_Week_2.Text), Convert.ToInt32(comboBox_Year_2.Text), ref grid_datalist_d);
                            _getDataRange_Week(LineName[5], Convert.ToInt32(comboBox_Week_1.Text), Convert.ToInt32(comboBox_Year_1.Text), Convert.ToInt32(comboBox_Week_2.Text), Convert.ToInt32(comboBox_Year_2.Text), ref grid_datalist_e);
                            _getDataRange_Week(LineName[6], Convert.ToInt32(comboBox_Week_1.Text), Convert.ToInt32(comboBox_Year_1.Text), Convert.ToInt32(comboBox_Week_2.Text), Convert.ToInt32(comboBox_Year_2.Text), ref grid_datalist_g);
                            _getDataRange_Week(LineName[7], Convert.ToInt32(comboBox_Week_1.Text), Convert.ToInt32(comboBox_Year_1.Text), Convert.ToInt32(comboBox_Week_2.Text), Convert.ToInt32(comboBox_Year_2.Text), ref grid_datalist_m);

                            _getPlanActualRange_Week();
                            _getPlanActualRange_Week_All();

                            break;
                        case "Year":
                            _getDataRange_Year(LineName[0], Convert.ToInt32(comboBox_Year_1.Text), Convert.ToInt32(comboBox_Year_2.Text), ref grid_datalist_a);
                            _getDataRange_Year(LineName[1], Convert.ToInt32(comboBox_Year_1.Text), Convert.ToInt32(comboBox_Year_2.Text), ref grid_datalist_b1);
                            _getDataRange_Year(LineName[2], Convert.ToInt32(comboBox_Year_1.Text), Convert.ToInt32(comboBox_Year_2.Text), ref grid_datalist_b9);
                            _getDataRange_Year(LineName[3], Convert.ToInt32(comboBox_Year_1.Text), Convert.ToInt32(comboBox_Year_2.Text), ref grid_datalist_c);
                            _getDataRange_Year(LineName[4], Convert.ToInt32(comboBox_Year_1.Text), Convert.ToInt32(comboBox_Year_2.Text), ref grid_datalist_d);
                            _getDataRange_Year(LineName[5], Convert.ToInt32(comboBox_Year_1.Text), Convert.ToInt32(comboBox_Year_2.Text), ref grid_datalist_e);
                            _getDataRange_Year(LineName[6], Convert.ToInt32(comboBox_Year_1.Text), Convert.ToInt32(comboBox_Year_2.Text), ref grid_datalist_g);
                            _getDataRange_Year(LineName[7], Convert.ToInt32(comboBox_Year_1.Text), Convert.ToInt32(comboBox_Year_2.Text), ref grid_datalist_m);

                            _getPlanActualRange_Year();
                            _getPlanActualRange_Year_All();

                            break;
                    }

                    lab_day.Text = "Range";
                    lab_week.Text = "";
                    lab_day_all.Text = "Range (All group)";
                    lab_week_all.Text = "";
                    lab_week_group_plan.Text = "";
                    lab_week_group_actual.Text = "";
                    lab_week_p.Text = "";
                    lab_week_a.Text = "";
                    tblLayout_status_week.Visible = false;
                    tblLayout_status_week_all.Visible = false;
                }
                else
                {
                    _getDataList(LineName[0], date_data.Value, ref grid_datalist_a);
                    _getDataList(LineName[1], date_data.Value, ref grid_datalist_b1);
                    _getDataList(LineName[2], date_data.Value, ref grid_datalist_b9);
                    _getDataList(LineName[3], date_data.Value, ref grid_datalist_c);
                    _getDataList(LineName[4], date_data.Value, ref grid_datalist_d);
                    _getDataList(LineName[5], date_data.Value, ref grid_datalist_e);
                    _getDataList(LineName[6], date_data.Value, ref grid_datalist_g);
                    _getDataList(LineName[7], date_data.Value, ref grid_datalist_m);

                    lab_day.Text = "Day";
                    lab_week.Text = "Week";
                    lab_day_all.Text = "Day (All group)";
                    lab_week_all.Text = "Week (All group)";

                    _getPlanActualDay();
                    _getPlanActualDayPerGroup();
                    _getPlanActualWeek();
                    _getPlanActualWeekPerGroup();
                    tblLayout_status_week.Visible = true;
                    tblLayout_status_week_all.Visible = true;
                }

                _getDataOther();
            }
        }