Esempio n. 1
0
        private void updateAlarmPackageGrid()
        {
            var context = new db_sqlceEntities();
            var cn      = listView1.Items[3].SubItems[1].Text;

            try
            {
                var query = from c in context.package_al
                            where (c.date_inc >= dateTimePicker1.Value && c.date_inc <= dateTimePicker2.Value) &&
                            (c.na.Equals(cn))

                            select new
                {
                    da = c.date_inc,
                    sn = c.na,
                    wr = c.wr_txt
                };

                var results = query.ToList();
                this.bindingWarningSource.DataSource = results;
            }
            catch (EntitySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (this.textBox1.Text != "")
     {
         using (var context = new db_sqlceEntities())
         {
             var q = context.counters.FirstOrDefault(c => c.serial_amspi == textBox2.Text);
             if (q == null)
             {
                 var cnt = new counters()
                 {
                     objects_place_id         = _treeNodeId,
                     serial_amspi             = textBox2.Text,
                     date_init_calibration_r1 = dateTimePicker1.Value.Date,
                     date_init_calibration_r2 = dateTimePicker2.Value.Date,
                     date_calibration_r1      = dateTimePicker3.Value.Date,
                     date_calibration_r2      = dateTimePicker4.Value.Date,
                     date_calibration_amspi   = dateTimePicker5.Value.Date,
                     diameter_r1 = Convert.ToInt32(textBox5.Text),
                     diameter_r2 = Convert.ToInt32(textBox6.Text),
                     date_start  = dateTimePicker6.Value.Date
                 };
                 context.counters.Add(cnt);
                 context.SaveChanges();
                 this.Close();
             }
             else
             {
                 MessageBox.Show("ППУ-РМ с таким серийным номером уже установлен!");
             }
         }
     }
 }
Esempio n. 3
0
 private void toolStripButton1_Click(object sender, EventArgs e)
 {
     if (ownersDataGridView.SelectedCells.Count > 0)
     {
         DialogResult dialogResult = MessageBox.Show("Вы действительно хотите удалить выбранный пункт?",
                                                     "Подтвердите удаление!", MessageBoxButtons.YesNo);
         if (dialogResult == DialogResult.Yes)
         {
             int i = (int)ownersDataGridView.CurrentRow.Cells[0].Value;
             using (var context = new db_sqlceEntities())
             {
                 try
                 {
                     var obPlc = context.owners.FirstOrDefault(p => p.id == i);
                     if (obPlc != null)
                     {
                         context.owners.Remove(obPlc);
                         context.SaveChanges();
                         LoadData();
                         //loadTree();
                     }
                 }
                 catch (EntitySqlException ex)
                 {
                     MessageBox.Show(ex.Message);
                 }
             }
         }
         else if (dialogResult == DialogResult.No)
         {
             return;
         }
     }
 }
Esempio n. 4
0
        public void loadTree()
        {
            doneNotes.Clear();
            dtTable = new DataTable("TreeView");
            dtTable.Columns.Add("PlaceID", typeof(string));
            dtTable.Columns.Add("PlaceName", typeof(string));
            DataColumn dc = new DataColumn("PlaceParentID", typeof(string))
            {
                AllowDBNull = true
            };

            dtTable.Columns.Add(dc);

            using (var context = new db_sqlceEntities())
            {
                foreach (var db in context.objects_place.ToList())
                {
                    dtTable.Rows.Add(db.id, db.name, db.objects_place_id);
                }
            }


            CreateNodes();

            /* byte[] myBytes = {0,0,0,0,0,88,112,64}; //assume you pad your array with enough zeros to make it 8 bytes.
             * var myDouble = BitConverter.ToDouble(myBytes,0);
             * byte[] byt = BitConverter.GetBytes(261.5);
             * Console.WriteLine(byt.ToString());
             * Console.WriteLine(myDouble.ToString("F", CultureInfo.InvariantCulture));*/
        }
Esempio n. 5
0
 private void удалитьОбъектToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (var context = new db_sqlceEntities())
     {
         try
         {
             var ttt = context.objects_place.LongCount(p => p.objects_place_id == _treeNodeId);
             if (ttt > 0)
             {
                 MessageBox.Show("У объекта есть вложенные объекты!");
             }
             else
             {
                 var obPlc = context.objects_place.FirstOrDefault(p => p.id == _treeNodeId);
                 if (obPlc != null)
                 {
                     context.objects_place.Remove(obPlc);
                     context.SaveChanges();
                     loadTree();
                 }
             }
         }
         catch (EntitySqlException ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
Esempio n. 6
0
        private void startHttpService()
        {
            int ip_port = 8080;

            using (var context = new db_sqlceEntities())
            {
                try
                {
                    var opt = context.options.FirstOrDefault();
                    if (opt != null && opt.is_ip)
                    {
                        ip_port    = (int)opt.ip_port;
                        httpServer = new MyHttpServer(ip_port);
                        thread     = new Thread(new ThreadStart(httpServer.listen));
                        Debug.WriteLine("стартуем хттп");
                        thread.IsBackground = true;
                        thread.Start();
                    }
                }
                catch (EntitySqlException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Esempio n. 7
0
        private void MailService()
        {
            MailService mailService = VodopriborUchet.MailService.GetInstance();

            using (var context = new db_sqlceEntities())
            {
                try
                {
                    var opt = context.options.FirstOrDefault();
                    if (opt != null)
                    {
                        if (opt.is_mail == true)
                        {
                            mailService.StartMailService();
                        }
                        if (opt.is_mail == false)
                        {
                            mailService.StopMailService();
                        }
                    }
                }
                catch (EntitySqlException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Esempio n. 8
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (this.textBox1.Text != "" && this.textBox2.Text != "" && this.textBox3.Text != "")
     {
         using (var context = new db_sqlceEntities())
         {
             try
             {
                 var objct = new owners()
                 {
                     name            = this.textBox1.Text,
                     surname         = this.textBox2.Text,
                     patronymic      = this.textBox3.Text,
                     tel             = this.textBox4.Text,
                     category_pay_id = (int?)this.comboBox1.SelectedValue
                 };
                 context.owners.Add(objct);
                 context.SaveChanges();
                 mEditOwners.LoadData();
                 this.Close();
             }
             catch (DbEntityValidationException ex)
             {
                 MessageBox.Show(ex.ToString());
             }
         }
     }
 }
Esempio n. 9
0
        private void AddOwner_Load(object sender, EventArgs e)
        {
            var context = new db_sqlceEntities();

            try
            {
                var query = from c in context.category_pay_type
                            select new
                {
                    c.id,
                    c.name             //new {c_name = c.name, c_ucost = c.net, a_name = c.kod_BTI};
                };
                var results = query.ToList();
                this.comboBox1.DataSource    = results;
                this.comboBox1.DisplayMember = "name";
                this.comboBox1.ValueMember   = "id";

                //this.objects_placeBindingSource.Columns[0].Visible = false;
                // context.SaveChanges();
            }
            catch (EntitySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 10
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (this.textBox1.Text != "" && this.textBox2.Text != "")
     {
         if (ValidateInt())
         {
             using (var context = new db_sqlceEntities())
             {
                 try
                 {
                     var objct = new impulse()
                     {
                         weight = Convert.ToInt32(this.textBox1.Text),
                         code   = Convert.ToInt32(this.textBox2.Text)
                     };
                     context.impulse.Add(objct);
                     context.SaveChanges();
                     editImpulse.LoadData();
                     this.Close();
                 }
                 catch (DbEntityValidationException ex)
                 {
                     MessageBox.Show(ex.ToString());
                 }
             }
         }
     }
 }
Esempio n. 11
0
        private List <string> getMessagesUIDFromBase(int c, Pop3Client client)
        {
            List <string> uids = new List <string>();

            using (var context = new db_sqlceEntities())
            {
                try
                {
                    uids.AddRange(from al in context.package_al
                                  where al.mail_uid != null
                                  select al.mail_uid);
                    uids.AddRange(from al in context.package_iz
                                  where al.mail_uid != null
                                  select al.mail_uid);
                    uids.AddRange(from al in context.package_on
                                  where al.mail_uid != null
                                  select al.mail_uid);
                    uids.AddRange(from al in context.package_tm
                                  where al.mail_uid != null
                                  select al.mail_uid);
                    uids.AddRange(from al in context.package_ts
                                  where al.mail_uid != null
                                  select al.mail_uid);
                }
                catch (SqlCeException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            return(uids);
        }
Esempio n. 12
0
        private void updateDataPackagesGrid()
        {
            var context = new db_sqlceEntities();
            var cn      = listView1.Items[3].SubItems[1].Text;

            try
            {
                var query = from c in context.package_iz
                            from p1 in context.impulse.Where(p => p.code == c.pw1).DefaultIfEmpty()
                            from p2 in context.impulse.Where(p => p.code == c.pw2).DefaultIfEmpty()
                            where (c.da >= dateTimePicker1.Value && c.da <= dateTimePicker2.Value) &&
                            (c.na.Equals(cn))

                            select  new PackageC()
                {
                    date = c.date_inc,
                    r1   = (float)(c.r1 * p1.weight) / 1000,          // * c.pw1 / 1000,
                    r2   = (float)(c.r2 * p2.weight) / 1000,          //* c.pw2 / 1000
                    r1_c = 0,
                    r2_c = 0
                };



                var results = query.ToList();


                for (var i = 1; i < results.Count; i++)
                {
                    results[i].r1_c = results[i].r1 - results[i - 1].r1;
                    results[i].r2_c = results[i].r2 - results[i - 1].r2;
                }

                this.bindingPackageSource.DataSource = results;

                /*   DataTable dat = new DataTable();
                 *
                 *
                 * using (SqlCeDataAdapter adap =
                 *           new SqlCeDataAdapter("SELECT * from package_iz unpivot (Cons for  r1_0, r1_1,r1_2,r1_3,r1_4,r1_5,r1_6,r1_7,r1_8,r1_9,r1_10,r1_11 FROM package_iz p" +
                 *
                 *                                " ", @"Data Source=C:\Users\User\Documents\Visual Studio 2013\Projects\VodopriborUchet\VodopriborUchet\db\db_sqlce.sdf"))
                 * {
                 *     //the adapter will open and close the connection for you.
                 *     adap.Fill(dat);
                 * }
                 */
            }
            catch (EntitySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 13
0
        private void AddPlace_Load(object sender, EventArgs e)
        {
            var context = new db_sqlceEntities();

            try
            {
                var query = from c in context.object_type
                            select new
                {
                    c.id,
                    c.name            //new {c_name = c.name, c_ucost = c.net, a_name = c.kod_BTI};
                };
                var results = query.ToList();

                var query1 = from c in context.net
                             select new
                {
                    c.id,
                    c.name            //new {c_name = c.name, c_ucost = c.net, a_name = c.kod_BTI};
                };
                var results1 = query1.ToList();
                this.comboBox1.DataSource    = results;
                this.comboBox1.DisplayMember = "name";
                this.comboBox1.ValueMember   = "id";
                this.comboBox2.DataSource    = results1;
                this.comboBox2.DisplayMember = "name";
                this.comboBox2.ValueMember   = "id";
            }
            catch (EntitySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }

            try
            {
                var query1 = from c in context.owners
                             select new
                {
                    c.id, fio = c.surname + " " + c.name + " " + c.patronymic         //new {c_name = c.name, c_ucost = c.net, a_name = c.kod_BTI};
                };
                var results1 = query1.ToList();
                this.comboBox3.DataSource    = results1;
                this.comboBox3.DisplayMember = "fio";
                this.comboBox3.ValueMember   = "id";
            }
            catch (EntitySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 14
0
        public void listen()
        {
            string ip_adr = "127.0.0.1";

            using (var context = new db_sqlceEntities())
            {
                try
                {
                    var opt = context.options.FirstOrDefault();
                    ip_adr = opt.ip_addr;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            /* IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
             * foreach (IPAddress ip in host.AddressList)
             * {
             *   if (ip.AddressFamily == AddressFamily.InterNetwork)
             *   {
             *       ip_adr = ip.ToString();
             *   }
             * }*/

            IPAddress localAddr = IPAddress.Parse(ip_adr);

            try
            {
                listener = new TcpListener(localAddr, port);
                listener.Start();
                while (is_active)
                {
                    Debug.WriteLine("HTTPServer listener thread start!");
                    TcpClient     s         = listener.AcceptTcpClient();
                    HttpProcessor processor = new HttpProcessor(s, this);
                    Thread        thread    = new Thread(new ThreadStart(processor.process));
                    thread.IsBackground = true;
                    thread.Start();
                    Thread.Sleep(1);
                }
                //listener.Stop();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MessageBox.Show("Указан неверный ip-адрес для сервера!");
            }
        }
Esempio n. 15
0
        public void LoadData()
        {
            var context = new db_sqlceEntities();

            try
            {
                var query = from c in context.owners
                            select c;
                var results = query.ToList();
                this.ownersBindingSource.DataSource = results;
            }
            catch (EntitySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 16
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (var context = new db_sqlceEntities())
            {
                try
                {
                    var war = context.warning_conditions.FirstOrDefault();
                    if (war != null)
                    {
                        war.gprs_sig_min           = float.Parse(this.gprs_sig_min.Text, CultureInfo.InvariantCulture.NumberFormat);
                        war.gprs_sig_max           = float.Parse(this.gprs_sig_max.Text, CultureInfo.InvariantCulture.NumberFormat);
                        war.gprs_mod_min           = float.Parse(this.gprs_mod_min.Text, CultureInfo.InvariantCulture.NumberFormat);
                        war.gprs_mod_max           = float.Parse(this.gprs_mod_max.Text, CultureInfo.InvariantCulture.NumberFormat);
                        war.controller_voltage_min = float.Parse(this.cont_min.Text, CultureInfo.InvariantCulture.NumberFormat);
                        war.controller_voltage_max = float.Parse(this.cont_max.Text, CultureInfo.InvariantCulture.NumberFormat);
                        context.SaveChanges();
                        this.Close();
                    }
                    else
                    {
                        var wr = new warning_conditions()
                        {
                            gprs_sig_min =
                                float.Parse(this.gprs_sig_min.Text, CultureInfo.InvariantCulture.NumberFormat),
                            gprs_sig_max =
                                float.Parse(this.gprs_sig_max.Text, CultureInfo.InvariantCulture.NumberFormat),
                            gprs_mod_min =
                                float.Parse(this.gprs_mod_min.Text, CultureInfo.InvariantCulture.NumberFormat),
                            gprs_mod_max =
                                float.Parse(this.gprs_mod_max.Text, CultureInfo.InvariantCulture.NumberFormat),
                            controller_voltage_min =
                                float.Parse(this.cont_min.Text, CultureInfo.InvariantCulture.NumberFormat),
                            controller_voltage_max =
                                float.Parse(this.cont_max.Text, CultureInfo.InvariantCulture.NumberFormat)
                        };
                        context.warning_conditions.Add(wr);
                        context.SaveChanges();

                        this.Close();
                    }
                }
                catch (EntitySqlException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Esempio n. 17
0
        private void tabControl1_Selected(object sender, TabControlEventArgs e)
        {
            if (this.tabControl1.SelectedTab == tabPage3)
            {
                var chart   = this.chart1;
                var context = new db_sqlceEntities();
                var cn      = listView1.Items[3].SubItems[1].Text;
                try
                {
                    var query = from c in context.package_iz
                                from p1 in context.impulse.Where(p => p.code == c.pw1).DefaultIfEmpty()
                                from p2 in context.impulse.Where(p => p.code == c.pw2).DefaultIfEmpty()
                                where (c.da >= dateTimePicker1.Value && c.da <= dateTimePicker2.Value) &&
                                (c.na.Equals(cn))

                                select  new
                    {
                        date = c.da,
                        // r1 = c.r1/100,// * c.pw1 / 1000,
                        //  r2 = c.r2/100 //* c.pw2 / 1000
                        r1 = (float)(c.r1 * p1.weight) / 1000,        // * c.pw1 / 1000,
                        r2 = (float)(c.r2 * p2.weight) / 1000,        //* c.pw2 / 1000
                    };



                    var results = query.ToList();
                    if (results.Count <= 0)
                    {
                        return;
                    }

                    chart.Series[1].XValueType = ChartValueType.DateTime;
                    chart.Series[1].YValueType = ChartValueType.Int64;
                    chart.Series[0].XValueType = ChartValueType.DateTime;
                    chart.Series[0].YValueType = ChartValueType.Int64;
                    chart.Series[1].Points.DataBindXY(results, "date", results, "r2");
                    chart.Series[0].Points.DataBindXY(results, "date", results, "r1");
                }
                catch (EntitySqlException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Esempio n. 18
0
        private void EditUnits_Load(object sender, EventArgs e)
        {
            var context = new db_sqlceEntities();

            try
            {
                var query = from c in context.units
                            select c;//new {c_name = c.name, c_ucost = c.net, a_name = c.kod_BTI};
                var results = query.ToList();
                this.unitsBindingSource.DataSource = results;
                //this.objects_placeBindingSource.Columns[0].Visible = false;
                // context.SaveChanges();
            }
            catch (EntitySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 19
0
 private void button1_Click(object sender, EventArgs e)
 {
     using (var context = new db_sqlceEntities())
     {
         var place = new objects_place()
         {
             name           = this.textBox1.Text,
             comment        = this.textBox4.Text,
             kod_BTI        = this.textBox2.Text,
             net_id         = (int?)this.comboBox2.SelectedValue,
             object_type_id = (int)this.comboBox1.SelectedValue
         };
         context.objects_place.Add(place);
         context.SaveChanges();
         _main.loadTree();
         this.Close();
     }
 }
Esempio n. 20
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (this.textBox1.Text != "")
     {
         using (var context = new db_sqlceEntities())
         {
             var objct = new object_type()
             {
                 name    = this.textBox1.Text,
                 comment = this.textBox2.Text
             };
             context.object_type.Add(objct);
             context.SaveChanges();
             mEditObjects.LoadData();
             this.Close();
         }
     }
 }
Esempio n. 21
0
        public void LoadData()
        {
            var context = new db_sqlceEntities();

            try
            {
                var query = from c in context.object_type
                            select c;//new {c_name = c.name, c_ucost = c.net, a_name = c.kod_BTI};
                var results = query.ToList();
                this.object_typeBindingSource.DataSource = results;
                //this.objects_placeBindingSource.Columns[0].Visible = false;
                // context.SaveChanges();
            }
            catch (EntitySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 22
0
        private void editOptions_Load(object sender, EventArgs e)
        {
            using (var context = new db_sqlceEntities())
            {
                try
                {
                    var opt = context.options.FirstOrDefault();
                    if (opt != null)
                    {
                        this.textBox1.Text        = opt.ip_addr;
                        this.textBox2.Text        = opt.ip_port.ToString();
                        this.textBox3.Text        = opt.pop_addr;
                        this.textBox4.Text        = opt.pop_port.ToString();
                        this.textBox5.Text        = opt.pop_mail;
                        this.textBox6.Text        = opt.pop_passwd;
                        this.checkBox3.Checked    = opt.pop_ssl;
                        this.textBox7.Text        = opt.ppu_mail;
                        this.numericUpDown1.Value = (decimal)opt.pop_int;
                        this.checkBox1.Checked    = opt.is_ip;
                        this.checkBox2.Checked    = opt.is_mail;
                        this.checkBox4.Checked    = (bool)opt.new_ip;
                        this.textBox8.Text        = opt.new_ip_addr;
                    }

                    /*else
                     * {
                     *  opt.ip_addr = "test";
                     *  context.options.Attach(opt);
                     *  context.Entry(opt).State = EntityState.Modified;
                     *  context.SaveChanges();
                     *  opt.ip_addr = "test";
                     *  opt.is_ip = false;
                     *  opt.is_mail = false;
                     *  context.options.Add(opt);
                     *  context.SaveChanges();
                     *
                     * }*/
                }
                catch (EntitySqlException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Esempio n. 23
0
 private void WarningConditions_Load(object sender, EventArgs e)
 {
     using (var context = new db_sqlceEntities())
     {
         try
         {
             var war = context.warning_conditions.FirstOrDefault();
             if (war != null)
             {
                 this.gprs_sig_min.Text = war.gprs_sig_min.ToString();
                 this.gprs_sig_max.Text = war.gprs_sig_max.ToString();
                 this.gprs_mod_min.Text = war.gprs_mod_min.ToString();
                 this.gprs_mod_max.Text = war.gprs_mod_max.ToString();
                 this.cont_min.Text     = war.controller_voltage_min.ToString();
                 this.cont_max.Text     = war.controller_voltage_max.ToString();
             }
         }
         catch (EntitySqlException ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
Esempio n. 24
0
        public override void handleGETRequest(HttpProcessor p)
        {
            using (var context = new db_sqlceEntities())
            {
                try
                {
                    var opt = context.options.FirstOrDefault();
                    if (opt.new_ip)
                    {
                        Console.WriteLine("request: {0}", p.http_url);
                        p.writeSuccess();
                        p.outputStream.WriteLine("T##" + DateTime.Now.ToString("yyMMddHHmm") + "YIP=" + opt.new_ip_addr);
                    }
                    else
                    {
                        Console.WriteLine("request: {0}", p.http_url);
                        p.writeSuccess();
                        p.outputStream.Write("T##" + DateTime.Now.ToString("yyMMddHHmm"));
                    }
                }
                catch (SqlCeException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }


            /*p.writeSuccess();
             * p.outputStream.WriteLine("<html><body><h1>test server</h1>");
             * p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString());
             * p.outputStream.WriteLine("url : {0}", p.http_url);*/

            /*   p.outputStream.WriteLine("<form method=post action=/form>");
             * p.outputStream.WriteLine("<input type=text name=foo value=foovalue>");
             * p.outputStream.WriteLine("<input type=submit name=bar value=barvalue>");
             * p.outputStream.WriteLine("</form>");*/
        }
Esempio n. 25
0
        /* public MailService(string pop3s, int pop3p, bool ssl, string m, string pass, string mailppu)
         * {
         *  this.pop3_server = pop3s;
         *  this.pop3_port = pop3p;
         *  this.use_ssl = ssl;
         *  this.mail = m;
         *  this.passwd = pass;
         *  this.mail_ppu = mailppu;
         * // "pop.mail.ru", 995, true, "*****@*****.**", "dontask_mewhy", "*****@*****.**"
         * }*/

        public void StartMailService()
        {
            using (var context = new db_sqlceEntities())
            {
                try
                {
                    var opt = context.options.FirstOrDefault();
                    if (opt != null && opt.is_mail == true)
                    {
                        this.pop3_server = opt.pop_addr;
                        this.pop3_port   = (int)opt.pop_port;
                        this.use_ssl     = opt.pop_ssl;
                        this.mail        = opt.pop_mail;
                        this.passwd      = opt.pop_passwd;
                        this.mail_ppu    = opt.ppu_mail;

                        if (timer != null)
                        {
                            return;
                        }
                        timer = new Timer {
                            Interval = (double)(opt.pop_int * 60000)
                        };

                        timer.Elapsed += timerElapsed;
                        timer.Start();

                        Debug.WriteLine("MailService Started: " + DateTime.Now.TimeOfDay);
                    }
                }
                catch (SqlCeException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Esempio n. 26
0
        private void treeView1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                contextMenuStrip1.Show(Cursor.Position);
                TreeNode tn = treeView1.GetNodeAt(e.X, e.Y);

                if (tn == null)
                {
                    treeView1.SelectedNode             = treeView1.TopNode;
                    contextMenuStrip1.Items[1].Enabled = false;
                    contextMenuStrip1.Items[2].Enabled = false;
                    contextMenuStrip1.Items[4].Enabled = false;
                }
                else
                {
                    treeView1.SelectedNode             = tn;
                    _treeNodeId                        = Convert.ToInt32(treeView1.SelectedNode.Name);
                    _treeNodeName                      = treeView1.SelectedNode.Text;
                    contextMenuStrip1.Items[1].Enabled = true;
                    contextMenuStrip1.Items[2].Enabled = true;
                    contextMenuStrip1.Items[4].Enabled = true;
                }


                // MessageBox.Show(treeView1.SelectedNode.FullPath);
            }

            if (e.Button == MouseButtons.Left)
            {
                TreeNode tn = treeView1.GetNodeAt(e.X, e.Y);


                if (tn != null)
                {
                    // MessageBox.Show(tn.Name+ " " + tn.Text + " " + tn.Tag);
                    treeView1.SelectedNode = tn;
                    var nodeID = Convert.ToInt32(treeView1.SelectedNode.Name);
                    _treeNodeId   = Convert.ToInt32(treeView1.SelectedNode.Name);
                    _treeNodeName = treeView1.SelectedNode.Text;
                    using (var context = new db_sqlceEntities())
                    {
                        var query1 = from c in context.objects_place

                                     /*join o in context.owners on c.owner_id equals o.id
                                      * join cou in context.counters on c.id equals cou.objects_place_id
                                      * where c.id == nodeID
                                      * select new
                                      *     {
                                      *         fio = o.surname + " " + o.name + " " + o.patronymic,
                                      *         o.tel, counter = cou.serial_amspi, sn1 = cou.serial_r1, sn2 = cou.serial_r2
                                      *     };*/

                                     from cou in context.counters.Where(cou => cou.objects_place_id == c.id).DefaultIfEmpty()
                                     from o in context.owners.Where(o => o.id == c.owner_id)
                                     where c.id == nodeID
                                     select new
                        {
                            fio = o.surname + " " + o.name + " " + o.patronymic,
                            o.tel,
                            counter = cou.serial_amspi,
                            sn1     = cou.serial_r1,
                            sn2     = cou.serial_r2
                        };
                        var rr = query1.ToList();
                        if (rr.LongCount() > 0)
                        {
                            this.listView1.Items[0].SubItems[1].Text = rr.First().fio;
                            this.listView1.Items[1].SubItems[1].Text = rr.First().tel;
                            this.listView1.Items[2].SubItems[1].Text = FindRootNode(treeView1.SelectedNode).Text;
                            this.listView1.Items[3].SubItems[1].Text = rr.First().counter;
                            this.listView1.Items[4].SubItems[1].Text = rr.First().sn1;
                            this.listView1.Items[5].SubItems[1].Text = rr.First().sn2;
                        }
                        else
                        {
                            this.listView1.Items[0].SubItems[1].Text = "";
                            this.listView1.Items[1].SubItems[1].Text = "";
                            this.listView1.Items[2].SubItems[1].Text = "";
                            this.listView1.Items[3].SubItems[1].Text = "";
                            this.listView1.Items[4].SubItems[1].Text = "";
                            this.listView1.Items[5].SubItems[1].Text = "";
                        }
                    }
                }
                else
                {
                    if (treeView1.TopNode != null)
                    {
                        treeView1.SelectedNode = treeView1.TopNode;
                    }
                }
            }
            this.groupBox2.Text = treeView1.SelectedNode.Text;

            updateDataPackagesGrid();
            updateAlarmPackageGrid();
        }
Esempio n. 27
0
        private void LoadMassagesInDb(Message message, Pop3Client client, int i_msg)
        {
            string[] separator = new string[] { "\r\n", "\n" };

            MessageHeader  headers = client.GetMessageHeaders(i_msg);
            RfcMailAddress from    = headers.From;


            if (from.HasValidMailAddress && from.Address.Equals(this.mail_ppu))
            {
                if (message.Headers.Subject.Contains("_TEST"))
                {
                    Debug.WriteLine("MAIL_TS");
                    var mail_strings =
                        message.FindFirstPlainTextVersion()
                        .GetBodyAsText()
                        .Split(separator, StringSplitOptions.RemoveEmptyEntries)
                        .Select(s => s.Split(new[] { '=' }));

                    Dictionary <string, string> dict = new Dictionary <string, string>();
                    foreach (var item in mail_strings)
                    {
                        dict.Add(item[0], item[1]);
                    }

                    using (var context = new db_sqlceEntities())
                    {
                        try
                        {
                            var package_ts = new package_ts()
                            {
                                pt            = "/home/ts",
                                na            = dict["na"],
                                r1            = Convert.ToInt32(dict["r1"]),
                                r2            = Convert.ToInt32(dict["r2"]),
                                pw1           = Convert.ToInt32(dict["pw1"]),
                                pw2           = Convert.ToInt32(dict["pw2"]),
                                gp            = Convert.ToInt32(dict["gp"]),
                                te            = Convert.ToInt32(dict["te"]),
                                vc            = Convert.ToInt32(dict["vc"]),
                                vg            = Convert.ToInt32(dict["vg"]),
                                ti            = Convert.ToInt32(dict["ti"]),
                                sn1           = dict["sn1"],
                                sn2           = dict["sn2"],
                                mail_uid      = client.GetMessageUid(i_msg),
                                ismail        = true,
                                da            = DateTime.ParseExact(dict["da"], "yyMMdd", null).Date,
                                date_time_inc = DateTime.Now
                            };
                            context.package_ts.Add(package_ts);
                            context.SaveChanges();
                        }

                        catch (DbEntityValidationException ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                    log.Write(message.FindFirstPlainTextVersion()
                              .GetBodyAsText());
                }

                if (message.Headers.Subject.Contains("_TM"))
                {
                    Debug.WriteLine("MAIL_TM");
                    var mail_strings =
                        message.FindFirstPlainTextVersion()
                        .GetBodyAsText()
                        .Split(separator, StringSplitOptions.RemoveEmptyEntries)
                        .Select(s => s.Split(new[] { '=' }));

                    Dictionary <string, string> dict = new Dictionary <string, string>();
                    foreach (var item in mail_strings)
                    {
                        dict.Add(item[0], item[1]);
                    }

                    using (var context = new db_sqlceEntities())
                    {
                        try
                        {
                            var package_tm = new package_tm()
                            {
                                pt       = "/home/tm",
                                na       = dict["na"],
                                ismail   = true,
                                mail_uid = client.GetMessageUid(i_msg),
                                date_inc = DateTime.Now
                            };
                            context.package_tm.Add(package_tm);
                            context.SaveChanges();
                        }

                        catch (DbEntityValidationException ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                }

                if (message.Headers.Subject.Contains("_ON"))
                {
                    Debug.WriteLine("MAIL_ON");

                    var mail_strings =
                        message.FindFirstPlainTextVersion()
                        .GetBodyAsText()
                        .Trim()
                        .Split(separator, StringSplitOptions.RemoveEmptyEntries)
                        .Select(s => s.Split(new[] { '=' }));

                    Dictionary <string, string> dict = new Dictionary <string, string>();
                    foreach (var item in mail_strings)
                    {
                        dict.Add(item[0], item[1]);
                    }

                    using (var context = new db_sqlceEntities())
                    {
                        try
                        {
                            var package_on = new package_on()
                            {
                                pt            = "/home/on",
                                na            = dict["na"],
                                r1            = Convert.ToInt32(dict["r1"]),
                                r2            = Convert.ToInt32(dict["r2"]),
                                pw1           = Convert.ToInt32(dict["pw1"]),
                                pw2           = Convert.ToInt32(dict["pw2"]),
                                gp            = Convert.ToInt32(dict["gp"]),
                                te            = Convert.ToInt32(dict["te"]),
                                vc            = Convert.ToInt32(dict["vc"]),
                                vg            = Convert.ToInt32(dict["vg"]),
                                ti            = Convert.ToInt32(dict["ti"]),
                                sn1           = dict["sn1"],
                                sn2           = dict["sn2"],
                                mail_uid      = client.GetMessageUid(i_msg),
                                ismail        = true,
                                da            = DateTime.ParseExact(dict["da"], "yyMMdd", null).Date,
                                date_time_inc = DateTime.Now
                            };
                            context.package_on.Add(package_on);
                            context.SaveChanges();
                        }

                        catch (DbEntityValidationException ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                    log.Write(message.FindFirstPlainTextVersion()
                              .GetBodyAsText());
                }

                if (message.Headers.Subject.Contains("_AL"))
                {
                    Debug.WriteLine("MAIL_AL");
                    var mail_strings =
                        message.FindFirstPlainTextVersion()
                        .GetBodyAsText()
                        .Split(separator, StringSplitOptions.RemoveEmptyEntries)
                        .Select(s => s.Split(new[] { '=' }));

                    Dictionary <string, string> dict = new Dictionary <string, string>();
                    foreach (var item in mail_strings)
                    {
                        dict.Add(item[0], item[1]);
                    }

                    var wr_txt = "";
                    var war    = Convert.ToInt32(dict["w"]);
                    switch (war)
                    {
                    case (0):
                        wr_txt = "Вскрыте крышки!";
                        break;

                    case (1):
                        wr_txt = "Расход за час для первого счетчика больше предельного!";
                        break;

                    case (2):
                        wr_txt = "Расход за час для второго счетчика больше предельного!";
                        break;
                    }

                    using (var context = new db_sqlceEntities())
                    {
                        try
                        {
                            var package_al = new package_al()
                            {
                                pt       = "/home/wr",
                                na       = dict["na"],
                                wr       = war,
                                date_inc = DateTime.Now,
                                ismail   = true,
                                mail_uid = client.GetMessageUid(i_msg),
                                wr_txt   = wr_txt
                            };
                            context.package_al.Add(package_al);
                            context.SaveChanges();
                        }

                        catch (DbEntityValidationException ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                }

                if (message.Headers.Subject.Contains("_Data"))
                {
                    Debug.WriteLine("MAIL_IZ");
                    var mail_strings =
                        message.FindFirstPlainTextVersion()
                        .GetBodyAsText()
                        .Trim()
                        .Split(separator, StringSplitOptions.RemoveEmptyEntries)
                        .Select(s => s.Split(new[] { '=' }));
                    Dictionary <string, string> dict = mail_strings.ToDictionary(item => item[0], item => item[1]);



                    using (var context = new db_sqlceEntities())
                    {
                        try
                        {
                            string rw_1 = dict["r1"].Substring(0, 8);
                            string rw_2 = dict["r2"].Substring(0, 8);

                            string r1 = dict["r1"].Substring(8, 96);
                            string r2 = dict["r2"].Substring(8, 96);

                            // r1 = r1.Replace('g', '0');
                            // r2 = r2.Replace('g', '0');



                            r1 = Regex.Replace(r1, @"([^0-9])(\d){3}", "0000");
                            r2 = Regex.Replace(r2, @"([^0-9])(\d){3}", "0000");
                            IEnumerable <string> groups1 = Enumerable.Range(0, r1.Length / 4)
                                                           .Select(i => r1.Substring(i * 4, 4));
                            List <int> rw1 = new List <int>();
                            foreach (var grp in groups1)
                            {
                                rw1.Add(Convert.ToInt32(grp));
                            }

                            IEnumerable <string> groups2 = Enumerable.Range(0, r2.Length / 4)
                                                           .Select(i => r2.Substring(i * 4, 4));
                            List <int> rw2 = new List <int>();
                            foreach (var grp in groups2)
                            {
                                rw2.Add(Convert.ToInt32(grp));
                            }

                            string ppu_na = null;
                            if (!string.IsNullOrEmpty(dict["na"]))
                            {
                                ppu_na = dict["na"];
                            }
                            var package_iz = new package_iz()
                            {
                                pt    = "/home/iz",
                                na    = dict["na"],
                                r1    = Convert.ToInt32(rw_1),
                                r1_0  = Convert.ToInt32(groups1.ElementAt(0)),
                                r1_1  = Convert.ToInt32(groups1.ElementAt(1)),
                                r1_2  = Convert.ToInt32(groups1.ElementAt(2)),
                                r1_3  = Convert.ToInt32(groups1.ElementAt(3)),
                                r1_4  = Convert.ToInt32(groups1.ElementAt(4)),
                                r1_5  = Convert.ToInt32(groups1.ElementAt(5)),
                                r1_6  = Convert.ToInt32(groups1.ElementAt(6)),
                                r1_7  = Convert.ToInt32(groups1.ElementAt(7)),
                                r1_8  = Convert.ToInt32(groups1.ElementAt(8)),
                                r1_9  = Convert.ToInt32(groups1.ElementAt(9)),
                                r1_10 = Convert.ToInt32(groups1.ElementAt(10)),
                                r1_11 = Convert.ToInt32(groups1.ElementAt(11)),
                                r1_12 = Convert.ToInt32(groups1.ElementAt(12)),
                                r1_13 = Convert.ToInt32(groups1.ElementAt(13)),
                                r1_14 = Convert.ToInt32(groups1.ElementAt(14)),
                                r1_15 = Convert.ToInt32(groups1.ElementAt(15)),
                                r1_16 = Convert.ToInt32(groups1.ElementAt(16)),
                                r1_17 = Convert.ToInt32(groups1.ElementAt(17)),
                                r1_18 = Convert.ToInt32(groups1.ElementAt(18)),
                                r1_19 = Convert.ToInt32(groups1.ElementAt(19)),
                                r1_20 = Convert.ToInt32(groups1.ElementAt(20)),
                                r1_21 = Convert.ToInt32(groups1.ElementAt(21)),
                                r1_22 = Convert.ToInt32(groups1.ElementAt(22)),
                                r1_23 = Convert.ToInt32(groups1.ElementAt(23)),
                                // r1_24 = Convert.ToInt32(groups1.ElementAt(24)),

                                r2    = Convert.ToInt32(rw_2),
                                r2_0  = Convert.ToInt32(groups2.ElementAt(0)),
                                r2_1  = Convert.ToInt32(groups2.ElementAt(1)),
                                r2_2  = Convert.ToInt32(groups2.ElementAt(2)),
                                r2_3  = Convert.ToInt32(groups2.ElementAt(3)),
                                r2_4  = Convert.ToInt32(groups2.ElementAt(4)),
                                r2_5  = Convert.ToInt32(groups2.ElementAt(5)),
                                r2_6  = Convert.ToInt32(groups2.ElementAt(6)),
                                r2_7  = Convert.ToInt32(groups2.ElementAt(7)),
                                r2_8  = Convert.ToInt32(groups2.ElementAt(8)),
                                r2_9  = Convert.ToInt32(groups2.ElementAt(9)),
                                r2_10 = Convert.ToInt32(groups2.ElementAt(10)),
                                r2_11 = Convert.ToInt32(groups2.ElementAt(11)),
                                r2_12 = Convert.ToInt32(groups2.ElementAt(12)),
                                r2_13 = Convert.ToInt32(groups2.ElementAt(13)),
                                r2_14 = Convert.ToInt32(groups2.ElementAt(14)),
                                r2_15 = Convert.ToInt32(groups2.ElementAt(15)),
                                r2_16 = Convert.ToInt32(groups2.ElementAt(16)),
                                r2_17 = Convert.ToInt32(groups2.ElementAt(17)),
                                r2_18 = Convert.ToInt32(groups2.ElementAt(18)),
                                r2_19 = Convert.ToInt32(groups2.ElementAt(19)),
                                r2_20 = Convert.ToInt32(groups2.ElementAt(20)),
                                r2_21 = Convert.ToInt32(groups2.ElementAt(21)),
                                r2_22 = Convert.ToInt32(groups2.ElementAt(22)),
                                r2_23 = Convert.ToInt32(groups2.ElementAt(23)),
                                //r2_24 = Convert.ToInt32(groups2.ElementAt(24)),

                                pw1      = Convert.ToInt32(dict["pw1"]),
                                pw2      = Convert.ToInt32(dict["pw2"]),
                                gp       = Convert.ToInt32(dict["gp"]),
                                te       = dict["te"],
                                vc       = Convert.ToInt32(dict["vc"]),
                                vg       = Convert.ToInt32(dict["vg"]),
                                ti       = Convert.ToInt32(dict["ti"]),
                                sn1      = dict["sn1"],
                                sn2      = dict["sn2"],
                                da       = DateTime.ParseExact(dict["da"], "yyMMdd", null).Date,
                                ismail   = true,
                                mail_uid = client.GetMessageUid(i_msg),
                                date_inc = DateTime.Now
                            };
                            context.package_iz.Add(package_iz);
                            context.SaveChanges();

                            var qu = context.counters.FirstOrDefault(c => c.serial_amspi == ppu_na);

                            if (qu != null)
                            {
                                qu.serial_r1 = dict["sn1"];
                                qu.serial_r2 = dict["sn2"];
                                context.SaveChanges();
                            }
                        }

                        catch (DbEntityValidationException ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                    log.Write(message.FindFirstPlainTextVersion()
                              .GetBodyAsText());
                }
            }
        }
Esempio n. 28
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (validateFields())
            {
                using (var context = new db_sqlceEntities())
                {
                    try
                    {
                        var opt = context.options.FirstOrDefault();
                        if (opt != null)
                        {
                            opt.ip_addr     = this.textBox1.Text;
                            opt.ip_port     = Convert.ToInt32(this.textBox2.Text);
                            opt.pop_addr    = this.textBox3.Text.Trim();
                            opt.pop_port    = Convert.ToInt32(this.textBox4.Text);
                            opt.pop_mail    = this.textBox5.Text.Trim();;
                            opt.pop_passwd  = this.textBox6.Text.Trim();
                            opt.pop_ssl     = this.checkBox3.Checked;
                            opt.ppu_mail    = this.textBox7.Text.Trim();
                            opt.pop_int     = Convert.ToInt32(this.numericUpDown1.Value);
                            opt.is_ip       = this.checkBox1.Checked;
                            opt.is_mail     = this.checkBox2.Checked;
                            opt.new_ip      = checkBox4.Checked;
                            opt.new_ip_addr = this.textBox8.Text;

                            context.SaveChanges();
                            this.Close();
                        }

                        else
                        {
                            var opti = new options()
                            {
                                ip_addr     = this.textBox1.Text,
                                ip_port     = Convert.ToInt32(this.textBox2.Text),
                                pop_addr    = this.textBox3.Text,
                                pop_port    = Convert.ToInt32(this.textBox4.Text),
                                pop_mail    = this.textBox5.Text,
                                pop_passwd  = this.textBox6.Text,
                                pop_ssl     = this.checkBox3.Checked,
                                ppu_mail    = this.textBox7.Text,
                                pop_int     = Convert.ToInt32(this.numericUpDown1.Value),
                                is_ip       = this.checkBox1.Checked,
                                is_mail     = this.checkBox2.Checked,
                                new_ip      = checkBox4.Checked,
                                new_ip_addr = this.textBox8.Text
                            };

                            context.options.Add(opti);
                            context.SaveChanges();

                            this.Close();
                        }
                        MailService();
                    }
                    catch (EntitySqlException ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }
Esempio n. 29
0
        private void warningDelegate()
        {
            var context = new db_sqlceEntities();

            try
            {
                var w_query = context.warning_conditions.FirstOrDefault();

                var tr    = DateTime.Now.AddMonths(-1);
                var ttr   = DateTime.Now;
                var query = from c in context.package_iz
                            where ((c.date_inc >= tr && c.date_inc <= ttr) &&
                                   (c.vg <w_query.gprs_mod_min || c.vg> w_query.gprs_mod_max || c.gp <w_query.gprs_sig_min || c.gp> w_query.gprs_sig_max || c.vc <w_query.controller_voltage_min || c.vc> w_query.controller_voltage_max))

                            select new
                {
                    na = c.na,
                    vc = c.vc,
                    vg = c.vg,
                    gp = c.gp
                };

                var           results = query.ToList();
                List <string> lst     = new List <string>();
                foreach (var item in results)
                {
                    string txt_gp_max;
                    string txt_gp_min;
                    string txt_vg_max;
                    string txt_vg_min;
                    string txt_ct_min;
                    string txt_ct_max;
                    if (item.vg > w_query.gprs_mod_max)
                    {
                        txt_vg_max = "ППУ-РМ № " + item.na + " Напряжение GPRS модуля превышено!"; lst.Add(txt_vg_max);
                    }
                    if (item.vg < w_query.gprs_mod_min)
                    {
                        txt_vg_min = "ППУ-РМ № " + item.na + " Напряжение GPRS модуля ниже нормы!"; lst.Add(txt_vg_min);
                    }
                    if (item.gp < w_query.gprs_sig_min)
                    {
                        txt_gp_min = "ППУ-РМ № " + item.na + " Уровень GPRS сиграла ниже нормы!"; lst.Add(txt_gp_min);
                    }
                    if (item.gp > w_query.gprs_sig_max)
                    {
                        txt_gp_max = "ППУ-РМ № " + item.na + " Уровень GPRS сиграла превышен!"; lst.Add(txt_gp_max);
                    }
                    if (item.vc < w_query.controller_voltage_min)
                    {
                        txt_ct_min = "ППУ-РМ № " + item.na + " Напряжение контроллера ниже нормы!"; lst.Add(txt_ct_min);
                    }
                    if (item.vc > w_query.controller_voltage_max)
                    {
                        txt_ct_max = "ППУ-РМ № " + item.na + " Напряжение контроллера превышено!"; lst.Add(txt_ct_max);
                    }
                }

                listBox1.Items.Clear();
                listBox1.Items.AddRange(lst.ToArray());
                listBox1.Update();
                lst.Clear();
            }
            catch (SqlCeException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 30
0
        public void parseRequest()
        {
            String request = streamReadLine(inputStream);

            string[] tokens = request.Split(' ');
            if (tokens.Length != 3)
            {
                throw new Exception("invalid http request line");
            }
            http_method = tokens[0].ToUpper();
            http_url    = tokens[1];
            http_protocol_versionstring = tokens[2];


            var    spaceIndex = http_url.IndexOf("%20", System.StringComparison.Ordinal);
            string s;

            s = spaceIndex != -1 ? http_url.Substring(0, spaceIndex) : http_url;

            var url      = new Uri("http://www.example.com" + s);
            var url_path = url.AbsolutePath;
            NameValueCollection qscollection = HttpUtility.ParseQueryString(url.Query);
            string ppu_na = null;

            if (!string.IsNullOrEmpty(qscollection["na"]))
            {
                ppu_na = qscollection["na"];
            }
            //var pac = qscollection.Get(0).ToLower();

            /* switch (qscollection.Get(0))
             * {*/
            if (url_path.IndexOf("/home/ts") > -1)
            {
                Debug.WriteLine("ts");
                using (var context = new db_sqlceEntities())
                {
                    try
                    {
                        var package_ts = new package_ts()
                        {
                            pt            = url_path,
                            na            = qscollection["na"],
                            r1            = Convert.ToInt32(qscollection["r1"]),
                            r2            = Convert.ToInt32(qscollection["r2"]),
                            pw1           = Convert.ToInt32(qscollection["pw1"]),
                            pw2           = Convert.ToInt32(qscollection["pw2"]),
                            gp            = Convert.ToInt32(qscollection["gp"]),
                            te            = Convert.ToInt32(qscollection["te"]),
                            vc            = Convert.ToInt32(qscollection["vc"]),
                            vg            = Convert.ToInt32(qscollection["vg"]),
                            ti            = Convert.ToInt32(qscollection["ti"]),
                            sn1           = qscollection["sn1"],
                            sn2           = qscollection["sn2"],
                            ismail        = false,
                            da            = DateTime.ParseExact(qscollection["da"], "yyMMdd", null).Date,
                            date_time_inc = DateTime.Now
                        };
                        context.package_ts.Add(package_ts);
                        context.SaveChanges();
                    }

                    catch (DbEntityValidationException ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            }

            if (url_path.IndexOf("/home/iz") > -1)
            {
                Debug.WriteLine("iz");

                using (var context = new db_sqlceEntities())
                {
                    try
                    {
                        string rw_1 = qscollection["r1"].Substring(0, 8);
                        string rw_2 = qscollection["r2"].Substring(0, 8);

                        string r1 = qscollection["r1"].Substring(8, 96);
                        string r2 = qscollection["r2"].Substring(8, 96);

                        IEnumerable <string> groups1 = Enumerable.Range(0, r1.Length / 4)
                                                       .Select(i => r1.Substring(i * 4, 4));
                        List <int> rw1 = new List <int>();
                        foreach (var grp in groups1)
                        {
                            rw1.Add(Convert.ToInt32(grp));
                        }

                        IEnumerable <string> groups2 = Enumerable.Range(0, r2.Length / 4)
                                                       .Select(i => r2.Substring(i * 4, 4));
                        List <int> rw2 = new List <int>();
                        foreach (var grp in groups2)
                        {
                            rw2.Add(Convert.ToInt32(grp));
                        }

                        var package_iz = new package_iz()
                        {
                            pt    = url_path,
                            na    = qscollection["na"],
                            r1    = Convert.ToInt32(rw_1),
                            r1_0  = Convert.ToInt32(groups1.ElementAt(0)),
                            r1_1  = Convert.ToInt32(groups1.ElementAt(1)),
                            r1_2  = Convert.ToInt32(groups1.ElementAt(2)),
                            r1_3  = Convert.ToInt32(groups1.ElementAt(3)),
                            r1_4  = Convert.ToInt32(groups1.ElementAt(4)),
                            r1_5  = Convert.ToInt32(groups1.ElementAt(5)),
                            r1_6  = Convert.ToInt32(groups1.ElementAt(6)),
                            r1_7  = Convert.ToInt32(groups1.ElementAt(7)),
                            r1_8  = Convert.ToInt32(groups1.ElementAt(8)),
                            r1_9  = Convert.ToInt32(groups1.ElementAt(9)),
                            r1_10 = Convert.ToInt32(groups1.ElementAt(10)),
                            r1_11 = Convert.ToInt32(groups1.ElementAt(11)),
                            r1_12 = Convert.ToInt32(groups1.ElementAt(12)),
                            r1_13 = Convert.ToInt32(groups1.ElementAt(13)),
                            r1_14 = Convert.ToInt32(groups1.ElementAt(14)),
                            r1_15 = Convert.ToInt32(groups1.ElementAt(15)),
                            r1_16 = Convert.ToInt32(groups1.ElementAt(16)),
                            r1_17 = Convert.ToInt32(groups1.ElementAt(17)),
                            r1_18 = Convert.ToInt32(groups1.ElementAt(18)),
                            r1_19 = Convert.ToInt32(groups1.ElementAt(19)),
                            r1_20 = Convert.ToInt32(groups1.ElementAt(20)),
                            r1_21 = Convert.ToInt32(groups1.ElementAt(21)),
                            r1_22 = Convert.ToInt32(groups1.ElementAt(22)),
                            r1_23 = Convert.ToInt32(groups1.ElementAt(23)),
                            // r1_24 = Convert.ToInt32(groups1.ElementAt(24)),

                            r2    = Convert.ToInt32(rw_2),
                            r2_0  = Convert.ToInt32(groups2.ElementAt(0)),
                            r2_1  = Convert.ToInt32(groups2.ElementAt(1)),
                            r2_2  = Convert.ToInt32(groups2.ElementAt(2)),
                            r2_3  = Convert.ToInt32(groups2.ElementAt(3)),
                            r2_4  = Convert.ToInt32(groups2.ElementAt(4)),
                            r2_5  = Convert.ToInt32(groups2.ElementAt(5)),
                            r2_6  = Convert.ToInt32(groups2.ElementAt(6)),
                            r2_7  = Convert.ToInt32(groups2.ElementAt(7)),
                            r2_8  = Convert.ToInt32(groups2.ElementAt(8)),
                            r2_9  = Convert.ToInt32(groups2.ElementAt(9)),
                            r2_10 = Convert.ToInt32(groups2.ElementAt(10)),
                            r2_11 = Convert.ToInt32(groups2.ElementAt(11)),
                            r2_12 = Convert.ToInt32(groups2.ElementAt(12)),
                            r2_13 = Convert.ToInt32(groups2.ElementAt(13)),
                            r2_14 = Convert.ToInt32(groups2.ElementAt(14)),
                            r2_15 = Convert.ToInt32(groups2.ElementAt(15)),
                            r2_16 = Convert.ToInt32(groups2.ElementAt(16)),
                            r2_17 = Convert.ToInt32(groups2.ElementAt(17)),
                            r2_18 = Convert.ToInt32(groups2.ElementAt(18)),
                            r2_19 = Convert.ToInt32(groups2.ElementAt(19)),
                            r2_20 = Convert.ToInt32(groups2.ElementAt(20)),
                            r2_21 = Convert.ToInt32(groups2.ElementAt(21)),
                            r2_22 = Convert.ToInt32(groups2.ElementAt(22)),
                            r2_23 = Convert.ToInt32(groups2.ElementAt(23)),
                            //r2_24 = Convert.ToInt32(groups2.ElementAt(24)),

                            pw1      = Convert.ToInt32(qscollection["pw1"]),
                            pw2      = Convert.ToInt32(qscollection["pw2"]),
                            gp       = Convert.ToInt32(qscollection["gp"]),
                            te       = qscollection["te"],
                            vc       = Convert.ToInt32(qscollection["vc"]),
                            vg       = Convert.ToInt32(qscollection["vg"]),
                            ti       = Convert.ToInt32(qscollection["ti"]),
                            sn1      = qscollection["sn1"],
                            sn2      = qscollection["sn2"],
                            ismail   = false,
                            da       = DateTime.ParseExact(qscollection["da"], "yyMMdd", null).Date,
                            date_inc = DateTime.Now
                        };
                        context.package_iz.Add(package_iz);
                        context.SaveChanges();

                        var que = context.counters.FirstOrDefault(c => c.serial_amspi == ppu_na);

                        if (que != null)
                        {
                            que.serial_r1 = qscollection["sn1"];
                            que.serial_r2 = qscollection["sn2"];
                            context.SaveChanges();
                        }
                    }

                    catch (DbEntityValidationException ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            }
            if (url_path.IndexOf("/home/tm") > -1)
            {
                Debug.WriteLine("tm");
                using (var context = new db_sqlceEntities())
                {
                    try
                    {
                        var package_tm = new package_tm()
                        {
                            pt       = url_path,
                            na       = qscollection["na"],
                            ismail   = false,
                            date_inc = DateTime.Now
                        };
                        context.package_tm.Add(package_tm);
                        context.SaveChanges();
                    }

                    catch (DbEntityValidationException ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            }
            if (url_path.IndexOf("/home/on") > -1)
            {
                Debug.WriteLine("on");
                using (var context = new db_sqlceEntities())
                {
                    try
                    {
                        var package_on = new package_on()
                        {
                            pt            = url_path,
                            na            = qscollection["na"],
                            r1            = Convert.ToInt32(qscollection["r1"]),
                            r2            = Convert.ToInt32(qscollection["r2"]),
                            pw1           = Convert.ToInt32(qscollection["pw1"]),
                            pw2           = Convert.ToInt32(qscollection["pw2"]),
                            gp            = Convert.ToInt32(qscollection["gp"]),
                            te            = Convert.ToInt32(qscollection["te"]),
                            vc            = Convert.ToInt32(qscollection["vc"]),
                            vg            = Convert.ToInt32(qscollection["vg"]),
                            ti            = Convert.ToInt32(qscollection["ti"]),
                            sn1           = qscollection["sn1"],
                            sn2           = qscollection["sn2"],
                            ismail        = false,
                            da            = DateTime.ParseExact(qscollection["da"], "yyMMdd", null).Date,
                            date_time_inc = DateTime.Now
                        };
                        context.package_on.Add(package_on);
                        context.SaveChanges();
                    }

                    catch (DbEntityValidationException ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            }
            if (url_path.IndexOf("/home/al") > -1)
            {
                Debug.WriteLine("al");
                var wr_txt = "";
                var war    = Convert.ToInt32(qscollection.Get(2));
                switch (war)
                {
                case (0):
                    wr_txt = "Вскрыте крышки!";
                    break;

                case (1):
                    wr_txt = "Расход за час для первого счетчика больше предельного!";
                    break;

                case (2):
                    wr_txt = "Расход за час для второго счетчика больше предельного!";
                    break;
                }

                using (var context = new db_sqlceEntities())
                {
                    try
                    {
                        var package_al = new package_al()
                        {
                            pt       = url_path,
                            na       = qscollection["na"],
                            wr       = war,
                            date_inc = DateTime.Now,
                            ismail   = false,
                            wr_txt   = wr_txt
                        };
                        context.package_al.Add(package_al);
                        context.SaveChanges();

                        var query1 = from c in context.objects_place
                                     from cou in context.counters.Where(cou => cou.objects_place_id == c.id).DefaultIfEmpty()
                                     where cou.serial_amspi == package_al.na
                                     select new
                        {
                            c.name
                        };
                        string rr = query1.FirstOrDefault().name;

                        MessageBox.Show("ППУ-РМ №: " + package_al.na + " " + rr + " - " + package_al.wr_txt, "АВАРИЯ!",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1,
                                        MessageBoxOptions.ServiceNotification);
                    }

                    catch (DbEntityValidationException ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            }


            log.Write(http_url);
        }