Exemple #1
0
        private void btnCreateSFS_Click(object sender, EventArgs e)
        {
            // MessageBox.Show("Bạn đã tạo thành công dự án" + txtName.Text + " tại : " + Environment.NewLine + "Đường dẫn : " + txtPath.Text);


            DialogResult dialogResult = MessageBox.Show("Bạn muốn giữ nguyên DỮ LIỆU cũ không", "Project mới", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.No)
            {
                G.sourceSQL = G.VariableSQL;
                SQLITE.DeleteAll("DEVICE");
                SQLITE.DeleteAll("CycleTime");
                SQLITE.DeleteAll("Global");
                SQLITE.DeleteAll("LostTime");
                SQLITE.DeleteAll("Yield");
                G.sourceSQL = G.ToolSQL;
                SQLITE.DeleteAll("Quantity");
                SQLITE.DeleteAll("TOOL");
                SQLITE.DeleteAll("Time");
                G.sourceSQL = G.ChartSQL;
                SQLITE.DeleteAll("CHART");
            }
            //INSERT INTO INFOR VALUES ('0','12/09/2018','EMTY','');"; //gancau lech cmd
            G.sourceSQL = G.defautSQL;
            if (!SQLITE.CHECK("*", "INFOR", "NMAE='" + txtName.Text.Trim() + "'"))
            {
                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("SELECTS", "0");
                SQLITE.Update("INFOR", dic, "", G.defautSQL);
                System.IO.Directory.CreateDirectory(txtPath.Text + "\\" + txtName.Text + "\\");
                G.pathSQL = txtPath.Text + "\\" + txtName.Text;
                List <string> list = new List <string>();
                list.Add(DateTime.Now.ToString("dd/MM/yyyy"));
                list.Add(txtName.Text.Trim());
                list.Add(G.pathSQL);
                list.Add("1");
                SQLITE.Insert("INFOR", list);
                this.Close();
                Form1 = new Form1();
                Form1.btnNewDevice.Enabled = true;
                Form1.Text = "Program :" + txtName.Text;
                Form1.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("VUI LÒNG ĐẶT TÊN KHÁC ! ");
            }
        }
Exemple #2
0
        public DATAHOUR(string timeBegin)
        {
            G.sourceSQL = G.VariableSQL;
            string datenows = DateTime.Now.ToString("yyyy-MM-dd");

            foreach (ListVariables ListVariables in G.ListVariables)
            {
                List <string> list         = new List <string>();
                string        nameVariable = "";
                int           iShift       = G.Shift + 1;
                if (ListVariables.Name != null)
                {
                    nameVariable = ListVariables.Name;
                }
                else if (ListVariables.CycleTime != null)
                {
                    nameVariable = ListVariables.CycleTime.Name;
                }
                else if (ListVariables.Yield != null)
                {
                    nameVariable = ListVariables.Yield.Name;
                }
                else if (ListVariables.LostTime != null)
                {
                    nameVariable = ListVariables.LostTime.Name;
                }

                if (!SQLITE.CHECK("*", "DATEHOUR", "DATE='" + datenows + "' AND SHIFT ='" + iShift + "' AND HOUR ='" + timeBegin + "'  AND VARIABLE ='" + nameVariable + "'"))
                {
                    list.Add(datenows);
                    list.Add(iShift + "");
                    list.Add(timeBegin);
                    list.Add(nameVariable + "");
                    list.Add(ListVariables.Val + "");

                    SQLITE.Insert("DATEHOUR", list);
                }
                else
                {
                    Dictionary <string, string> dic = new Dictionary <string, string>();
                    dic.Add("VALUE", ListVariables.Val + "");
                    SQLITE.Update("DATEHOUR", dic, "DATE='" + datenows + "' AND SHIFT ='" + iShift + "' AND HOUR ='" + timeBegin + "'  AND VARIABLE ='" + nameVariable + "'", G.VariableSQL);
                }
            }
        }
