Esempio n. 1
0
        public void DeleteUsedInfo(int id)
        {
            var msg = new Msg();

            try
            {
                var Used = new Useds_total();
                var used = Used.FindById(id);
                if (used == null)
                {
                    throw new Exception("该宿舍读表信息不存在!");
                }
                else if (!Used.Delete(id))
                {
                    throw new Exception("删除宿舍读表信息时发生错误!");
                }
                else
                {
                    msg.Message = "删除成功!";
                }
            }
            catch (Exception ex)
            {
                msg.Code    = -1;
                msg.Message = ex.Message;
            }

            Response.Write(msg.ToJson());
            Response.End();
        }
Esempio n. 2
0
        public ActionResult UsedInfo()
        {
            var keyword = "";
            int page    = 1;
            int limit   = 10;
            int stat    = 0;
            int count   = 0;

            try
            {
                keyword = Request["keyword"]; // 搜索关键词
                page    = Convert.ToInt32(Request["page"]); if (page < 1)
                {
                    page = 1;
                }
                limit = Convert.ToInt32(Request["limit"]); if (limit > 99 || limit < 1)
                {
                    limit = 10;
                }
                stat = Convert.ToInt32(Request["stat"]);

                var Useds_total = new Useds_total();
                ViewBag.useds = Useds_total.GetByPages(page, limit, ref count, keyword, (int)Session["pid"]);// 获取列表

                ViewBag.keyword = keyword;
                ViewBag.count   = count; // 获取当前页数量
                ViewBag.page    = page;  // 获取当前页
                return(View());
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 3
0
        public void Last(FormCollection collection)
        {
            /// 获取宿舍的读表数值
            var msg = new Msg();

            try
            {
                var Used = new Useds_total();
                msg.Content = Used.Last(Convert.ToInt32(collection["pid"]));
                Response.Write(msg.ToJson());
                Response.End();
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 4
0
        public void CreateUsedInfo(FormCollection collection)
        {
            var msg = new Msg();
            var Db  = new Useds_total().Db;

            try
            {
                var pid = Convert.ToInt32(collection["pid"]);
                var cold_water_value = Convert.ToSingle(collection["cold_water_value"]);
                var hot_water_value  = Convert.ToSingle(collection["hot_water_value"]);
                var electric_value   = Convert.ToSingle(collection["electric_value"]);
                var Note             = collection["note"];

                ///1.1判断输入数值
                if (cold_water_value < 0 || hot_water_value < 0 || electric_value < 0)
                {
                    throw new Exception("数值输入有误,读表数值不能小于0");
                }
                else
                {
                    var usedinfo = Db.Queryable <T_Used_total>().Single(u => u.Ut_model_state && pid == u.Ut_room_id);
                    if (usedinfo == null)//如果读表数值为null,新建一个读表数值对象
                    {
                        usedinfo = new T_Used_total();
                        var room = Db.Queryable <Entity.T_Room>().Single(x => x.Room_id == pid && x.Room_model_state);
                        if (room == null)
                        {
                            throw new Exception("该宿舍不存在,id:" + pid);
                        }
                        usedinfo.Ut_dorm_id     = room.Room_dorm_id;
                        usedinfo.Ut_building_id = room.Room_building_id;
                        usedinfo.Ut_room_id     = pid;
                    }
                    usedinfo.Ut_note = Note;

                    usedinfo.Ut_hot_water_value  = hot_water_value;
                    usedinfo.Ut_cold_water_value = cold_water_value;
                    usedinfo.Ut_electric_value   = electric_value;

                    usedinfo.Ut_post_date = DateTime.Now;
                    ///1.2保存读表信息
                    Db.Ado.BeginTran();     //开始事务
                    if (usedinfo.Ut_id < 1) // 如果是新增的读表记录,就执行插入操作
                    {
                        Db.Insertable(usedinfo).ExecuteCommand();
                        //throw new Exception("插入读表记录时发生错误");
                    }
                    else if (Db.Updateable(usedinfo).ExecuteCommand() < 1)
                    {
                        throw new Exception("更新读表记录时发生错误"); // 否则执行更新操作
                    }
                    Db.Ado.CommitTran();                    // 提交事务
                    msg.Message = "保存成功";
                }
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();//发生错误,回滚操作
                msg.Code    = -1;
                msg.Message = "添加读表信息时发生错误:" + ex.Message;
            }
            Response.Write(msg.ToJson());
            Response.End();
        }