Esempio n. 1
0
 //  public ListVariables ListVariables;
 public GlobalVariable(string Name, LisPLC Device, string Area, string bit, string Val, isBit isBit, typeBit typeBit, typeVariable typeVariable)
 {
     this.Device = Device;
     this.Area = Area;
     this.bit = bit;
     this.Val = Val;
     this.isBit = isBit;
     this.typeBit = typeBit;
     this.Name = Name;
     this.typeVariable = typeVariable;
 }
Esempio n. 2
0
        public LoadSQLITE()
        {
            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 >= 10)
                {
                    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())));
                }
            }
            G.sourceSQL  = G.DATASQL;
            G.sPicAvatar = new List <string>();
            G.sPicAvatar = SQLITE.SQL_List(0, SQLITE.SQL_Table("*", "PIC", ""));
        }
Esempio n. 3
0
        private void btnAddVari_Click(object sender, EventArgs e)
        {
            G.sourceSQL = G.VariableSQL;
            if (typeVariable == typeVariable2.CycleTime)
            {
                {
                    if (!cSQL.CHECK("*", "CycleTime", "NAME='" + txtNameVari.Text.Trim() + "' "))
                    {
                        DateTime     dt       = new DateTime();
                        List <Point> pDrawing = new List <Point>();
                        G.ListVariables.Add(new ListVariables(new CycleTime(txtNameNew.Text, G.ListVariables[txtNameVari.SelectedIndex], "0", 0, Convert.ToInt32(numScan_change_V.Value), dt, dt, isCycle.open, false), typeVariable2.CycleTime));
                        List <string> List = new List <string>();
                        List.Add(txtNameNew.Text);
                        List.Add(G.ListVariables[G.ListVariables.Count - 1].CycleTime.ListVariables.Name);
                        List.Add(G.ListVariables[G.ListVariables.Count - 1].CycleTime.cycleTime);
                        List.Add(G.ListVariables[G.ListVariables.Count - 1].CycleTime.tempValue + "");
                        List.Add(G.ListVariables[G.ListVariables.Count - 1].CycleTime.numScan + "");
                        List.Add(G.ListVariables[G.ListVariables.Count - 1].CycleTime.dtBegin + "");
                        List.Add(G.ListVariables[G.ListVariables.Count - 1].CycleTime.dtEnd + "");
                        List.Add(G.ListVariables[G.ListVariables.Count - 1].CycleTime.isCycle.ToString() + "");
                        List.Add(G.ListVariables[G.ListVariables.Count - 1].CycleTime.blStartCycle + "");
                        cSQL.Insert("CycleTime", List);
                        LoadData("CycleTime");
                    }
                    else
                    {
                        MessageBox.Show("Vui lòng nhập tên khác!");
                    }
                }
            }
            else if (typeVariable == typeVariable2.Global)
            {
                if (!cSQL.CHECK("*", "Global", "NAME='" + txtNameVari.Text.Trim() + "' "))
                {
                    if (!cSQL.CHECK("*", "Global", "AREA='" + cbArea.Text.Trim() + "' AND BIT ='" + txtbit.Text.Trim() + "AND DEVICE ='" + cbDevice.Text.Trim() + "'"))
                    {
                        //dynamic itArea = cbArea.Items[cbArea.SelectedIndex];
                        dynamic itTypeBit = cbTypeBit.Items[cbTypeBit.SelectedIndex];

                        typeBit typeBit = (typeBit)int.Parse(itTypeBit.Value);
                        G.ListVariables.Add(new ListVariables(txtNameVari.Text, G.LisPLC[cbDevice.SelectedIndex], cbArea.Text.Trim(), txtbit.Text.Trim(), txtVal.Text, isBit._using, typeBit, typeVariable2.Global));
                        List <string> List = new List <string>();
                        List.Add(txtNameVari.Text);
                        List.Add(G.LisPLC[cbDevice.SelectedIndex].name);
                        List.Add(cbArea.Text.Trim());
                        List.Add(txtbit.Text.Trim());
                        List.Add(typeBit.ToString());
                        List.Add(txtVal.Text);
                        List.Add(isBit._using.ToString());
                        cSQL.Insert("Global", List);
                        LoadData("Global");
                    }
                    else
                    {
                        MessageBox.Show("Vui lòng chọn Bit khác!");
                    }
                }
                else
                {
                    MessageBox.Show("Vui lòng nhập tên khác!");
                }
            }
            else if (typeVariable == typeVariable2.Yield)
            {
                if (!cSQL.CHECK("*", "Yield", "NAME='" + txtNameVari.Text.Trim() + "' "))
                {
                    //  cmd.CommandText = " CREATE TABLE Yield (NAME nvachar(50),Yield nvachar(50),ListOK nvachar(50),ListNG nvachar(50));"; //gancau lech cmd
                    // cmd.ExecuteNonQuery();//thuc thi

                    DateTime     dt       = new DateTime();
                    List <Point> pDrawing = new List <Point>();
                    G.ListVariables.Add(new ListVariables(new Yield(txtNameNew.Text, "100", ListYieldOK, ListYieldNG), typeVariable2.Yield));
                    List <string> List = new List <string>();
                    string        ListOKsql = "", ListNGsql = "";
                    foreach (ListVariables s in ListYieldOK)
                    {
                        ListOKsql += s.Name + ",";
                    }
                    ListOKsql = ListOKsql.Substring(0, ListOKsql.Count() - 1);
                    foreach (ListVariables s in ListYieldNG)
                    {
                        ListNGsql += s.Name + ",";
                    }
                    ListNGsql = ListNGsql.Substring(0, ListNGsql.Count() - 1);
                    List.Add(txtNameNew.Text);
                    List.Add(G.ListVariables[G.ListVariables.Count - 1].Yield.valYield);
                    List.Add(ListOKsql);
                    List.Add(ListNGsql);

                    cSQL.Insert("Yield", List);
                    LoadData("Yield");
                }
                else
                {
                    MessageBox.Show("Vui lòng nhập tên khác!");
                }
            }
            else if (typeVariable == typeVariable2.LostTime)
            {
                if (!cSQL.CHECK("*", "LostTime", "NAME='" + txtNameVari.Text.Trim() + "' "))
                {
                    DateTime     dt       = new DateTime();
                    List <Point> pDrawing = new List <Point>();
                    //(new LostTime(txtNameNew.Text, G.ListVariables[txtNameVari.SelectedIndex], "0", 0, Convert.ToInt32(numScan_change_V.Value), dt, dt, isLost.open, false), typeVariable.LosTime)
                    G.ListVariables.Add(new ListVariables(new LostTime(txtNameNew.Text, G.ListVariables[txtNameVari.SelectedIndex], "0", 0, Convert.ToInt32(numScan_change_V.Value), dt, dt, isLost.open, false), typeVariable2.LostTime));
                    List <string> List = new List <string>();
                    List.Add(txtNameNew.Text);
                    List.Add(G.ListVariables[G.ListVariables.Count - 1].LostTime.ListVariables.Name);
                    List.Add(G.ListVariables[G.ListVariables.Count - 1].LostTime.LostTimes);
                    List.Add(G.ListVariables[G.ListVariables.Count - 1].LostTime.tempValue + "");
                    List.Add(G.ListVariables[G.ListVariables.Count - 1].LostTime.timeMax + "");
                    List.Add(G.ListVariables[G.ListVariables.Count - 1].LostTime.dtBegin + "");
                    List.Add(G.ListVariables[G.ListVariables.Count - 1].LostTime.dtEnd + "");
                    List.Add(G.ListVariables[G.ListVariables.Count - 1].LostTime.isLost.ToString() + "");
                    List.Add(G.ListVariables[G.ListVariables.Count - 1].LostTime.blStart + "");
                    cSQL.Insert("LostTime", List);
                    LoadData("LostTime");
                }
                else
                {
                    MessageBox.Show("Vui lòng nhập tên khác!");
                }
            }
        }