Example #1
0
        private void btnGroupEdit_Click(object sender, EventArgs e)
        {
            try
            {
                id = Convert.ToInt32(lvGroup.SelectedItems[0].SubItems[0].Text);
                if (fieldGroup == false)
                {
                    fieldGroup   = true;
                    cancelGroup  = true;
                    buttonsGroup = "edit";
                    FieldsGroup(); // enable fields
                    ButtonsGroup();

                    txtGroup.Text = lvGroup.SelectedItems[0].SubItems[2].Text;
                }
                else
                {
                    if (fieldGroup == true)
                    {
                        string group = txtGroup.Text;
                        if (group == "")
                        {
                            MessageBox.Show("Please enter the group name", "MPS", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        }
                        else
                        {
                            Entity.variables ent = new Entity.variables();
                            ent.group = group;
                            ent.id    = id;
                            string str = Model.groupModel.editGroup(ent);
                            if (str == "success")
                            {
                                loadGroup();
                                MessageBox.Show("successfully update", "MPS", MessageBoxButtons.OK, MessageBoxIcon.Information);

                                fieldGroup = false;
                                FieldsGroup();
                                buttonsGroup = "default";
                                ButtonsGroup();
                                cancelGroup = false;
                                clearFieldsGroup();
                            }
                            else
                            {
                                MessageBox.Show(str);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Please select the group name you want to edit", "Select", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (field == false)
            {
                field   = true;
                cancel  = true;
                buttons = "add";
                Fields(); // enable fields
                Buttons();
            }
            else
            {
                if (field == true)
                {
                    string mobile_no = txtContact.Text.Trim();
                    string network   = cboNetwork.Text;
                    string group     = cboGroup.Text;
                    if (mobile_no == "" || network == "")
                    {
                        MessageBox.Show("Please enter the number and network", "MPS", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    else
                    {
                        Entity.variables ent = new Entity.variables();
                        ent.mobile_no = mobile_no;
                        ent.network   = network;
                        ent.group     = group;
                        string str = Model.contactModel.addContact(ent);
                        if (str == "success")
                        {
                            loadContact();

                            MessageBox.Show("successfully added", "MPS", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            field = false;
                            Fields();
                            buttons = "default";
                            Buttons();
                            cancel = false;
                            clearFields();
                            loadGroup();
                        }
                        else
                        {
                            MessageBox.Show(str);
                        }
                    }
                }
            }
        }
Example #3
0
        private void btnGroupAdd_Click(object sender, EventArgs e)
        {
            if (fieldGroup == false)
            {
                fieldGroup   = true;
                cancelGroup  = true;
                buttonsGroup = "add";
                FieldsGroup(); // enable fields
                ButtonsGroup();
            }
            else
            {
                if (fieldGroup == true)
                {
                    string group = txtGroup.Text;
                    if (group == "")
                    {
                        MessageBox.Show("Please enter group name", "MPS", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    else
                    {
                        Entity.variables ent = new Entity.variables();
                        ent.group = group;
                        string str = Model.groupModel.addGroup(ent);
                        if (str == "success")
                        {
                            loadGroup();
                            MessageBox.Show("successfully added", "MPS", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            fieldGroup = false;
                            FieldsGroup();
                            buttonsGroup = "default";
                            ButtonsGroup();
                            cancelGroup = false;
                            clearFieldsGroup();
                        }
                        else
                        {
                            MessageBox.Show(str);
                        }
                    }
                }
            }
        }
Example #4
0
        /**
         * Load data from database
         */
        public void loadContact(string filter = "All", string search = "All")
        {
            str = Model.contactModel.getContacts(pageNumber, filter, search);
            if (str == "success")
            {
                totalCount = config.records.Count;
                lvContact.Items.Clear();
                if (totalCount > 0)
                {
                    for (int count = 0; count < config.records.Count; count++)
                    {
                        ListViewItem item = new ListViewItem(config.records[count].id.ToString());
                        item.SubItems.Add(count.ToString());
                        item.SubItems.Add(config.records[count].mobile_no.ToString());
                        item.SubItems.Add(config.records[count].network.ToString());
                        item.SubItems.Add(config.records[count].group.ToString());
                        lvContact.Items.Add(item);
                        item_new_id = config.records[count].id;
                    }

                    Model.contactModel.getTotalPage();
                    Entity.variables variables = new Entity.variables();


                    if (item_new_id == item_old_id)
                    {
                    }
                    else
                    {
                        item_old_id   = item_new_id;
                        totalPage     = ((config.records[0].totalpage / Entity.variables.pageSize) + 1);
                        lblPages.Text = "Page " + pageNumber + " of " + ((config.records[0].totalpage / Entity.variables.pageSize) + 1).ToString();
                    }
                }
            }
            else
            {
                logs.log(str);
            }
        }
Example #5
0
        public void checkForIncommingMessage()
        {
            List <string> ports = Model.MainFormModel.getListActivePorts();

            logs.log("Checking Message : " + string.Join(",", ports));

            for (int i = 0; i < ports.Count; i++)
            {
                try
                {
                    //Serial Ports Setting
                    SerialPort sp = new SerialPort();
                    sp.PortName  = ports[i];
                    sp.BaudRate  = 115200;
                    sp.Parity    = Parity.None;
                    sp.StopBits  = StopBits.One;
                    sp.DataBits  = 8;
                    sp.Handshake = Handshake.None;
                    sp.RtsEnable = true;
                    sp.NewLine   = "\n";

                    //sp.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
                    sp.Open();
                    //sp.WriteLine("AT\r");


                    if (sp.IsOpen)
                    {
                        sp.WriteLine("AT\r");
                        Thread.Sleep(500);
                        sp.WriteLine("AT+CMGF=1\r");
                        Thread.Sleep(500);
                        sp.WriteLine("AT+CMGL=\"REC UNREAD\"\r");
                        Thread.Sleep(3000);
                        Regex regEx = new Regex(@"\+CMGL: (\d+),""(.+)"",""(.+)"",(.*),""(.+)""\r\n(.+)\r\n");
                        Match match = regEx.Match(sp.ReadExisting());
                        while (match.Success)
                        {
                            string inboxID          = match.Groups[1].Value;
                            string inboxStatus      = match.Groups[2].Value;
                            string inboxSender      = match.Groups[3].Value;
                            string inboxDateAndTime = match.Groups[4].Value;
                            string inboxBlank       = match.Groups[5].Value;
                            string inboxData        = match.Groups[6].Value;
                            //MessageBox.Show(inboxID);

                            string           filteredMobileNo = inboxSender.Replace("+63", "0").Trim();
                            Entity.variables entity           = new Entity.variables();
                            if (inboxData.Trim().Contains("YES"))
                            {
                                string checkMobileNumber = Model.MainFormModel.checkMobileLastPromo(filteredMobileNo);

                                if (checkMobileNumber == "success")
                                {
                                    entity.promotionTitle = Model.MainFormModel.getLastPromo(filteredMobileNo);
                                    entity.mobile_no      = inboxSender;
                                    entity.message        = inboxData;
                                    string insertMessage = Model.MainFormModel.addMessages(entity);

                                    if (insertMessage != "success")
                                    {
                                        logs.log("Saving Message Failed: " + insertMessage);
                                    }
                                }
                            }
                            else
                            {
                                entity.promotionTitle = "N";
                                entity.mobile_no      = inboxSender;
                                entity.message        = inboxData;
                                string insertMessage = Model.MainFormModel.addMessages(entity);

                                if (insertMessage != "success")
                                {
                                    logs.log("Saving Message Failed: " + insertMessage);
                                }
                            }

                            string checkForAutoReplay = Model.MainFormModel.checkForAutoReplay(inboxData);
                            if (checkForAutoReplay != "false")
                            {
                                sp.WriteLine("AT+CMGS=\"" + filteredMobileNo + "\"\r");
                                Thread.Sleep(1000);
                                sp.WriteLine(checkForAutoReplay + "\x1a");
                                Thread.Sleep(4000);
                                logs.log("Auto Replay Done");
                            }


                            match = match.NextMatch();
                        }
                    }
                    sp.Close();
                }
                catch (Exception exception)
                {
                    //Log the Error
                    logs.log("ExceptionMainForm: " + exception.Message);
                }
            }
        }
Example #6
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                id = Convert.ToInt32(lvContact.SelectedItems[0].Text);
                if (field == false)
                {
                    field   = true;
                    cancel  = true;
                    buttons = "edit";
                    Fields(); // enable fields
                    Buttons();

                    txtContact.Text = lvContact.SelectedItems[0].SubItems[2].Text;
                    cboNetwork.Text = lvContact.SelectedItems[0].SubItems[3].Text;
                    cboGroup.Text   = lvContact.SelectedItems[0].SubItems[4].Text;
                }
                else
                {
                    if (field == true)
                    {
                        string mobile_no = txtContact.Text.Trim();
                        string network   = cboNetwork.Text;
                        string group     = cboGroup.Text;
                        if (mobile_no == "" || network == "")
                        {
                            MessageBox.Show("Please enter the number and network", "MPS", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        }
                        else
                        {
                            Entity.variables ent = new Entity.variables();
                            ent.mobile_no = mobile_no;
                            ent.network   = network;
                            ent.group     = group;
                            ent.id        = id;
                            string str = Model.contactModel.editContact(ent);
                            if (str == "success")
                            {
                                loadContact();

                                MessageBox.Show("successfully update", "MPS", MessageBoxButtons.OK, MessageBoxIcon.Information);

                                field = false;
                                Fields();
                                buttons = "default";
                                Buttons();
                                cancel = false;
                                clearFields();
                                loadGroup();
                            }
                            else
                            {
                                MessageBox.Show(str);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Please select the number you want to edit", "Select", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #7
0
        private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            int portCounter = SerialPort.GetPortNames().Length;
            var tasks       = new List <Task>();

            string[] ports = SerialPort.GetPortNames();
            Model.splashModel.deleteAvailablePorts();
            for (int i = 0; i < ports.Length; i++)
            {
                try
                {
                    SerialPort sp = new SerialPort();
                    sp.PortName  = ports[i];
                    sp.BaudRate  = 115200;
                    sp.Parity    = Parity.None;
                    sp.StopBits  = StopBits.One;
                    sp.DataBits  = 8;
                    sp.Handshake = Handshake.None;
                    sp.RtsEnable = true;
                    sp.NewLine   = "\n";

                    //sp.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);


                    sp.Open();



                    Task task = Task.Factory.StartNew(() =>
                    {
                        if (sp.IsOpen)
                        {
                            string portName = sp.PortName;
                            Thread.Sleep(1000);
                            sp.WriteLine("AT\r");
                            Thread.Sleep(2000);

                            string result = sp.ReadExisting();
                            if (result.Contains("OK"))
                            {
                                sp.WriteLine("AT+CNUM\r");
                                Thread.Sleep(2000);
                                string cmdReadMobileNo = sp.ReadExisting();
                                string[] lineResult    = cmdReadMobileNo.Split(
                                    new[] { Environment.NewLine },
                                    StringSplitOptions.None
                                    );
                                string[] strCNUM = lineResult[2].Split(',');

                                Entity.variables entity = new Entity.variables();
                                entity.port             = sp.PortName;
                                entity.mobile_no        = strCNUM[1];
                                entity.network          = "ON-Development";
                                entity.balance          = 0;

                                string addAvailablePortsResult = Model.splashModel.addAvailablePorts(entity);
                                if (addAvailablePortsResult == "success")
                                {
                                    //Insertion success
                                }
                                else
                                {
                                    // Log the errors
                                }
                            }
                        }
                    });

                    task.Wait();
                    double          percentage = (double)(i + 1) / (double)ports.Length;
                    Action <double> update     = p =>
                    {
                        progressBar.Value = (int)Math.Round(p * 100);
                    };
                    this.Invoke(update, percentage);
                }
                catch (Exception exs) {
                    //Log the Error
                    logs.log("Splash BG Worker: " + exs);
                }
            }
        }