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();
        }
        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();
            }
        }
Ejemplo n.º 3
0
        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();
            }
        }
Ejemplo n.º 4
0
        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();
        }