Exemplo n.º 1
0
        private void DeleteSignals(int PlcID)
        {
            DBLite db = new DBLite("delete from PLC_Signal where PLC=@id");

            db.AddParameter("id", PlcID, DbType.Int32);
            db.Exec();
        }
Exemplo n.º 2
0
        private void smazatToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Delete PLC?", "Delete PLC", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            int id = Convert.ToInt32(treeView1.SelectedNode.Tag);

            if (id >= 0)
            {
                // Signals
                DBLite dbsignals = new DBLite("delete from PLC_Signal where PLC=@id");
                dbsignals.AddParameter("id", id, DbType.Int32);
                dbsignals.Exec();
                // PLC
                DBLite db = new DBLite("delete from PLC where ID=@id");
                db.AddParameter("id", id, DbType.Int32);
                db.Exec();
                // Close
                CloseEdit();
            }

            LoadTree();
        }
Exemplo n.º 3
0
        private void btn_ok_Click(object sender, EventArgs e)
        {
            try {
                if (!string.IsNullOrEmpty(txt_ip.Text) && !string.IsNullOrEmpty(txt_name.Text))
                {
                    if (!Test())
                    {
                        if (MessageBox.Show("Unable to connect to PLC, continue anyway?", "Unable to connect", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            return;
                        }
                    }

                    if (!Edit)
                    {
                        if (!PLCExists())
                        {
                            DBLite db = new DBLite("insert into PLC values (null, @name, ifnull(@desc,''), @ip, @r, @s, @type)");
                            db.AddParameter("name", txt_name.Text, DbType.String);
                            db.AddParameter("desc", txt_desc.Text, DbType.String);
                            db.AddParameter("ip", txt_ip.Text, DbType.String);
                            db.AddParameter("r", rack.Value, DbType.Int32);
                            db.AddParameter("s", slot.Value, DbType.Int32);
                            db.AddParameter("type", combo_typ.SelectedValue.ToString(), DbType.String);
                            db.Exec();
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            MessageBox.Show("There is already PLC with this name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        if (!PLCExists())
                        {
                            DBLite db = new DBLite("update PLC set Name=@name, Desc=@desc, IP=@ip, Rack=@r, Slot=@s, Type=@type where ID=@id ");
                            db.AddParameter("name", txt_name.Text, DbType.String);
                            db.AddParameter("desc", txt_desc.Text, DbType.String);
                            db.AddParameter("ip", txt_ip.Text, DbType.String);
                            db.AddParameter("r", rack.Value, DbType.Int32);
                            db.AddParameter("s", slot.Value, DbType.Int32);
                            db.AddParameter("type", combo_typ.SelectedValue.ToString(), DbType.String);
                            db.AddParameter("id", ID, DbType.Int32);
                            db.Exec();
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            MessageBox.Show("There is already PLC with this name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            } catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error while saving", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 4
0
        private void SaveSignals(int PlcID)
        {
            try
            {
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    string desc  = "";
                    string repre = "";
                    string addr  = "";

                    if (row.Cells["desc"].Value != null)
                    {
                        desc = row.Cells["desc"].Value.ToString();
                    }

                    if (row.Cells["address"].Value != null)
                    {
                        addr = row.Cells["address"].Value.ToString();
                    }

                    if (row.Cells["format"].Value != null)
                    {
                        repre = row.Cells["format"].Value.ToString();
                    }


                    DBLite db = new DBLite("insert into PLC_Signal values (@id, @addr, @desc, @repre)");
                    db.AddParameter("id", this._id, DbType.Int32);
                    db.AddParameter("addr", addr, DbType.String);
                    db.AddParameter("desc", desc, DbType.String);
                    db.AddParameter("repre", repre.ToLower(), DbType.String);
                    db.Exec();
                    db = null;
                }
                MessageBox.Show("Successfully saved", "Saved");
            }catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Save error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }