예제 #1
0
        private async void btn_updatePort_Click(object sender, EventArgs e)
        {
            if (txt_portNumber.Text.Trim().Length == 0)
            {
                MessageBox.Show("Chưa nhập port!");
                return;
            }
            if (txt_language.Text.Trim().Length == 0)
            {
                MessageBox.Show("Chưa nhập language!");
                return;
            }

            this.Enabled = false;
            bool success = false;
            int  loop    = 0;

            do
            {
                if (loop == 10)
                {
                    break;
                }
                try
                {
                    //Xóa cái cũ
                    await portConn.Delete(port.portNumber);

                    //Thêm cái mới
                    port.portNumber = txt_portNumber.Text;
                    port.active     = rb_active_true.Checked;
                    port.data       = rb_data_true.Checked;
                    port.die        = rb_die_true.Checked;
                    port.port       = rb_port_true.Checked;
                    port.language   = Int32.Parse(txt_language.Text);

                    await portConn.Insert(port);

                    success = true;
                }
                catch
                {
                    loop++;
                    Thread.Sleep(2000);
                }
            } while (!success);

            if (!success)
            {
                MessageBox.Show("Đã thử " + loop + " lần mà *** đc :))");
                this.Enabled = true;
            }
            this.Enabled = true;
            this.Close();
        }
예제 #2
0
        private async void btn_addLink_Click(object sender, EventArgs e)
        {
            if (PortSelected == null)
            {
                MessageBox.Show("Chua chon Port!");
                return;
            }

            this.Enabled = false;
            bool success = false;
            int  loop    = 0;

            do
            {
                if (loop == 10)
                {
                    break;
                }
                try
                {
                    Link link = new Link();
                    link.link          = txt_link.Text;
                    link.linkThumbnail = txt_linkThumbnail.Text;
                    link.title         = txt_title.Text;
                    link.tag           = txt_tag.Text;
                    link.description   = txt_description.Text;
                    link.linkAff       = txt_linkAff.Text;
                    link.type          = Int32.Parse(txt_type.Text);

                    LinkConnection linkConn = new LinkConnection(IPSelected.ipAddress, PortSelected.portNumber);
                    await linkConn.Insert(link);

                    //Update port.data
                    PortConnection portConn = new PortConnection(IPSelected.ipAddress);
                    PortSelected = Task.Run(() => portConn.GetWithKey(PortSelected.portNumber)).Result;
                    if (PortSelected.links != null && PortSelected.links.Count > 0 && !PortSelected.data)
                    {
                        PortSelected.data = true;
                        await portConn.Delete(PortSelected.portNumber);

                        await portConn.Insert(PortSelected);

                        loadPort();
                    }

                    success = true;

                    loadLinkWithWaitForm();
                    resetInputLink();
                }
                catch
                {
                    loop++;
                    Thread.Sleep(2000);
                }
            } while (!success);

            if (!success)
            {
                MessageBox.Show("Đã thử " + loop + " lần mà *** đc :))");
                this.Enabled = true;
            }
            this.Enabled = true;
        }