Exemple #3
0
        private void UPDATE_SQL(string Tab)
        {
            List <string> nameColumns  = new List <string>();
            List <string> ValueColumn  = new List <string>();
            List <int>    delectSelect = new List <int>();

            for (int i = 0; i < dtEdit.Columns.Count; i++)
            {
                nameColumns.Add(dtEdit.Columns[i].Name);
            }
            foreach (DataGridViewCell cell in dtEdit.SelectedCells)
            {
                delectSelect.Add(cell.RowIndex);
                //ListRowIndexMOD.Add(cell.RowIndex);
            }
            delectSelect = delectSelect.Distinct().ToList();

            foreach (int selectedrowindex in delectSelect)
            {
                DataGridViewRow selectedRow = dtEdit.Rows[selectedrowindex];
                foreach (string nameColumn in nameColumns)
                {
                    ValueColumn.Add(Convert.ToString(selectedRow.Cells[nameColumn].Value));
                    // string VA
                }
                dic = new Dictionary <string, string>();
                dic.Add("VALUE", ValueColumn[5] + "");
                SQLITE.Update("Global", dic, "NAME='" + ValueColumn[0] + "'", G.VariableSQL);
                string Model = G.ListVariables[selectedrowindex].Device.plcKey.PLC.ToString().Split('_')[1] + "_" + G.ListVariables[selectedrowindex].Area;
                eModel = (DBPlcDevice)Enum.Parse(typeof(DBPlcDevice), Model);
                G.ListVariables[selectedrowindex].Device.plcKey.WriteDevice((DBPlcDevice)eModel, G.ListVariables[selectedrowindex].bit, int.Parse(ValueColumn[5]));

                //  Insert(Tab, nameColumns, ValueColumn);

                LoadData(G.curTab);
            }
        }
