Exemple #1
0
        private void listView_tag_KeyDown(object sender, KeyEventArgs e)
        {
            // delete operation for tag
            if (e.KeyCode == Keys.Delete && lastSelectedPLC >= 0)
            {
                // check if current user has the authority to do this operation
                if (GPLC.AuthVerify(Security.GPLCAuthority.Administrator))
                {
                    // index of the last selected plc should not be over the list range
                    Debug.Assert(lastSelectedPLC < markers[_shownMarker].ProjectData.plcs.Count);

                    if (listView_tag.SelectedIndices.Count > 0)
                    {
                        // last selected plc
                        PLC plc = markers[_shownMarker].ProjectData.plcs[lastSelectedPLC];
                        // last selected tag
                        int index = listView_tag.SelectedIndices[0];
                        // db operation
                        ModelUtil.deleteTag(plc.tags[index].id);
                        // refresh tag list
                        refreshTagList();
                    }
                }
            }
        }
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            // check authentication
            GPLC.Auth(GPLCAuthority.Administrator);

            ModelUtil.deleteProject((marker as ProjectMarker).ProjectData.id);
            //refresh map
            GPLC.Refresh();
            this.Parent.Dispose();
        }
Exemple #3
0
 private void listView_tag_DoubleClick(object sender, EventArgs e)
 {
     // check if current user has the authority to do this operation
     if (GPLC.AuthVerify(Security.GPLCAuthority.Administrator))
     {
         // get the index of selected plc, -1 if no selection
         int index = listView_tag.SelectedIndices.Count > 0 ? listView_tag.SelectedIndices[0] : -1;
         // show tag edit control
         TagEditControl(index);
     }
 }
        private void InputButton_Click(object sender, EventArgs e)
        {
            try
            {
                // parse
                long   id   = long.Parse(textBox_project_id.Text);
                string name = textBox_project_Name.Text.Trim();
                string addr = richTextBox_project_addr.Text.Trim();
                double lat  = double.Parse(textBox_latlng_lat.Text.Trim());
                double lng  = double.Parse(textBox_latlng_lng.Text.Trim());
                // check name
                if (name.Length < 4)
                {
                    throw new FormatException("Name長度必須超過4");
                }
                // check latlng
                if (lat > 90 || lat < -90 || lng > 180 || lat < -180)
                {
                    throw new FormatException("Latlng value out of bound");
                }

                // check authentication
                GPLC.Auth(GPLCAuthority.Administrator);

                // update database
                if (InputButton.Text.Equals("Modify"))
                {
                    long oid = (marker as ProjectMarker).ProjectData.id;
                    ModelUtil.updateProject(id, name, addr, lat, lng, oid);
                }
                else
                {
                    ModelUtil.insertProject(id, name, addr, lat, lng);
                }

                //refresh map
                GPLC.Refresh();
                this.Parent.Dispose();
            }
            catch (FormatException ex)
            {
                label_info.Text = ex.Message;
            }
            catch (UnauthorizedException ex)
            {
                MessageBox.Show(ex.Message, "Fatal Error");
                Application.Exit();
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                // check authentication
                GPLC.Auth(GPLCAuthority.Administrator);

                long id       = (tag != null) ? tag.id : -1;
                Tag  inputTag = new Tag(id, textBox_name.Text,
                                        textBox_addr.Text, comboBox_type.Text,
                                        comboBox_format.Text, textBox_unit.Text, plcid);

                if (checkBox_scale_linear.Checked)
                {
                    Scaling scale = new Scaling(comboBox_scale_type.Text,
                                                textBox_raw_hi.Text, textBox_raw_lo.Text,
                                                textBox_scale_hi.Text, textBox_scale_lo.Text);
                    id = id < 0 ? ModelUtil.inputTag(inputTag) : id;
                    ModelUtil.inputScaling(scale, id);
                }
                else
                {
                    if (id >= 0)
                    {
                        ModelUtil.deleteScaling(id);
                    }
                    ModelUtil.inputTag(inputTag);
                }
                this.Parent.Refresh();
            }
            catch (FormatException ex)
            {
                label_info.Text = ex.Message;
            }
            catch (UnauthorizedException ex)
            {
                MessageBox.Show(ex.Message, "Fatal Error");
                Application.Exit();
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                // check authentication
                GPLC.Auth(GPLCAuthority.Administrator);

                // parse textBox
                string alias     = textBox_name.Text;
                int    net_id    = int.Parse(textBox_net_ID.Text);
                string ip        = textBox_net_ip.Text;
                int    port      = int.Parse(textBox_net_port.Text);
                int    poll_rate = int.Parse(textBox_poll_rate.Text);

                if (plc != null)
                {
                    plc = new PLC(plc.id, alias, net_id, ip, port, poll_rate, null);
                    // input plc : update record if exist; otherwise, insert a new one
                    ModelUtil.inputPLC(plc, project.id);
                }
                // insert a new plc
                else
                {
                    ModelUtil.insertPLC(alias, net_id, ip, port, poll_rate, project.id);
                }
                this.Parent.Refresh();
            }
            catch (FormatException)
            {
                //MessageBox.Show(ex.Message);
            }
            catch (UnauthorizedException ex)
            {
                MessageBox.Show(ex.Message, "Fatal Error");
                Application.Exit();
            }
        }
        public void init(GMapMarker marker)
        {
            // check authentication
            GPLC.Auth(GPLCAuthority.Administrator);

            this.marker = marker;
            // initial
            if (marker is ProjectMarker)
            {
                ProjectData p = (marker as ProjectMarker).ProjectData;
                label_project.Text = "設定專案";
                InputButton.Text   = "Modify";
                setInput(p.id, p.name, p.addr, p.lat, p.lng);
                DeleteButton.Visible = true;
            }
            else
            {
                label_project.Text = "新增專案";
                setInput(null, "", "", marker.Position.Lat, marker.Position.Lng);
                InputButton.Dock = DockStyle.Fill;
            }
            label_info.Text = "";
            this.Show();
        }