Ejemplo n.º 1
0
        public ActionResult AddMeter(Counter_model_add model_add)
        {
            //Test Autorize
            //if (!WebSecurity.IsAuthenticated)
            //    return RedirectToAction("Index", "Login");

            Counter meter = new Counter();

            meter.UserId = WebSecurity.CurrentUserId;
            if (model_add.Name == null)
            {
                Json("Введите название");
            }
            meter.Name = model_add.Name;
            if (model_add.Serial == null)
            {
                Json("Введите серийный номер");
            }
            meter.Serial = model_add.Serial;
            //if (model_add.Name == null) { Json("Введите название счетчика") }
            meter.Status = false;
            if (model_add.Type == 0)
            {
                Json("Выберите тип");
            }
            meter.Type = model_add.Type;
            if (model_add.Measure == null)
            {
                Json("Введите название счетчика");
            }
            meter.Measure = model_add.Measure;
            if (model_add.DateOfReview == null)
            {
                Json("Выберите дату проверки счетчика");
            }
            meter.DateOfReview = model_add.DateOfReview;


            if (ModelState.IsValid)
            {
                repository.SaveCounter(meter);
                //TempData["message"] = string.Format("Газовый счетчик успешно добавлен(обновлен)");
            }

            //int li = repository.context.Database.SqlQuery<int>("LAST_INSERT_ID()").FirstOrDefault();

            Counter_data model_data = new Counter_data();

            if (meter.id != 0)
            {
                model_data.data   = model_add.firstdata;
                model_data.write  = DateTime.UtcNow;
                model_data.status = false;
                model_data.id     = meter.id;
                repository.SaveCounder_data(model_data);
                return(Json("Ok"));
            }
            return(Json("Error"));
        }