Exemple #4
0
        public ReadData()
        {
            Enum eModel;

            G.sourceSQL = G.VariableSQL;
            int index = 0;

            foreach (ListVariables ListVariables in G.ListVariables)
            {
                if (ListVariables.Device != null)
                {
                    if (ListVariables.Device.isConnect == isConnect.Connected)
                    {
                        int valBit = 0;
                        Dictionary <string, string> dic = new Dictionary <string, string>();
                        dic = new Dictionary <string, string>();
                        dic.Clear();
                        string Model = ListVariables.Device.plcKey.PLC.ToString().Split('_')[1] + "_" + ListVariables.Area;
                        eModel = (DBPlcDevice)Enum.Parse(typeof(DBPlcDevice), Model);
                        valBit = ListVariables.Device.plcKey.ReadDevice((DBPlcDevice)eModel, ListVariables.bit);
                        if (int.Parse(G.ListVariables[index].Val) != valBit)
                        {
                            G.ListVariables[index].Val = valBit + "";
                            dic = new Dictionary <string, string>();
                            dic.Add("VALUE", G.ListVariables[index].Val + "");
                            SQLITE.Update("Global", dic, "NAME='" + G.ListVariables[index].Name + "'", G.VariableSQL);
                            LoadData = new LoadData("Global");
                        }
                    }
                }
                else
                {
                    if (ListVariables.typeVariable == typeVariable2.CycleTime)
                    {
                        string Model = ListVariables.CycleTime.ListVariables.Device.plcKey.PLC.ToString().Split('_')[1] + "_" + ListVariables.CycleTime.ListVariables.Area;
                        eModel = (DBPlcDevice)Enum.Parse(typeof(DBPlcDevice), Model);

                        if (ListVariables.CycleTime.isCycle == isCycle.open)
                        {
                            // ListVariables.CycleTime.ListVariables.Val = G.ListVariables[index].CycleTime.ListVariables.Device.plcKey.ReadDevice((DBPlcDevice)eModel, ListVariables.CycleTime.ListVariables.bit) + "";
                            if (ListVariables.CycleTime.tempValue != int.Parse(ListVariables.CycleTime.ListVariables.Val) && ListVariables.CycleTime.tempValue != 0 && ListVariables.CycleTime.blStartCycle == false)
                            {
                                ListVariables.CycleTime.dtBegin = DateTime.Now; ListVariables.CycleTime.blStartCycle = true;
                                G.sourceSQL = G.VariableSQL;
                                Dictionary <string, string> dic = new Dictionary <string, string>();
                                dic.Add("TempValue", ListVariables.CycleTime.tempValue + "");
                                SQLITE.Update("CycleTime", dic, "NAME='" + G.ListVariables[index].CycleTime.Name + "'", G.VariableSQL);
                                LoadData = new LoadData("CycleTime");
                            }
                            if (ListVariables.CycleTime.blStartCycle == false)
                            {
                                ListVariables.CycleTime.tempValue = int.Parse(ListVariables.CycleTime.ListVariables.Val);
                            }
                            if (ListVariables.CycleTime.blStartCycle == true && int.Parse(ListVariables.CycleTime.ListVariables.Val) - ListVariables.CycleTime.tempValue >= Convert.ToInt32(ListVariables.CycleTime.numScan) - 1)
                            {
                                ListVariables.CycleTime.dtEnd = DateTime.Now;
                                G.spRead = ListVariables.CycleTime.dtEnd - ListVariables.CycleTime.dtBegin;
                                double second = (double)(G.spRead.Minutes * 60 + G.spRead.Seconds) / Convert.ToInt32(ListVariables.CycleTime.numScan);
                                ListVariables.CycleTime.cycleTime = second + "";
                                //  ListVariables.CycleTime.pDrawing.Add(new Point(-1, second));
                                ListVariables.CycleTime.blStartCycle = false;
                                ListVariables.CycleTime.tempValue    = int.Parse(ListVariables.CycleTime.ListVariables.Val);
                                ListVariables.CycleTime.isCycle      = isCycle.close;
                                Dictionary <string, string> dic = new Dictionary <string, string>();
                                dic.Add("CycleTime", ListVariables.CycleTime.cycleTime + "");
                                dic.Add("isCycle", isCycle.close.ToString() + "");
                                SQLITE.Update("CycleTime", dic, "NAME='" + G.ListVariables[index].CycleTime.Name + "'", G.VariableSQL);
                                LoadData = new LoadData("CycleTime");
                            }
                            G.sourceSQL = G.defautSQL;
                        }
                    }
                    if (ListVariables.typeVariable == typeVariable2.LostTime)
                    {
                        string Model = ListVariables.LostTime.ListVariables.Device.plcKey.PLC.ToString().Split('_')[1] + "_" + ListVariables.LostTime.ListVariables.Area;
                        eModel = (DBPlcDevice)Enum.Parse(typeof(DBPlcDevice), Model);

                        if (ListVariables.LostTime.isLost == isLost.open)
                        {
                            // ListVariables.LostTime.ListVariables.Val = G.ListVariables[index].LostTime.ListVariables.Device.plcKey.ReadDevice((DBPlcDevice)eModel, ListVariables.LostTime.ListVariables.bit) + "";
                            if (ListVariables.LostTime.tempValue != int.Parse(ListVariables.LostTime.ListVariables.Val) && ListVariables.LostTime.tempValue != 0 && ListVariables.LostTime.blStart == false)
                            {
                                ListVariables.LostTime.dtBegin = DateTime.Now; ListVariables.LostTime.blStart = true;
                                G.sourceSQL = G.VariableSQL;
                                Dictionary <string, string> dic = new Dictionary <string, string>();
                                dic.Clear();
                                dic = new Dictionary <string, string>();
                                dic.Add("TempValue", ListVariables.LostTime.tempValue + "");
                                SQLITE.Update("LostTime", dic, "NAME='" + G.ListVariables[index].LostTime.Name + "'", G.VariableSQL);
                                LoadData = new LoadData("LostTime");
                            }
                            if (ListVariables.LostTime.blStart == false)
                            {
                                ListVariables.LostTime.tempValue = int.Parse(ListVariables.LostTime.ListVariables.Val);
                            }
                            if (ListVariables.LostTime.blStart == true && int.Parse(ListVariables.LostTime.ListVariables.Val) - ListVariables.LostTime.tempValue >= Convert.ToInt32(ListVariables.LostTime.tempValue) - 1)
                            {
                                ListVariables.LostTime.dtEnd = DateTime.Now;
                                G.spRead = ListVariables.LostTime.dtEnd - ListVariables.LostTime.dtBegin;
                                double second = (double)(G.spRead.Minutes * 60 + G.spRead.Seconds) / Convert.ToInt32(ListVariables.LostTime.tempValue);
                                ListVariables.LostTime.LostTimes = second + "";
                                //  ListVariables.LostTime.pDrawing.Add(new Point(-1, second));
                                ListVariables.LostTime.blStart   = false;
                                ListVariables.LostTime.tempValue = int.Parse(ListVariables.LostTime.ListVariables.Val);
                                ListVariables.LostTime.isLost    = isLost.close;
                                Dictionary <string, string> dic = new Dictionary <string, string>();
                                dic.Clear();
                                dic.Add("LostTime", ListVariables.LostTime.LostTimes + "");
                                dic.Add("isCycle", isCycle.close.ToString() + "");
                                SQLITE.Update("LostTime", dic, "NAME='" + G.ListVariables[index].LostTime.Name + "'", G.VariableSQL);
                                LoadData = new LoadData("LostTime");
                            }
                            G.sourceSQL = G.defautSQL;
                        }
                    }
                }
                index++;
            }
        }
