private void btnImport_Click(object sender, EventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm2));
            SITES_BUS                 busSite        = new SITES_BUS();
            FACILITY_BUS              busFacility    = new FACILITY_BUS();
            MANUFACTURER_BUS          busManufacture = new MANUFACTURER_BUS();
            DESIGN_CODE_BUS           busDesignCode  = new DESIGN_CODE_BUS();
            FACILITY_RISK_TARGET_BUS  busRiskTarget  = new FACILITY_RISK_TARGET_BUS();
            EQUIPMENT_MASTER_BUS      busEquipMaster = new EQUIPMENT_MASTER_BUS();
            COMPONENT_MASTER_BUS      busCompMaster  = new COMPONENT_MASTER_BUS();
            RW_ASSESSMENT_BUS         busAss         = new RW_ASSESSMENT_BUS();
            RW_EQUIPMENT_BUS          busEquip       = new RW_EQUIPMENT_BUS();
            RW_COMPONENT_BUS          busCom         = new RW_COMPONENT_BUS();
            RW_EXTCOR_TEMPERATURE_BUS busExtcor      = new RW_EXTCOR_TEMPERATURE_BUS();
            RW_STREAM_BUS             busStream      = new RW_STREAM_BUS();
            RW_MATERIAL_BUS           busMaterial    = new RW_MATERIAL_BUS();
            RW_COATING_BUS            busCoating     = new RW_COATING_BUS();
            RW_INPUT_CA_TANK_BUS      busInputCATank = new RW_INPUT_CA_TANK_BUS();
            Bus_PLANT_PROCESS_Excel   busExcel       = new Bus_PLANT_PROCESS_Excel();

            busExcel.path = txtPathFileExcel.Text;
            //Sites
            List <SITES> lstSite = busExcel.getAllSite();

            foreach (SITES s in lstSite)
            {
                if (!busSite.checkExist(s.SiteName))
                {
                    busSite.add(s);
                }
                else
                {
                    busSite.edit(s);
                }
            }

            //Facility
            List <FACILITY> lstFacility = busExcel.getFacility();

            foreach (FACILITY f in lstFacility)
            {
                if (busFacility.checkExist(f.FacilityName))
                {
                    busFacility.edit(f);
                }
                else
                {
                    busFacility.add(f);
                    int FaciID = busFacility.getLastFacilityID();
                    FACILITY_RISK_TARGET riskTarget = new FACILITY_RISK_TARGET();
                    riskTarget.FacilityID = FaciID;
                    busRiskTarget.add(riskTarget);
                }
            }

            //Manufacture
            List <string> manufacture = busExcel.getAllManufacture();

            for (int i = 0; i < manufacture.Count; i++)
            {
                MANUFACTURER manu = new MANUFACTURER();
                manu.ManufacturerID   = busManufacture.getIDbyName(manufacture[i]);
                manu.ManufacturerName = manufacture[i];
                if (busManufacture.getIDbyName(manufacture[i]) == 0)
                {
                    busManufacture.add(manu);
                }
                else
                {
                    busManufacture.edit(manu);
                }
            }

            //Design Code
            List <string> designCode = busExcel.getAllDesigncode();

            for (int i = 0; i < designCode.Count; i++)
            {
                DESIGN_CODE design = new DESIGN_CODE();
                design.DesignCodeID  = busDesignCode.getIDbyName(designCode[i]);
                design.DesignCode    = designCode[i];
                design.DesignCodeApp = "";
                if (design.DesignCodeID == 0)
                {
                    busDesignCode.add(design);
                }
                else
                {
                    busDesignCode.edit(design);
                }
            }

            //Equipment Master
            List <EQUIPMENT_MASTER> lstEquipMaster = busExcel.getEquipmentMaster();

            foreach (EQUIPMENT_MASTER eq in lstEquipMaster)
            {
                if (busEquipMaster.check(eq.EquipmentNumber))
                {
                    busEquipMaster.edit(eq);
                }
                else
                {
                    busEquipMaster.add(eq);
                }
            }

            //Component Master
            List <COMPONENT_MASTER> lstCompMaster = busExcel.getComponentMaster();

            foreach (COMPONENT_MASTER com in lstCompMaster)
            {
                if (busCompMaster.checkExist(com.ComponentNumber))
                {
                    com.ComponentID = busCompMaster.getIDbyName(com.ComponentNumber);
                    busCompMaster.edit(com);
                }
                else
                {
                    busCompMaster.add(com);
                }
            }

            //Rw Assessment
            List <RW_ASSESSMENT> lstAssessment = busExcel.getAssessment();
            List <int>           editExcel     = new List <int>();
            List <int>           addExcel      = new List <int>();

            foreach (RW_ASSESSMENT ass in lstAssessment)
            {
                List <int[]> ID_checkAddbyExcel = busAss.getCheckAddExcel_ID(ass.ComponentID, ass.EquipmentID);
                if (ID_checkAddbyExcel.Count != 0)
                {
                    for (int i = 0; i < ID_checkAddbyExcel.Count; i++)
                    {
                        if (ID_checkAddbyExcel[i][0] != 0) //kiem tra xem co phai Assessment nay duoc them tu file Excel ko
                        {
                            ass.ID = ID_checkAddbyExcel[i][1];
                            editExcel.Add(ass.ID);
                            busAss.edit(ass);
                        }
                    }
                }
                else
                {
                    ass.AddByExcel = 1;
                    busAss.add(ass);
                    int assID = busAss.getLastID();
                    addExcel.Add(assID);
                    RW_INPUT_CA_TANK inputCATank = new RW_INPUT_CA_TANK();
                    inputCATank.ID = assID;
                    busInputCATank.add(inputCATank);
                }
            }

            //RW Equipment
            List <RW_EQUIPMENT> lstEquipment = busExcel.getRwEquipmentTank();

            for (int i = 0; i < lstEquipment.Count; i++)
            {
                if (editExcel.Count != 0)
                {
                    for (int j = 0; j < editExcel.Count; j++)
                    {
                        if (lstEquipment[i].ID == editExcel[j])
                        {
                            busEquip.edit(lstEquipment[i]);
                        }
                    }
                }
                if (addExcel.Count != 0)
                {
                    for (int j = 0; j < addExcel.Count; j++)
                    {
                        if (lstEquipment[i].ID == addExcel[j])
                        {
                            busEquip.add(lstEquipment[i]);
                        }
                    }
                }
            }

            //RW Component
            List <RW_COMPONENT> lstComponent = busExcel.getRwComponentTank();

            for (int i = 0; i < lstComponent.Count; i++)
            {
                if (editExcel.Count != 0)
                {
                    for (int j = 0; j < editExcel.Count; j++)
                    {
                        if (lstComponent[i].ID == editExcel[j])
                        {
                            busCom.edit(lstComponent[i]);
                        }
                    }
                }
                if (addExcel.Count != 0)
                {
                    for (int j = 0; j < addExcel.Count; j++)
                    {
                        if (lstComponent[i].ID == addExcel[j])
                        {
                            busCom.add(lstComponent[i]);
                        }
                    }
                }
            }

            //RW Extcor temperature
            List <RW_EXTCOR_TEMPERATURE> lstExtcor = busExcel.getRwExtTemp();

            for (int i = 0; i < lstExtcor.Count; i++)
            {
                if (editExcel.Count != 0)
                {
                    for (int j = 0; j < editExcel.Count; j++)
                    {
                        if (lstExtcor[i].ID == editExcel[j])
                        {
                            busExtcor.edit(lstExtcor[i]);
                        }
                    }
                }
                if (addExcel.Count != 0)
                {
                    for (int j = 0; j < addExcel.Count; j++)
                    {
                        if (lstExtcor[i].ID == addExcel[j])
                        {
                            busExtcor.add(lstExtcor[i]);
                        }
                    }
                }
            }

            //RW Stream
            List <RW_STREAM> lstStream = busExcel.getRwStreamTank();

            for (int i = 0; i < lstStream.Count; i++)
            {
                if (editExcel.Count != 0)
                {
                    for (int j = 0; j < editExcel.Count; j++)
                    {
                        if (lstStream[i].ID == editExcel[j])
                        {
                            busStream.edit(lstStream[i]);
                        }
                    }
                }
                if (addExcel.Count != 0)
                {
                    for (int j = 0; j < addExcel.Count; j++)
                    {
                        if (lstStream[i].ID == addExcel[j])
                        {
                            busStream.add(lstStream[i]);
                        }
                    }
                }
            }

            //RW Material
            List <RW_MATERIAL> lstMaterial = busExcel.getRwMaterialTank();

            for (int i = 0; i < lstMaterial.Count; i++)
            {
                if (editExcel.Count != 0)
                {
                    for (int j = 0; j < editExcel.Count; j++)
                    {
                        if (lstMaterial[i].ID == editExcel[j])
                        {
                            busMaterial.edit(lstMaterial[i]);
                        }
                    }
                }
                if (addExcel.Count != 0)
                {
                    for (int j = 0; j < addExcel.Count; j++)
                    {
                        if (lstMaterial[i].ID == addExcel[j])
                        {
                            busMaterial.add(lstMaterial[i]);
                        }
                    }
                }
            }

            //RW Coating
            List <RW_COATING> lstCoating = busExcel.getRwCoating();

            for (int i = 0; i < lstCoating.Count; i++)
            {
                if (editExcel.Count != 0)
                {
                    for (int j = 0; j < editExcel.Count; j++)
                    {
                        if (lstCoating[i].ID == editExcel[j])
                        {
                            busCoating.edit(lstCoating[i]);
                        }
                    }
                }
                if (addExcel.Count != 0)
                {
                    for (int j = 0; j < addExcel.Count; j++)
                    {
                        if (lstCoating[i].ID == addExcel[j])
                        {
                            busCoating.add(lstCoating[i]);
                        }
                    }
                }
            }
            ButtonOKClicked = true;
            SplashScreenManager.CloseForm();
            MessageBox.Show("All data have been saved! You need to add Risk Target in Facility!", "Cortek RBI", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            this.Close();
        }
        private void btnImport_Click(object sender, EventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm2));
            // data from file
            SITES_BUS                 busSite         = new SITES_BUS();
            FACILITY_BUS              busFacility     = new FACILITY_BUS();
            MANUFACTURER_BUS          busManufacture  = new MANUFACTURER_BUS();
            DESIGN_CODE_BUS           busDesign       = new DESIGN_CODE_BUS();
            EQUIPMENT_MASTER_BUS      busEqMaster     = new EQUIPMENT_MASTER_BUS();
            COMPONENT_MASTER_BUS      busComMaster    = new COMPONENT_MASTER_BUS();
            RW_ASSESSMENT_BUS         busAss          = new RW_ASSESSMENT_BUS();
            RW_EQUIPMENT_BUS          busEq           = new RW_EQUIPMENT_BUS();
            RW_COMPONENT_BUS          buscom          = new RW_COMPONENT_BUS();
            RW_EXTCOR_TEMPERATURE_BUS busExcort       = new RW_EXTCOR_TEMPERATURE_BUS();
            RW_STREAM_BUS             busStream       = new RW_STREAM_BUS();
            RW_MATERIAL_BUS           busMaterial     = new RW_MATERIAL_BUS();
            RW_COATING_BUS            busCoat         = new RW_COATING_BUS();
            RW_INPUT_CA_LEVEL_1_BUS   busInputCA      = new RW_INPUT_CA_LEVEL_1_BUS();
            FACILITY_RISK_TARGET_BUS  busRiskTarget   = new FACILITY_RISK_TARGET_BUS();
            Bus_PLANT_PROCESS_Excel   busExcelProcess = new Bus_PLANT_PROCESS_Excel();

            busExcelProcess.path = txtPathFileExcel.Text;
            List <SITES> listSite = busExcelProcess.getAllSite();

            foreach (SITES s in listSite)
            {
                if (!busSite.checkExist(s.SiteName))
                {
                    busSite.add(s);
                }
                else
                {
                    busSite.edit(s);
                }
            }

            List <FACILITY> listFacility = busExcelProcess.getFacility();

            foreach (FACILITY f in listFacility)
            {
                if (busFacility.checkExist(f.FacilityName))
                {
                    busFacility.edit(f);
                }
                else
                {
                    busFacility.add(f);
                    int FaciID = busFacility.getLastFacilityID();
                    FACILITY_RISK_TARGET riskTarget = new FACILITY_RISK_TARGET();
                    riskTarget.FacilityID = FaciID;
                    busRiskTarget.add(riskTarget);
                }
            }

            List <string> manufacture = busExcelProcess.getAllManufacture();

            for (int i = 0; i < manufacture.Count; i++)
            {
                MANUFACTURER manu = new MANUFACTURER();
                manu.ManufacturerID   = busManufacture.getIDbyName(manufacture[i]);
                manu.ManufacturerName = manufacture[i];
                if (busManufacture.getIDbyName(manufacture[i]) == 0)
                {
                    busManufacture.add(manu);
                }
                else
                {
                    busManufacture.edit(manu);
                }
            }

            List <String> designcode = busExcelProcess.getAllDesigncode();

            for (int i = 0; i < designcode.Count; i++)
            {
                DESIGN_CODE design = new DESIGN_CODE();
                design.DesignCodeID  = busDesign.getIDbyName(designcode[i]);
                design.DesignCode    = designcode[i];
                design.DesignCodeApp = "";
                if (design.DesignCodeID == 0)
                {
                    busDesign.add(design);
                }
                else
                {
                    busDesign.edit(design);
                }
            }

            List <EQUIPMENT_MASTER> listEpMaster = busExcelProcess.getEquipmentMaster();

            foreach (EQUIPMENT_MASTER eqM in listEpMaster)
            {
                if (busEqMaster.check(eqM.EquipmentNumber))
                {
                    busEqMaster.edit(eqM);
                }
                else
                {
                    busEqMaster.add(eqM);
                }
            }

            List <COMPONENT_MASTER> listComMaster = busExcelProcess.getComponentMaster();

            foreach (COMPONENT_MASTER comM in listComMaster)
            {
                if (busComMaster.checkExist(comM.ComponentNumber))
                {
                    busComMaster.edit(comM);
                }
                else
                {
                    busComMaster.add(comM);
                }
            }

            List <RW_ASSESSMENT> listRW_Assessment = busExcelProcess.getAssessment();
            List <int>           editExcel         = new List <int>();
            List <int>           addExcel          = new List <int>();

            foreach (RW_ASSESSMENT rwAss in listRW_Assessment)
            {
                //kiem tra xem Proposal add bang file Excel hay add bang tay
                List <int[]> ID_checkAddbyExcel = busAss.getCheckAddExcel_ID(rwAss.ComponentID, rwAss.EquipmentID);
                if (ID_checkAddbyExcel.Count != 0)
                {
                    for (int i = 0; i < ID_checkAddbyExcel.Count; i++)
                    {
                        if (ID_checkAddbyExcel[i][0] != 0) //kiem tra xem co phai Assessment nay duoc them tu file Excel ko, !=0 la them tu file Excel
                        {
                            rwAss.ID = ID_checkAddbyExcel[i][1];
                            editExcel.Add(rwAss.ID);
                            busAss.edit(rwAss);
                        }
                    }
                }
                else
                {
                    rwAss.AddByExcel = 1;
                    busAss.add(rwAss);
                    int assID = busAss.getLastID();
                    addExcel.Add(assID);
                    RW_INPUT_CA_LEVEL_1 inputCA = new RW_INPUT_CA_LEVEL_1();
                    inputCA.ID = assID;
                    busInputCA.add(inputCA);
                }
            }

            List <RW_EQUIPMENT> listRw_eq = busExcelProcess.getRwEquipment();

            for (int i = 0; i < listRw_eq.Count; i++)
            {
                if (editExcel.Count != 0)
                {
                    for (int j = 0; j < editExcel.Count; j++)
                    {
                        if (listRw_eq[i].ID == editExcel[j])
                        {
                            busEq.edit(listRw_eq[i]);
                        }
                    }
                }
                if (addExcel.Count != 0)
                {
                    for (int j = 0; j < addExcel.Count; j++)
                    {
                        if (listRw_eq[i].ID == addExcel[j])
                        {
                            busEq.add(listRw_eq[i]);
                        }
                    }
                }
            }

            List <RW_COMPONENT> listRw_com = busExcelProcess.getRwComponent();

            for (int i = 0; i < listRw_com.Count; i++)
            {
                if (editExcel.Count != 0)
                {
                    for (int j = 0; j < editExcel.Count; j++)
                    {
                        if (listRw_com[i].ID == editExcel[j])
                        {
                            buscom.edit(listRw_com[i]);
                        }
                    }
                }
                if (addExcel.Count != 0)
                {
                    for (int j = 0; j < addExcel.Count; j++)
                    {
                        if (listRw_com[i].ID == addExcel[j])
                        {
                            buscom.add(listRw_com[i]);
                        }
                    }
                }
            }

            List <RW_EXTCOR_TEMPERATURE> listRw_extcor = busExcelProcess.getRwExtTemp();

            //MessageBox.Show(listRw_extcor.Count.ToString());
            for (int i = 0; i < listRw_extcor.Count; i++)
            {
                if (editExcel.Count != 0)
                {
                    for (int j = 0; j < editExcel.Count; j++)
                    {
                        if (listRw_extcor[i].ID == editExcel[j])
                        {
                            //MessageBox.Show("add file excel");
                            busExcort.edit(listRw_extcor[i]);
                        }
                    }
                }
                if (addExcel.Count != 0)
                {
                    for (int j = 0; j < addExcel.Count; j++)
                    {
                        if (listRw_extcor[i].ID == addExcel[j])
                        {
                            //MessageBox.Show("add file excel");
                            busExcort.add(listRw_extcor[i]);
                        }
                    }
                }
            }

            List <RW_STREAM> listRw_stream = busExcelProcess.getRwStream();

            for (int i = 0; i < listRw_stream.Count; i++)
            {
                if (editExcel.Count != 0)
                {
                    for (int j = 0; j < editExcel.Count; j++)
                    {
                        if (listRw_stream[i].ID == editExcel[j])
                        {
                            busStream.edit(listRw_stream[i]);
                        }
                    }
                }
                if (addExcel.Count != 0)
                {
                    for (int j = 0; j < addExcel.Count; j++)
                    {
                        if (listRw_stream[i].ID == addExcel[j])
                        {
                            busStream.add(listRw_stream[i]);
                        }
                    }
                }
            }

            List <RW_MATERIAL> listRw_material = busExcelProcess.getRwMaterial();

            for (int i = 0; i < listRw_material.Count; i++)
            {
                if (editExcel.Count != 0)
                {
                    for (int j = 0; j < editExcel.Count; j++)
                    {
                        if (listRw_material[i].ID == editExcel[j])
                        {
                            busMaterial.edit(listRw_material[i]);
                        }
                    }
                }
                if (addExcel.Count != 0)
                {
                    for (int j = 0; j < addExcel.Count; j++)
                    {
                        if (listRw_material[i].ID == addExcel[j])
                        {
                            busMaterial.add(listRw_material[i]);
                        }
                    }
                }
            }

            List <RW_COATING> listRw_coat = busExcelProcess.getRwCoating();

            for (int i = 0; i < listRw_coat.Count; i++)
            {
                if (editExcel.Count != 0)
                {
                    for (int j = 0; j < editExcel.Count; j++)
                    {
                        if (listRw_coat[i].ID == editExcel[j])
                        {
                            busCoat.edit(listRw_coat[i]);
                        }
                    }
                }
                if (addExcel.Count != 0)
                {
                    for (int j = 0; j < addExcel.Count; j++)
                    {
                        if (listRw_coat[i].ID == addExcel[j])
                        {
                            busCoat.add(listRw_coat[i]);
                        }
                    }
                }
            }
            ButtonOKClicked = true;
            SplashScreenManager.CloseForm();
            MessageBox.Show("All data have been saved! You need to add Risk Target in Facility!", "Cortek RBI", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            this.Close();
        }
        public void ShowDatatoControl(int ID)
        {
            RW_COATING_BUS BUS  = new RW_COATING_BUS();
            RW_COATING     coat = BUS.getData(ID);

            String[] extQuality = { "No coating or poor quality", "Medium coating quality", "High coating quality" };
            String[] inType     = { "Organic", "Castable refractory", "Strip lined alloy", "Castable refractory severe condition", "Glass lined", "Acid Brick", "Fibreglass" };
            String[] inCon      = { "Good", "Average", "Poor", "Unknown" };
            String[] extType    = { "Foam Glass", "Pearlite", "Fibreglass", "Mineral Wool", "Calcium Silicate", "Asbestos" };
            String[] isuCon     = { "Above average", "Average", "Below average" };
            if (coat.ExternalCoating == 1)
            {
                chkExternalCoat.Checked = true;
            }
            else
            {
                chkExternalCoat.Checked = false;
            }

            if (coat.ExternalInsulation == 1)
            {
                chkExternalIsulation.Checked = true;
            }
            else
            {
                chkExternalIsulation.Checked = false;
            }

            if (coat.InternalCladding == 1)
            {
                chkInternalCladding.Checked = true;
            }
            else
            {
                chkInternalCladding.Checked = false;
            }

            if (coat.InternalCoating == 1)
            {
                chkInternalCoat.Checked = true;
            }
            else
            {
                chkInternalCoat.Checked = false;
            }

            if (coat.InternalLining == 1)
            {
                chkInternalLining.Checked = true;
            }
            else
            {
                chkInternalLining.Checked = false;
            }

            dateExternalCoating.DateTime = coat.ExternalCoatingDate;


            for (int i = 0; i < extQuality.Length; i++)
            {
                if (coat.ExternalCoatingQuality == extQuality[i])
                {
                    cbExternalCoatQuality.SelectedIndex = i;
                    break;
                }
            }
            for (int i = 0; i < extType.Length; i++)
            {
                if (coat.ExternalInsulationType == extType[i])
                {
                    cbExternalIsulation.SelectedIndex = i + 1;
                    break;
                }
            }
            for (int i = 0; i < inCon.Length; i++)
            {
                if (coat.InternalLinerCondition == inCon[i])
                {
                    cbInternalLinerCondition.SelectedIndex = i + 1;
                    break;
                }
            }

            if (coat.InsulationContainsChloride == 1)
            {
                chkInsulationContainsChlorides.Checked = true;
            }
            else
            {
                chkInsulationContainsChlorides.Checked = false;
            }

            for (int i = 0; i < inType.Length; i++)
            {
                if (coat.InternalLinerType == inType[i])
                {
                    cbInternalLinerType.SelectedIndex = i + 1;
                    break;
                }
            }

            txtCladdingCorrosionRate.Text = coat.CladdingCorrosionRate.ToString();

            if (coat.SupportConfigNotAllowCoatingMaint == 1)
            {
                chkSupport.Checked = true;
            }
            else
            {
                chkSupport.Checked = false;
            }

            for (int i = 0; i < isuCon.Length; i++)
            {
                if (coat.InsulationCondition == isuCon[i])
                {
                    cbIsulationCondition.SelectedIndex = i + 1;
                    break;
                }
            }
        }