Ejemplo n.º 2
0
        public ActionResult AddCounterMonthValue(int type = 0)
        {
            if (type == 0)
            {
                return(View("Error"));
            }
            Counter_data model;
            Counter      counter = repository.Counter.Where(u => u.UserId.Equals(WebSecurity.CurrentUserId)).Where(p => p.Type.Equals(type)).SingleOrDefault();

            model    = new Counter_data();
            model.id = counter.id;
            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult AddValueMeter(Counter_data model_data)
        {
            //int li = repository.context.Database.SqlQuery<int>("LAST_INSERT_ID()").FirstOrDefault();

            if (model_data.id != 0)
            {
                //  model_data.data = model_add.firstdata;
                model_data.write  = DateTime.UtcNow;
                model_data.status = false;
                //  model_data.id = meter.id;
                repository.SaveCounder_data(model_data);
                return(Json("Ok"));
            }
            return(Json("Error"));
        }
Ejemplo n.º 4
0
        public void SaveCounder_data(Counter_data cou)
        {
            DateTime            seek  = DateTime.Today;
            int                 month = seek.Month;
            int                 year  = seek.Year;
            List <Counter_data> temp  = context.Database.SqlQuery <Counter_data>("SELECT * FROM [dbo].[Counter_data] WHERE id = " + cou.id + " AND write >= '" + year + "." + month + ".01'", "").ToList();;

            if (temp.Count == 0)
            {
                context.SQLStringConnect("INSERT INTO [dbo].[Counter_data] ([id],[write],[data],[status]) VALUES    ( " + cou.id + "   , '" + cou.write + "' , '" + cou.data + "' , '" + cou.status + "') ");
            }
            else
            {
                context.SQLStringConnect("UPDATE [dbo].[Counter_data] SET write = '" + cou.write + "' , data = '" + cou.data + "' , status = '" + cou.status + "' WHERE id=" + cou.id + " AND write >= '" + year + "." + month + ".01'");
            }
        }
Ejemplo n.º 5
0
        public ActionResult ViewCounters(int month = 0, int year = 0)
        {
            IEnumerable <UserProfile> users = null;
            //To do add array of user's counters
            List <Counter_model>       model       = new List <Counter_model>();
            IEnumerable <Counter>      ListCounter = null;
            IEnumerable <Counter_data> ListData    = null;
            Admtszh admuser;
            string  requestDomain = Request.Headers["host"];

            try
            {
                admuser = repository.Admtszh.Where(p => p.AdmtszhId.Equals(WebSecurity.CurrentUserId)).SingleOrDefault();
                uk_profile uk = repository.uk_profile.Where(p => p.id.Equals(admuser.id_uk)).SingleOrDefault();
                users = repository.UserProfile.Where(p => p.id_uk.Equals(uk.id));
            }
            catch (Exception ex)
            {
                Log.Error(Request.ToString() + " User: "******"";
                foreach (var item in users)
                {
                    if (!u.Equals(""))
                    {
                        u = u + ",";
                    }
                    u = u + item.UserId.ToString();
                }
                ListCounter = context.Database.SqlQuery <Counter>("SELECT * FROM [dbo].[Counter] WHERE UserId IN  ( " + u + " )").ToArray(); //repository.Counter.Where(u => u.UserId.Equals(it.id)).Where(p => p.type.Equals(type));

                if (ListCounter.Count() != 0)
                {
                    string res = "";
                    foreach (var item in ListCounter)
                    {
                        if (!res.Equals(""))
                        {
                            res = res + ",";
                        }
                        res = res + item.id.ToString();
                    }
                    ListData = context.Database.SqlQuery <Counter_data>("SELECT * FROM [dbo].[Counter_data] WHERE id IN  ( " + res + " )").ToArray();
                }
                else
                {
                    ListData = new List <Counter_data>().ToArray();
                }
                uk_adress adr;
                foreach (var user in users)
                {
                    Counter_model temp = new Counter_model();
                    temp.Name = user.SurName + " " + user.Name;

                    adr         = context.uk_adresses.Where(pu => pu.id.Equals(user.Adress)).FirstOrDefault();
                    temp.street = adr.Street;
                    temp.house  = adr.House;
                    temp.flat   = user.Apartment;
                    if (year == 0)
                    {
                        year = DateTime.Now.Year;
                    }
                    if (month == 0)
                    {
                        month = DateTime.Now.Month;
                    }
                    DateTime d_start = new DateTime(year, month, 1);
                    DateTime d_end   = d_start.AddMonths(1);
                    bool     status  = true;

                    for (int j = 1; j <= 4; j++)
                    {
                        if (j == 1)
                        {
                            temp.gasi = new List <count_place>();
                        }
                        if (j == 2)
                        {
                            temp.energoi = new List <count_place>();
                        }
                        if (j == 3)
                        {
                            temp.cwi = new List <count_place>();
                        }
                        if (j == 4)
                        {
                            temp.hwi = new List <count_place>();
                        }

                        IEnumerable <Counter> counters = ListCounter.Where(p => p.UserId.Equals(user.UserId)).Where(t => t.Type.Equals(j));
                        foreach (Counter counter in counters)
                        {
                            Counter_data t_data = ListData.Where(m => m.id.Equals(counter.id)).Where(d => d.write >= d_start).Where(d => d.write < d_end).SingleOrDefault();
                            //                                foreach (var it in t_data)
                            if (t_data != null)
                            {
                                count_place cp = new count_place();
                                cp.id    = t_data.id;
                                cp.data  = t_data.data;
                                cp.place = ListCounter.Where(p => p.id.Equals(t_data.id)).FirstOrDefault().Name;
                                status   = t_data.status;

                                if (j == 1)
                                {
                                    temp.gasi.Add(cp);
                                }
                                if (j == 2)
                                {
                                    temp.energoi.Add(cp);
                                }
                                if (j == 3)
                                {
                                    temp.cwi.Add(cp);
                                }
                                if (j == 4)
                                {
                                    temp.hwi.Add(cp);
                                }
                                cp = null;
                            }
                        }
                    }


                    if ((temp.gasi.Count == 0) && (temp.energoi.Count == 0) && (temp.cwi.Count == 0) && (temp.hwi.Count == 0))
                    {
                        // temp = null;
                    }
                    else
                    {
                        temp.month  = d_start;
                        temp.status = status;
                        model.Add(temp);
                    }
                    temp = null;
                }
            }
            return(Json(model, JsonRequestBehavior.AllowGet));
        }