Exemple #5
0
        private void btnGo_Click(object sender, EventArgs e)
        {
            G.localMain = this.Location;
            Form1       = new Form1();
            if (cbMod.SelectedIndex == 1)
            {
                if (cbProgram.SelectedIndex == cbProgram.Items.Count - 1)
                {
                    Browser = new Browser(this.Form1);
                    Browser.ShowDialog();
                }
                else
                {
                    try
                    {
                        string[] files = System.IO.Directory.GetFiles(G.pathSQL + "\\DATA", " *.sfs");
                    }
                    catch (Exception)
                    {
                        X :        DialogResult dialogResult1 = MessageBox.Show("Dự án :" + G.editTile + Environment.NewLine + "Không tồn tại với đường link :" + G.pathSQL + Environment.NewLine
                                                                                + "Bạn muốn thay đổi đường dẫn khác ?", "Editor", MessageBoxButtons.YesNo);
                        if (dialogResult1 == DialogResult.Yes)
                        {
                            FolderBrowserDialog OpenPJ = new FolderBrowserDialog();

                            OpenPJ.ShowNewFolderButton = true;

                            DialogResult result = OpenPJ.ShowDialog();

                            if (result == DialogResult.OK)
                            {
                                G.pathSQL = OpenPJ.SelectedPath;
                                try
                                {
                                    string[] files = System.IO.Directory.GetFiles(G.pathSQL + "\\DATA.sfs");
                                }
                                catch (Exception)
                                {
                                    goto X;
                                }
                                Dictionary <string, string> dic = new Dictionary <string, string>();
                                dic.Add("PATH", G.pathSQL);
                                SQLITE.Update("INFOR", dic, "NAME='" + G.editTile + "'", G.defautSQL);
                            }

                            Computer comp = new Computer();

                            DialogResult dialogResult = MessageBox.Show("Bạn muốn Sửa chương trình", "Editor", MessageBoxButtons.YesNo);
                            if (dialogResult == DialogResult.Yes)
                            {
                                try
                                {
                                    // System.IO.File.Delete("SQL\\Data.sqlite");
                                    System.IO.File.Delete("SQL\\TOOL.sfs");
                                    System.IO.File.Delete("SQL\\CHART.sfs");
                                    System.IO.File.Delete("SQL\\DATA.sfs");
                                    System.IO.File.Delete("SQL\\Variables.sfs");
                                }
                                catch (Exception)
                                {
                                }
                                comp.FileSystem.CopyFile(G.pathSQL + "\\DATA.sfs", "SQL\\DATA.sfs", UIOption.AllDialogs, UICancelOption.DoNothing);
                                comp.FileSystem.CopyFile(G.pathSQL + "\\TOOL.sfs", "SQL\\TOOL.sfs", UIOption.AllDialogs, UICancelOption.DoNothing);
                                comp.FileSystem.CopyFile(G.pathSQL + "\\CHART.sfs", "SQL\\CHART.sfs", UIOption.AllDialogs, UICancelOption.DoNothing);
                                comp.FileSystem.CopyFile(G.pathSQL + "\\Variables.sfs", "SQL\\Variables.sfs", UIOption.AllDialogs, UICancelOption.DoNothing);

                                Form1.Show();
                            }
                        }
                    }
                }
            }
            else
            {
                LoadSQL = new LoadSQL();
                G.Shift = cbShift.SelectedIndex;
                Graphic.ShowDialog();
            }

            // this.Hide();
        }
