예제 #1
0
        private void LoadPlc()
        {
            DBLite db = new DBLite("select Name, Desc, IP, Rack, Slot, Type from PLC where ID=@id");

            db.AddParameter("id", _id, DbType.Int32);
            using (SQLiteDataReader dr = db.ExecReader())
            {
                if (dr.Read())
                {
                    _name = dr.GetString(dr.GetOrdinal("Name"));
                    _ip   = dr.GetString(dr.GetOrdinal("IP"));
                    _rack = dr.GetInt32(dr.GetOrdinal("Rack"));
                    _slot = dr.GetInt32(dr.GetOrdinal("Slot"));

                    switch (dr.GetString(dr.GetOrdinal("Type")))
                    {
                    case "s7-1500":
                        _type = Plc.S7Type.S71500;
                        break;

                    case "s7-1200":
                        _type = Plc.S7Type.S71200;
                        break;

                    case "s7-400":
                        _type = Plc.S7Type.S7400;
                        break;

                    case "s7-300":
                        _type = Plc.S7Type.S7300;
                        break;
                    }
                }
            }
        }
예제 #2
0
        private void LoadSignals()
        {
            // TODO: GetPlcID is not needed, ID is already known
            // TODO: Should use _id;
            int plcid = GetPlcID();

            DBLite db = new DBLite("select Addr, Desc, repre from PLC_Signal where PLC=@id");

            db.AddParameter("id", plcid, DbType.Int32);
            using (SQLiteDataReader dr = db.ExecReader())
            {
                while (dr.Read())
                {
                    dataGridView1.Rows.Add();
                    int newrow = dataGridView1.Rows.Count - 2;

                    string addr  = "";
                    string desc  = "";
                    string repre = "";

                    if (!dr["Addr"].Equals(DBNull.Value))
                    {
                        addr = dr.GetString(dr.GetOrdinal("Addr"));
                    }


                    if (!dr["Desc"].Equals(DBNull.Value))
                    {
                        desc = dr.GetString(dr.GetOrdinal("Desc"));
                    }


                    if (!dr["repre"].Equals(DBNull.Value))
                    {
                        repre = dr.GetString(dr.GetOrdinal("repre"));
                    }

                    dataGridView1.Rows[newrow].Cells["address"].Value = string.IsNullOrEmpty(addr) ? null : addr;
                    dataGridView1.Rows[newrow].Cells["desc"].Value    = desc;

                    if (!string.IsNullOrEmpty(addr))
                    {
                        dataGridView1_CellEndEdit(dataGridView1, new DataGridViewCellEventArgs(dataGridView1.Rows[newrow].Cells["address"].ColumnIndex, dataGridView1.Rows[newrow].Index));
                    }

                    dataGridView1.Rows[newrow].Cells["format"].Value = repre.ToUpper();
                }
                dataGridView1.Update();
            }
        }
예제 #3
0
        private void LoadTree()
        {
            treeView1.Nodes.Clear();
            DBLite db = new DBLite("select PLC.ID as ID, PLC.Name as Name, PLC_type.Name as Type from PLC left join PLC_Type on PLC.Type=PLC_type.ID");

            using (SQLiteDataReader dr = db.ExecReader())
            {
                while (dr.Read())
                {
                    TreeNode node = new TreeNode(dr.GetString(dr.GetOrdinal("Name")) + " [" + dr.GetString(dr.GetOrdinal("Type")) + "]");
                    node.Tag = dr.GetInt32(dr.GetOrdinal("ID"));
                    treeView1.Nodes.Add(node);
                }
            }
        }
예제 #4
0
 private void combo_typ_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (combo_typ.SelectedIndex >= 0)
     {
         DBLite db = new DBLite("select Def_Rack, Def_Slot from PLC_type where ID like @id");
         db.AddParameter("id", combo_typ.SelectedValue, DbType.String);
         using (SQLiteDataReader dr = db.ExecReader())
         {
             if (dr.Read())
             {
                 rack.Value = dr.GetValue(0).Equals(DBNull.Value) ? 0 : dr.GetInt32(0);
                 slot.Value = dr.GetValue(1).Equals(DBNull.Value) ? 0 : dr.GetInt32(1);
             }
         }
     }
 }
예제 #5
0
        private int GetPlcID()
        {
            int    id = 0;
            DBLite db = new DBLite("select ID from PLC where Name like @name and IP like @ip");

            db.AddParameter("name", this._name, DbType.String);
            db.AddParameter("ip", this._ip, DbType.String);
            using (SQLiteDataReader dr = db.ExecReader())
            {
                if (dr.Read())
                {
                    id = dr.GetInt32(0);
                }
            }

            return(id);
        }
예제 #6
0
 private void TestDB()
 {
     try {
         DBLite db = new DBLite("select 1");
         using (SQLiteDataReader dr = db.ExecReader())
         {
             if (dr.Read())
             {
                 return;
             }
         }
     } catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Unable to read from database", MessageBoxButtons.OK, MessageBoxIcon.Error);
         this.Close();
     }
 }
예제 #7
0
        private void LoadPLC()
        {
            DBLite db = new DBLite("SELECT Name,Desc,IP,Rack,Slot,Type FROM PLC where ID=@id");

            db.AddParameter("id", ID, DbType.Int32);
            using (SQLiteDataReader dr = db.ExecReader())
            {
                if (dr.Read())
                {
                    txt_name.Text           = dr.GetString(dr.GetOrdinal("Name"));
                    txt_ip.Text             = dr.GetString(dr.GetOrdinal("IP"));
                    txt_desc.Text           = dr.GetValue(dr.GetOrdinal("Desc")) == DBNull.Value ? "" : dr.GetString(dr.GetOrdinal("Desc"));
                    combo_typ.SelectedValue = dr.GetString(dr.GetOrdinal("Type"));
                    rack.Value = dr.GetInt32(dr.GetOrdinal("Rack"));
                    slot.Value = dr.GetInt32(dr.GetOrdinal("Slot"));
                }
            }
        }
예제 #8
0
        private Boolean PLCExists()
        {
            string query = "select * from PLC where Name like @name";

            if (Edit)
            {
                query = "select * from PLC where Name like @name and ID<>@id";
            }
            DBLite db = new DBLite(query);

            db.AddParameter("name", txt_name.Text, DbType.String);
            if (Edit)
            {
                db.AddParameter("id", ID, DbType.Int32);
            }
            using (SQLiteDataReader dr = db.ExecReader())
            {
                if (dr.HasRows)
                {
                    return(true);
                }
            }
            return(false);
        }