Exemple #6
0
        public LoadSQLITE(int wMap)
        {
            G.LisDevice     = new List <string>();
            G.LisPLC        = new List <LisPLC>();
            G.ListGraphic   = new List <ListGraphic>();
            G.ListVariables = new List <ListVariables>();
            G.ListToolGr    = new List <ToolGr>();
            G.ListToolChart = new List <GRAPHIC.ToolChart>();
            G.ListToolTemp  = new List <ToolGr>();
            G.pPen          = new Point(0, 0);
            G.sourceSQL     = G.VariableSQL;
            DataTable dtCycleTime           = new DataTable();
            DataTable dtYield               = new DataTable();
            DataTable dtLostTime            = new DataTable();
            DataTable dtToolQua             = new DataTable();
            DataTable dtToolTime            = new DataTable();
            DataTable dtChart               = new DataTable();
            DataTable dtDevice              = new DataTable();
            DataTable dtVariable            = new DataTable();
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("isCycle", isCycle.open.ToString());
            SQLITE.Update("CycleTime", dic, "", G.VariableSQL);
            dtDevice    = SQLITE.SQL_Table("*", "DEVICE", "");
            dtVariable  = SQLITE.SQL_Table("*", "Global", "");
            dtCycleTime = SQLITE.SQL_Table("*", "CycleTime", "");
            dtYield     = SQLITE.SQL_Table("*", "Yield", "");
            dtLostTime  = SQLITE.SQL_Table("*", "LostTime", "");
            G.sourceSQL = G.ToolSQL;
            // SQLITE.DeleteAll("CHART");
            //   SQLITE.DeleteAll("Quantity");
            //   SQLITE.DeleteAll("Time");
            //SQLITE.DeleteAll("TOOL");
            //SQLITE.Delete("TOOL", "TYPE='Yield'");
            dtToolQua   = SQLITE.SQL_Table("*", "Quantity", "");
            dtToolTime  = SQLITE.SQL_Table("*", "Time", "");
            G.sourceSQL = G.ChartSQL;
            dtChart     = SQLITE.SQL_Table("*", "CHART", "");
            G.sourceSQL = G.VariableSQL;
            foreach (DataRow DataRow in dtDevice.Rows)
            {
                AxDBCommManager plcTemp = new AxDBCommManager();

                DBPlcId eModel = (DBPlcId)Enum.Parse(typeof(MOD), DataRow[3].ToString().Replace("-", ""));

                Via eVia = (Via)Enum.Parse(typeof(Via), DataRow[4].ToString());


                //   plcTemp = KEYENCEs.Create(eModel, eVia, DataRow[5].ToString());
                if (G.isConnect == isConnect.Disconnected)
                {
                    blConnect = false;
                }
                Image picModel, picVia;

                picModel = Image.FromFile(DataRow[3].ToString() + ".png");
                picVia   = Image.FromFile(DataRow[4].ToString() + ".png");
                G.LisPLC.Add(new LisPLC(DataRow[0].ToString(), DataRow[2].ToString(), DataRow[3].ToString(), eVia, DataRow[5].ToString(), plcTemp, G.isConnect, picModel, picVia, G.pPen));
                G.pPen.X += G.spicReview.X + 10;
                if (G.pPen.X + G.spicReview.X >= wMap)
                {
                    G.pPen.Y += G.spicReview.Y + 50;
                    G.pPen.X  = 0;
                }
            }
            foreach (DataRow DataRow in dtVariable.Rows)
            {
                isBit   isBit   = (isBit)Enum.Parse(typeof(isBit), DataRow[6].ToString());
                typeBit typeBit = (typeBit)Enum.Parse(typeof(typeBit), DataRow[4].ToString());
                int     i       = 0;
                int     index   = 0;
                foreach (DataRow DataRow1 in dtDevice.Rows)
                {
                    if (DataRow1[0].ToString() == DataRow[1].ToString())
                    {
                        index = i;
                    }
                    i++;
                }
                G.ListVariables.Add(new ListVariables(DataRow[0].ToString(), G.LisPLC[index], DataRow[2].ToString(), DataRow[3].ToString(), DataRow[5].ToString(), isBit, typeBit, typeVariable2.Global));
            }
            foreach (DataRow DataRow in dtCycleTime.Rows)
            {
                int i     = 0;
                int index = 0;
                foreach (DataRow DataRow1 in dtVariable.Rows)
                {
                    if (DataRow1[0].ToString() == DataRow[1].ToString())
                    {
                        index = i;
                    }
                    i++;
                }

                G.ListVariables.Add(new ListVariables(new CycleTime(DataRow[0].ToString(), G.ListVariables[index], DataRow[2].ToString(), int.Parse(DataRow[3].ToString()), int.Parse(DataRow[4].ToString()), new DateTime(), new DateTime(), isCycle.open, false), typeVariable2.CycleTime));
                //  LoadData("CycleTime");
            }
            foreach (DataRow DataRow in dtLostTime.Rows)
            {
                int i     = 0;
                int index = 0;
                foreach (DataRow DataRow1 in dtVariable.Rows)
                {
                    if (DataRow1[0].ToString() == DataRow[1].ToString())
                    {
                        index = i;
                    }
                    i++;
                }
                G.ListVariables.Add(new ListVariables(new LostTime(DataRow[0].ToString(), G.ListVariables[index], DataRow[2].ToString(), int.Parse(DataRow[3].ToString()), int.Parse(DataRow[4].ToString()), new DateTime(), new DateTime(), isLost.open, false), typeVariable2.LostTime));
            }

            foreach (DataRow DataRow in dtYield.Rows)
            {
                int    i = 0;
                int    index = 0;
                string ListOKsql = "", ListNGsql = "";
                ListOKsql = DataRow[2].ToString();
                ListNGsql = DataRow[3].ToString();
                string[]             ListOKsplit = ListOKsql.Split(',');
                string[]             ListNGsplit = ListNGsql.Split(',');
                List <ListVariables> ListYieldOK = new List <ListVariables>();
                List <ListVariables> ListYieldNG = new List <ListVariables>();
                foreach (ListVariables ListVariables in G.ListVariables)
                {
                    foreach (string ListOK in ListOKsplit)
                    {
                        if (ListVariables.Name == ListOK)
                        {
                            ListYieldOK.Add(ListVariables);
                        }
                    }
                    foreach (string ListNG in ListNGsplit)
                    {
                        if (ListVariables.Name == ListNG)
                        {
                            ListYieldNG.Add(ListVariables);
                        }
                    }
                }
                foreach (DataRow DataRow1 in dtVariable.Rows)
                {
                    if (DataRow1[0].ToString() == DataRow[1].ToString())
                    {
                        index = i;
                    }
                    i++;
                }
                //Color red = Color.FromName("Red");
                G.ListVariables.Add(new ListVariables(new Yield(DataRow[0].ToString(), DataRow[1].ToString(), ListYieldOK, ListYieldNG), typeVariable2.Yield));
            }
            foreach (DataRow DataRow in dtToolQua.Rows)
            {
                var    cvt   = new FontConverter();
                String color = DataRow[5].ToString();
                Font   fonts = new Font("Arial", 10);
                try
                {
                    fonts = cvt.ConvertFromString(DataRow[6].ToString()) as Font;
                }
                catch (Exception)
                {
                }
                String Fcolor = DataRow[7].ToString();
                color = color.Replace("Color [A=", "");
                color = color.Replace("]", "");
                color = color.Replace("Color [", "");
                color = color.Replace("R=", "");
                color = color.Replace("G=", "");
                color = color.Replace("B=", "");

                Fcolor = Fcolor.Replace("Color ", "");
                Fcolor = Fcolor.Replace("]", "");
                Fcolor = Fcolor.Replace("[", "");



                string[] splColor = color.Split(',');
                // string[] splFcolor = Fcolor.Split(',');

                SolidBrush backcolor;
                try
                {
                    backcolor = new SolidBrush(Color.FromArgb(int.Parse(splColor[0]), int.Parse(splColor[1]), int.Parse(splColor[2]), int.Parse(splColor[3])));
                }
                catch (Exception)
                {
                    backcolor = new SolidBrush(Color.FromName(color));
                }
                Color      fontColor = Color.FromName(Fcolor);
                FontDialog fontDlg   = new FontDialog();
                fontDlg.Color = fontColor;
                fontDlg.Font  = fonts;
                int i     = 0;
                int index = 0;
                foreach (ListVariables ListVariables in G.ListVariables)
                {
                    if (ListVariables.Name != null)
                    {
                        if (ListVariables.Name.ToString() == DataRow[2].ToString())
                        {
                            index = i;
                        }
                    }
                    else
                    {
                        if (ListVariables.Yield != null)
                        {
                            if (ListVariables.Yield.Name.ToString() == DataRow[2].ToString())
                            {
                                index = i;
                            }
                        }
                    }
                    i++;
                }
                //string Name,string sShow,TypeGr TypeGr,ListVariables ListVariables, Brush brFont,Color BackColor,int sizeFont,int defaut,Font font,bool isChar,bool isVal,bool isConst)
                TypeGr typeGr = (TypeGr)Enum.Parse(typeof(TypeGr), DataRow[1].ToString());
                G.ListToolGr.Add(new ToolGr(DataRow[0].ToString(), DataRow[3].ToString(), typeGr, G.ListVariables[index], new SolidBrush(fontDlg.Color), backcolor, int.Parse(DataRow[4].ToString()), int.Parse(DataRow[11].ToString()), fontDlg.Font, Boolean.Parse(DataRow[8].ToString()), Boolean.Parse(DataRow[9].ToString()), Boolean.Parse(DataRow[10].ToString())));
            }
            foreach (DataRow DataRow in dtToolTime.Rows)
            {
                var    cvt   = new FontConverter();
                String color = DataRow[5].ToString();
                Font   fonts = new Font("Arial", 10);
                try
                {
                    fonts = cvt.ConvertFromString(DataRow[6].ToString()) as Font;
                }
                catch (Exception)
                {
                }

                String Fcolor = DataRow[7].ToString();
                color = color.Replace("Color [A=", "");
                color = color.Replace("]", "");
                color = color.Replace("Color [", "");
                color = color.Replace("R=", "");
                color = color.Replace("G=", "");
                color = color.Replace("B=", "");

                Fcolor = Fcolor.Replace("Color ", "");
                Fcolor = Fcolor.Replace("]", "");
                Fcolor = Fcolor.Replace("[", "");



                string[] splColor = color.Split(',');
                // string[] splFcolor = Fcolor.Split(',');

                SolidBrush backcolor;
                try
                {
                    backcolor = new SolidBrush(Color.FromArgb(int.Parse(splColor[0]), int.Parse(splColor[1]), int.Parse(splColor[2]), int.Parse(splColor[3])));
                }
                catch (Exception)
                {
                    backcolor = new SolidBrush(Color.FromName(color));
                }
                Color      fontColor = Color.FromName(Fcolor);
                FontDialog fontDlg   = new FontDialog();
                fontDlg.Color = fontColor;
                fontDlg.Font  = fonts;
                int i     = 0;
                int index = 0;
                foreach (ListVariables ListVariables in G.ListVariables)
                {
                    if (ListVariables.CycleTime != null)
                    {
                        if (ListVariables.CycleTime.Name.ToString() == DataRow[2].ToString())
                        {
                            index = i;
                        }
                    }
                    else
                    {
                        //  if (ListVariables.LostTime.Name.ToString() == DataRow[2].ToString())
                        //  {

                        //     index = i;
                        //  }
                    }
                    i++;
                }
                //string Name,string sShow,TypeGr TypeGr,ListVariables ListVariables, Brush brFont,Color BackColor,int sizeFont,int defaut,Font font,bool isChar,bool isVal,bool isConst)
                TypeGr typeGr = (TypeGr)Enum.Parse(typeof(TypeGr), DataRow[1].ToString());
                G.ListToolGr.Add(new ToolGr(DataRow[0].ToString(), DataRow[3].ToString(), typeGr, G.ListVariables[index], new SolidBrush(fontDlg.Color), backcolor, Convert.ToDouble(DataRow[12].ToString()), fontDlg.Font, Boolean.Parse(DataRow[8].ToString()), Boolean.Parse(DataRow[9].ToString()), Boolean.Parse(DataRow[10].ToString())));
            }
            List <ToolChart> ToolChart = new List <GRAPHIC.ToolChart>();
            List <string>    ListNameChart = new List <string>();
            string           nameChart = ""; DateTime dtBegin = new DateTime(); int Reset = 0, Update = 0; Point pOffset = new Point();
            int indexRow = 0;

            foreach (DataRow DataRow in dtChart.Rows)
            {
                if (DataRow[0].ToString() != nameChart && nameChart != "")
                {
                    G.ListGraphic.Add(new ListGraphic(nameChart, ToolChart, G.ListData, dtBegin, Reset, Update, int.Parse(DataRow[5].ToString()), pOffset, int.Parse(DataRow[8].ToString()), bool.Parse(DataRow[9].ToString())));
                    ToolChart = new List <GRAPHIC.ToolChart>();
                }

                //  ToolChart.Clear();
                int i     = 0;
                int index = 0;
                foreach (ToolGr ToolGr in G.ListToolGr)
                {
                    if (DataRow[1].ToString() == ToolGr.Name)
                    {
                        string[] ChartPoint = DataRow[6].ToString().Split(',');
                        ToolChart.Add(new ToolChart(ToolGr, new Point(int.Parse(ChartPoint[0]), int.Parse(ChartPoint[1]))));
                    }
                    i++;
                }
                G.ListData = new List <List <ListData> >();
                dtBegin    = DateTime.Parse(DataRow[2].ToString());
                dtBegin.AddYears(DateTime.Now.Year - dtBegin.Year);
                dtBegin.AddMonths(DateTime.Now.Month - dtBegin.Month);
                dtBegin.AddDays(DateTime.Now.Day - dtBegin.Day);
                Reset           = int.Parse(DataRow[3].ToString());
                Update          = int.Parse(DataRow[4].ToString());
                G.ListToolChart = ToolChart;
                UpdateGraphic(Reset, Update);


                string[] pOffsetSplit = DataRow[7].ToString().Split(',');
                pOffset = new Point(int.Parse(pOffsetSplit[0]), int.Parse(pOffsetSplit[1]));

                nameChart = DataRow[0].ToString();
                indexRow++;
                if (indexRow == dtChart.Rows.Count)
                {
                    G.ListGraphic.Add(new ListGraphic(nameChart, ToolChart, G.ListData, dtBegin, Reset, Update, int.Parse(DataRow[5].ToString()), pOffset, int.Parse(DataRow[8].ToString()), bool.Parse(DataRow[9].ToString())));
                }
            }
        }