예제 #1
0
 public JsonResult Create(NoStockType obj)
 {
     try
     {
         obj.Enabled  = 1;
         obj.CreateBy = CurrentUser.Realname;
         obj.CreateOn = DateTime.Now;
         NSession.SaveOrUpdate(obj);
         NSession.Flush();
         List <NoStockLinkType> list1 = Newtonsoft.Json.JsonConvert.DeserializeObject <List <NoStockLinkType> >(obj.rows);
         foreach (NoStockLinkType link in list1)
         {
             link.OldSKU   = obj.OldSKU;
             link.SKU      = obj.SKU;
             link.PId      = obj.Id;
             link.CreateBy = CurrentUser.Realname;
             link.CreateOn = DateTime.Now;
             NSession.Save(link);
             NSession.Flush();
         }
     }
     catch (Exception ee)
     {
         return(Json(new { errorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = "true" }));
 }
예제 #2
0
 public JsonResult DoAudit(int Id)
 {
     try
     {
         StockInType obj = GetById(Id);
         obj.IsAudit = 1;
         NSession.SaveOrUpdate(obj);
         NSession.Flush();
         IList <WarehouseStockType> list = NSession.CreateQuery(" from WarehouseStockType where WId=:p1 and SKU=:p2").SetInt32("p1", obj.WId).SetString("p2", obj.SKU).List <WarehouseStockType>();
         if (list.Count > 0)
         {
             WarehouseStockType ws = list[0];
             ws.Qty = ws.Qty + obj.Qty;
             NSession.SaveOrUpdate(ws);
             NSession.Flush();
             Utilities.SetComposeStock(obj.SKU, NSession);
             Utilities.CreateSKUCode(obj.SKU, obj.Qty, obj.Id.ToString(), NSession);
             IList <OrderType> orders = NSession.CreateQuery(" from OrderType where Id in(select OId from OrderProductType where SKU ='" + obj.SKU + "' and IsQue=1) and IsOutOfStock=1").List <OrderType>();
             foreach (OrderType item in orders)
             {
                 OrderHelper.SetQueOrder(item, NSession);
             }
         }
     }
     catch (Exception ee)
     {
         return(Json(new { IsSuccess = false, ErrorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = true }));
 }
예제 #3
0
        public JsonResult Create(UserType obj)
        {
            try
            {
                OrganizeType obj1 = NSession.Get <OrganizeType>(obj.DId);
                if (obj1 != null)
                {
                    obj.DepartmentName = obj1.ShortName;
                }
                OrganizeType obj2 = NSession.Get <OrganizeType>(obj.CId);
                if (obj2 != null)
                {
                    obj.CompanyName = obj2.ShortName;
                }
                obj.CreateOn  = DateTime.Now;
                obj.LastVisit = DateTime.Now;

                NSession.SaveOrUpdate(obj);
                NSession.Flush();
            }
            catch (Exception ee)
            {
                return(Json(new { IsSuccess = false, ErrorMsg = "出错了" }));
            }
            return(Json(new { IsSuccess = true }));
        }
 public JsonResult Create(PurchasePlanType obj)
 {
     try
     {
         if (obj.SendOn < Convert.ToDateTime("2000-01-01"))
         {
             obj.SendOn = Convert.ToDateTime("2000-01-01");
         }
         if (obj.ReceiveOn < Convert.ToDateTime("2000-01-01"))
         {
             obj.ReceiveOn = Convert.ToDateTime("2000-01-01");
         }
         if (obj.ReceiveOn < Convert.ToDateTime("2000-01-01"))
         {
             obj.ReceiveOn = Convert.ToDateTime("2000-01-01");
         }
         obj.CreateOn = DateTime.Now;
         obj.BuyOn    = DateTime.Now;
         obj.CreateBy = CurrentUser.Realname;
         obj.BuyBy    = CurrentUser.Realname;
         NSession.SaveOrUpdate(obj);
         NSession.Flush();
         SaveSupplier(obj);
         LoggerUtil.GetPurchasePlanRecord(obj, "新建计划", "创建采购计划", CurrentUser, NSession);
     }
     catch (Exception ee)
     {
         return(Json(new { IsSuccess = false, ErrorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = true }));
 }
예제 #5
0
 public JsonResult Create(StockInType obj)
 {
     try
     {
         IList <WarehouseStockType> list =
             NSession.CreateQuery(" from WarehouseStockType where WId=:p1 and SKU=:p2").SetInt32("p1", obj.WId).
             SetString("p2", obj.SKU).List <WarehouseStockType>();
         if (list.Count > 0)
         {
             obj.IsAudit  = 0;
             obj.CreateBy = CurrentUser.Realname;
             obj.CreateOn = DateTime.Now;
             NSession.SaveOrUpdate(obj);
             NSession.Flush();
         }
         else
         {
             return(Json(new { IsSuccess = false, ErrorMsg = "该产品没有在系统中。请先添加产品!" }));
         }
     }
     catch (Exception ee)
     {
         return(Json(new { IsSuccess = false, ErrorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = true }));
 }
예제 #6
0
        public JsonResult Create(AccountType obj)
        {
            try
            {
                if (IsCreateOk(obj.AccountName, obj.Platform))
                {
                    return(Json(new { errorMsg = "此账号已存在!" }));
                }

                if (obj.Platform == "SMT")
                {
                    if (!string.IsNullOrEmpty(obj.ApiToken) && obj.ApiToken.Trim().Length > 0)
                    {
                        obj.ApiToken = AliUtil.GetToken(obj.ApiToken.Trim());
                    }
                }
                NSession.SaveOrUpdate(obj);
                NSession.Flush();
            }
            catch (Exception ee)
            {
                return(Json(new { IsSuccess = false, ErrorMsg = "出错了" }));
            }
            return(Json(new { IsSuccess = true }));
        }
예제 #7
0
 public ActionResult SavePic(HttpPostedFileBase fileData)
 {
     if (fileData != null)
     {
         try
         {
             // 文件上传后的保存路径
             string filePath;
             string fileName;
             string saveName;
             SaveFile(fileData, out filePath, out fileName, out saveName);
             filePath = Server.MapPath("~");
             IList <ProductType> list = NSession.CreateQuery(" from ProductType where SKU='" + fileName + "' ").List <ProductType>();
             if (list.Count > 0)
             {
                 list[0].PicUrl  = Utilities.BPicPath + list[0].SKU + ".jpg";
                 list[0].SPicUrl = Utilities.SPicPath + list[0].SKU + ".png";
                 Utilities.DrawImageRectRect(saveName, filePath + list[0].PicUrl, 310, 310);
                 Utilities.DrawImageRectRect(saveName, filePath + list[0].SPicUrl, 64, 64);
                 NSession.SaveOrUpdate(list[0]);
                 NSession.Flush();
             }
             return(Json(new { Success = true, FileName = fileName, SaveName = filePath + saveName }));
         }
         catch (Exception ex)
         {
             return(Json(new { Success = false, Message = ex.Message }, JsonRequestBehavior.AllowGet));
         }
     }
     else
     {
         return(Json(new { Success = false, Message = "请选择要上传的文件!" }, JsonRequestBehavior.AllowGet));
     }
 }
예제 #8
0
 public ActionResult Save(DictionaryType obj)
 {
     try
     {
         NSession.SaveOrUpdate(obj);
         NSession.Flush();
     }
     catch (Exception ee)
     {
         return(Json(new { IsSuccess = false, ErrorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = true }));
 }
예제 #9
0
 public JsonResult Create(RefundAmountType obj)
 {
     try
     {
         NSession.SaveOrUpdate(obj);
         NSession.Flush();
     }
     catch (Exception ee)
     {
         return(Json(new { errorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = "true" }));
 }
 public JsonResult Create(EbayType obj)
 {
     try
     {
         NSession.SaveOrUpdate(obj);
         NSession.Flush();
     }
     catch (Exception ee)
     {
         return(Json(new { ErrorMsg = "出错了", IsSuccess = false }));
     }
     return(Json(new { IsSuccess = "true" }));
 }
예제 #11
0
 public JsonResult Create(SerialNumberType obj)
 {
     try
     {
         NSession.SaveOrUpdate(obj);
         NSession.Flush();
     }
     catch (Exception ee)
     {
         return(Json(new { IsSuccess = false, ErrorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = true }));
 }
예제 #12
0
 public JsonResult Create(EmailTemplateType obj)
 {
     try
     {
         obj.Enable = 1;
         NSession.SaveOrUpdate(obj);
         NSession.Flush();
     }
     catch (Exception ee)
     {
         return(Json(new { IsSuccess = false, ErrorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = true }));
 }
 public JsonResult Create(LanguageType obj)
 {
     try
     {
         NSession.SaveOrUpdate(obj);
         NSession.Flush();
         Language.ReLoadLanguage();
     }
     catch (Exception ee)
     {
         return(Json(new { IsSuccess = false, ErrorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = true }));
 }
예제 #14
0
 public JsonResult Create(NewGuideType obj)
 {
     try
     {
         obj.CreateOn = DateTime.Now;
         NSession.SaveOrUpdate(obj);
         NSession.Flush();
     }
     catch (Exception ee)
     {
         return(Json(new { IsSuccess = false, ErrorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = true }));
 }
예제 #15
0
        public JsonResult Create(ProductType obj)
        {
            try
            {
                string filePath = Server.MapPath("~");
                obj.CreateOn = DateTime.Now;
                string pic = obj.PicUrl;
                if (!string.IsNullOrEmpty(pic))
                {
                    obj.PicUrl  = Utilities.BPicPath + obj.SKU + ".jpg";
                    obj.SPicUrl = Utilities.SPicPath + obj.SKU + ".png";

                    Utilities.DrawImageRectRect(pic, filePath + obj.PicUrl, 310, 310);
                    Utilities.DrawImageRectRect(pic, filePath + obj.SPicUrl, 64, 64);
                }

                List <ProductComposeType> list1 = Newtonsoft.Json.JsonConvert.DeserializeObject <List <ProductComposeType> >(obj.rows);
                if (list1.Count > 0)
                {
                    obj.IsZu = 1;
                }
                obj.Enabled = 1;
                NSession.SaveOrUpdate(obj);
                NSession.Flush();
                foreach (ProductComposeType productCompose in list1)
                {
                    productCompose.SKU = obj.SKU;
                    productCompose.PId = obj.Id;
                    NSession.Save(productCompose);
                    NSession.Flush();
                }
                List <ProductIsInfractionType> list2 = Newtonsoft.Json.JsonConvert.DeserializeObject <List <ProductIsInfractionType> >(obj.rows2);
                foreach (ProductIsInfractionType item in list2)
                {
                    item.OldSKU = obj.OldSKU;
                    item.SKU    = obj.SKU;
                    NSession.Save(item);
                    NSession.Flush();
                }

                AddToWarehouse(obj);
                LoggerUtil.GetProductRecord(obj, "商品创建", "创建一件商品", CurrentUser, NSession);
            }
            catch (Exception ee)
            {
                return(Json(new { IsSuccess = false, ErrorMsg = "出错了" }));
            }
            return(Json(new { IsSuccess = true }));
        }
 public JsonResult Create(SoresAddType obj)
 {
     try
     {
         obj.CreateBy = CurrentUser.Realname;
         obj.CreateOn = DateTime.Now;
         NSession.SaveOrUpdate(obj);
         NSession.Flush();
     }
     catch (Exception ee)
     {
         return(Json(new { errorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = "true" }));
 }
 public JsonResult Create(OrganizeType obj)
 {
     try
     {
         obj.CreateOn = DateTime.Now;
         obj.CreateBy = CurrentUser.Realname;
         NSession.SaveOrUpdate(obj);
         NSession.Flush();
     }
     catch (Exception ee)
     {
         return(Json(new { IsSuccess = false, ErrorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = true }));
 }
예제 #18
0
 public JsonResult Create(CountryType obj)
 {
     try
     {
         if (IsCreateOk(obj.ECountry))
         {
             return(Json(new { errorMsg = "编号已经存在" }));
         }
         NSession.SaveOrUpdate(obj);
         NSession.Flush();
     }
     catch (Exception ee)
     {
         return(Json(new { IsSuccess = false, ErrorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = true }));
 }
예제 #19
0
 public JsonResult Create(logisticsSetupType obj)
 {
     try
     {
         obj.SetupName     = obj.SetupId;
         obj.CreateOn      = DateTime.Now;
         obj.CreateBy      = GetCurrentAccount().Realname;
         obj.LogisticsName = NSession.Get <LogisticsType>(obj.LId).LogisticsName;
         NSession.SaveOrUpdate(obj);
         NSession.Flush();
     }
     catch (Exception ee)
     {
         return(Json(new { errorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = "true" }));
 }
예제 #20
0
 public JsonResult Create(LogisticsType obj)
 {
     try
     {
         if (IsCreateOk(obj.LogisticsCode))
         {
             return(Json(new { errorMsg = "此代码已存在,请检查后再创建!" }));
         }
         obj.CreateOn = DateTime.Now;
         NSession.SaveOrUpdate(obj);
         NSession.Flush();
     }
     catch (Exception ee)
     {
         return(Json(new { IsSuccess = false, ErrorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = true }));
 }
 public JsonResult Save(AccountFeeType obj)
 {
     try
     {
         if (obj.AmountBegin >= obj.AmountEnd)
         {
             return(Json(new { IsSuccess = false, ErrorMsg = "开始金额不能大于结束金额" }));
         }
         new System.Data.DataTable().Compute(obj.FeeFormula.Replace("T", "10"), "");
         NSession.SaveOrUpdate(obj);
         NSession.Flush();
     }
     catch (Exception ee)
     {
         return(Json(new { IsSuccess = false, ErrorMsg = "公式错误" }));
     }
     return(Json(new { IsSuccess = true }));
 }
        public ActionResult ResetFreight(string search, decimal z)
        {
            string orderby;

            var where = GetWhere(null, null, search, out @orderby);
            IList <OrderType> objList = NSession.CreateQuery("from OrderType " + where + orderby)
                                        .List <OrderType>();

            foreach (OrderType orderType in objList)
            {
                double d = 0;
                orderType.Freight = Convert.ToDouble(OrderHelper.GetFreight(orderType.Weight, orderType.LogisticMode, orderType.Country, NSession, z));
                NSession.SaveOrUpdate(orderType);
                NSession.Flush();
                OrderHelper.SaveAmount(orderType, NSession);
            }
            return(Json(new { IsSuccess = true }));
        }
 public JsonResult Create(PlanDaoType obj)
 {
     try
     {
         IList <PurchasePlanType> plan =
             NSession.CreateQuery("from PurchasePlanType where Id=:p").SetInt32("p", Convert.ToInt32(obj.PlanNo)).
             SetMaxResults(1)
             .List <PurchasePlanType>();
         if (plan.Count > 0)
         {
             if (plan[0].Status != "已收到")
             {
                 obj.PlanId = plan[0].Id;
                 obj.PlanNo = plan[0].PlanNo;
                 WarehouseType w = NSession.Get <WarehouseType>(obj.WId);
                 obj.WName   = w.WName;
                 obj.Price   = Math.Round(plan[0].Price + plan[0].Freight / plan[0].Qty, 4);
                 obj.DaoOn   = DateTime.Now;
                 obj.SendOn  = DateTime.Now;
                 obj.IsAudit = 0;
                 NSession.SaveOrUpdate(obj);
                 NSession.Flush();
                 plan[0].Status    = obj.Status;
                 plan[0].ReceiveOn = DateTime.Now;
                 plan[0].DaoQty   += obj.RealQty;
                 NSession.SaveOrUpdate(plan[0]);
                 NSession.Flush();
                 LoggerUtil.GetPurchasePlanRecord(plan[0], "采购到货", "采购到货" + obj.Status + obj.RealQty, CurrentUser, NSession);
             }
         }
         else
         {
             return(Json(new { ErrorMsg = "出错了", IsSuccess = false }));
         }
     }
     catch (Exception ee)
     {
         return(Json(new { IsSuccess = false, ErrorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = true }));
 }
        public JsonResult AuditDao(int Id)
        {
            PlanDaoType obj = NSession.Get <PlanDaoType>(Id);

            if (obj != null)
            {
                if (obj.IsAudit == 0)
                {
                    //obj.DaoOn = DateTime.Now;
                    obj.IsAudit = 1;
                    obj.SKUCode = Utilities.CreateSKUCode(obj.SKU, obj.RealQty, obj.PlanNo, NSession);

                    NSession.SaveOrUpdate(obj);
                    NSession.Flush();
                    Utilities.StockIn(obj.WId, obj.SKU, obj.RealQty, obj.Price, "采购到货", CurrentUser.Realname, obj.Memo, NSession, true);
                    return(Json(new { IsSuccess = true }));
                }
                return(Json(new { ErrorMsg = "已经审核了", IsSuccess = false }));
            }
            return(Json(new { ErrorMsg = "状态出错!", IsSuccess = false }));
        }
        public JsonResult Create(LogisticsAllocationType obj)
        {
            try
            {
                obj.CreateBy = CurrentUser.Realname;
                obj.CreateOn = DateTime.Now;
                if (!string.IsNullOrEmpty(obj.Content))
                {
                    obj.Content = "'" + obj.Content.Replace("\r", "").Replace("\n", ",").Replace(",", "','") + "'";
                }
                switch (obj.AllocationType)
                {
                case 1:
                    if (obj.NBegin > obj.NEnd)
                    {
                        obj.QuerySql = " Amount between " + obj.NBegin + " and " + obj.NEnd + " ";
                    }
                    break;

                case 2:
                    obj.QuerySql = " Country in (" + obj.Content + ") ";
                    break;

                case 3:
                    obj.QuerySql = " Id in(select OId from OrderProducts where SKU in (" + obj.Content + ")  ) ";
                    break;

                default:
                    break;
                }

                NSession.SaveOrUpdate(obj);
                NSession.Flush();
            }
            catch (Exception ee)
            {
                return(Json(new { errorMsg = "出错了" }));
            }
            return(Json(new { IsSuccess = "true" }));
        }
        public JsonResult Create(UserSetupType obj)
        {
            try
            {
                obj.CreateOn = DateTime.Now;
                obj.CreateBy = GetCurrentAccount().Realname;



                RoleEnum displayType = (RoleEnum)System.Enum.Parse(typeof(RoleEnum), obj.SetupID.ToString());
                obj.SetupName = displayType.ToString();
                UserType user = NSession.Get <UserType>(obj.UId);
                obj.RealName = user.Realname;
                NSession.SaveOrUpdate(obj);
                NSession.Flush();
            }
            catch (Exception ee)
            {
                return(Json(new { errorMsg = "出错了" }));
            }
            return(Json(new { IsSuccess = "true" }));
        }
예제 #27
0
        private void AddToWarehouse(ProductType obj)
        {
            IList <WarehouseType> list = NSession.CreateQuery(" from WarehouseType").List <WarehouseType>();

            //
            //在仓库中添加产品库存
            //
            foreach (var item in list)
            {
                WarehouseStockType stock = new WarehouseStockType();
                stock.Pic       = obj.SPicUrl;
                stock.WId       = item.Id;
                stock.Warehouse = item.WName;
                stock.PId       = obj.Id;
                stock.SKU       = obj.SKU;
                stock.Title     = obj.ProductName;
                stock.Qty       = 0;
                stock.UpdateOn  = DateTime.Now;
                NSession.SaveOrUpdate(stock);
                NSession.Flush();
            }
        }
예제 #28
0
 public JsonResult Create(DisputeType obj)
 {
     try
     {
         object count = NSession.CreateQuery("select Count(Id) from DisputeType where OrderNo='" + obj.OrderNo + "'").UniqueResult();
         if (Convert.ToInt32(count) > 0)
         {
             return(Json(new { IsSuccess = false, ErrorMsg = "该订单已经存在纠纷列表中" }));
         }
         obj.SolveOn   = Convert.ToDateTime("2000-01-01");
         obj.DisputeOn = DateTime.Now;
         obj.Status    = "未解决";
         obj.CreateOn  = DateTime.Now;
         obj.CreateBy  = CurrentUser.Realname;
         NSession.SaveOrUpdate(obj);
         NSession.Flush();
         LoggerUtil.GetDisputeRecord(obj, "发生纠纷", " 创建纠纷信息", CurrentUser, NSession);
     }
     catch (Exception ee)
     {
         return(Json(new { IsSuccess = false, ErrorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = true }));
 }
예제 #29
0
        public ActionResult ImportProduct(string fileName)
        {
            try
            {
                List <ResultInfo>     results = new List <ResultInfo>();
                DataTable             dt      = OrderHelper.GetDataTable(fileName);
                IList <WarehouseType> list    = NSession.CreateQuery(" from WarehouseType").List <WarehouseType>();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ProductType p = new ProductType {
                        CreateOn = DateTime.Now
                    };
                    p.SKU = dt.Rows[i]["子SKU"].ToString().Trim();
                    if (IsExist(p.SKU))
                    {
                        continue;
                    }
                    p.Status           = dt.Rows[i]["销售状态"].ToString();
                    p.ProductName      = dt.Rows[i]["名称"].ToString();
                    p.Category         = dt.Rows[i]["分类"].ToString();
                    p.Standard         = dt.Rows[i]["规格"].ToString();
                    p.Price            = Convert.ToDouble(dt.Rows[i]["价格"]);
                    p.Weight           = Convert.ToInt16(dt.Rows[i]["重量"]);
                    p.Long             = Convert.ToInt16(dt.Rows[i]["长"]);
                    p.Wide             = Convert.ToInt16(dt.Rows[i]["宽"]);
                    p.High             = Convert.ToInt16(dt.Rows[i]["高"]);
                    p.Location         = dt.Rows[i]["库位号"].ToString();
                    p.OldSKU           = dt.Rows[i]["SKU"].ToString();
                    p.HasBattery       = Convert.ToInt32(dt.Rows[i]["电池"].ToString());
                    p.IsElectronic     = Convert.ToInt32(dt.Rows[i]["电子"].ToString());
                    p.IsScan           = Convert.ToInt32(dt.Rows[i]["配货扫描"].ToString());
                    p.DayByStock       = Convert.ToInt32(dt.Rows[i]["备货天数"].ToString());
                    p.ProductAttribute = dt.Rows[i]["产品属性"].ToString();
                    p.Enabled          = 1;
                    if (!HasExsit(p.SKU))
                    {
                        NSession.SaveOrUpdate(p);
                        NSession.Flush();
                        results.Add(OrderHelper.GetResult(p.SKU, "", "导入成功"));

                        //在仓库中添加产品库存
                        foreach (var item in list)
                        {
                            WarehouseStockType stock = new WarehouseStockType();
                            stock.Pic       = p.SPicUrl;
                            stock.WId       = item.Id;
                            stock.Warehouse = item.WName;
                            stock.PId       = p.Id;
                            stock.SKU       = p.SKU;
                            stock.Title     = p.ProductName;
                            stock.Qty       = 0;
                            stock.UpdateOn  = DateTime.Now;
                            NSession.SaveOrUpdate(stock);
                            NSession.Flush();
                        }
                    }
                    else
                    {
                        results.Add(OrderHelper.GetResult(p.SKU, "该产品已存在", "导入失败"));
                    }
                }
                Session["Results"] = results;
                return(Json(new { IsSuccess = true, Info = true }));
            }
            catch (Exception ex)
            {
                return(Json(new { IsSuccess = false, ErrorMsg = ex.Message, Info = true }));
            }
        }
        //签到操作
        public JsonResult AttendOn(int id, string code = "")
        {
            string   ip         = GetIP();
            DateTime AttentTime = DateTime.Now;
            int      userid     = CurrentUser.Id;
            string   usercode   = CurrentUser.Code;
            string   realname   = CurrentUser.Realname;

            if (code != "")
            {
                IList <UserType> users = NSession.CreateQuery("from UserType where Code='" + code + "'").List <UserType>();
                if (users.Count > 0)
                {
                    userid   = users[0].Id;
                    usercode = users[0].Code;
                    realname = users[0].Realname;
                }
                else
                {
                    return(Json(new { Msg = code + " 编号不存在!" }, JsonRequestBehavior.AllowGet));
                }
            }
            AttendType obj = new AttendType()
            {
                CurrentDate = AttentTime.Date, UserId = userid, UserCode = usercode, RealName = realname
            };

            try
            {
                IList <AttendType> list = NSession.CreateQuery("from AttendType where UserId='" + obj.UserId + "' and CurrentDate='" + obj.CurrentDate + "'").List <AttendType>();
                if (IsOK(ip))
                {
                    //IList<AttendType> objList = NSession.CreateQuery("from AttendType " + " where UserId=\'" + obj.UserId + "\'  order by CurrentDate desc ")
                    //.List<AttendType>();
                    //if (objList.Count > 0)
                    //{
                    //   //NoAttend(objList[0].CurrentDate);
                    //}
                    if (list.Count > 0)
                    {
                        obj = list[0];
                    }
                    obj.IP = ip;
                }
                else
                {
                    return(Json(new { Msg = "请使用公司网络打卡!" }, JsonRequestBehavior.AllowGet));
                }

                switch (id)
                {
                case 0:
                    if (string.IsNullOrEmpty(obj.AMStart))
                    {
                        obj.AMStart = AttentTime.ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    else
                    {
                        return(Json(new { Msg = "请不要重复打卡!" }, JsonRequestBehavior.AllowGet));
                    }
                    break;

                case 1:
                    if (string.IsNullOrEmpty(obj.AMEnd))
                    {
                        obj.AMEnd = AttentTime.ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    else
                    {
                        return(Json(new { Msg = "请不要重复打卡!" }, JsonRequestBehavior.AllowGet));
                    }
                    break;

                case 2:
                    if (string.IsNullOrEmpty(obj.PMStart))
                    {
                        obj.PMStart = AttentTime.ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    else
                    {
                        return(Json(new { Msg = "请不要重复打卡!" }, JsonRequestBehavior.AllowGet));
                    }
                    break;

                case 3:
                    if (string.IsNullOrEmpty(obj.PMEnd))
                    {
                        obj.PMEnd = AttentTime.ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    else
                    {
                        return(Json(new { Msg = "请不要重复打卡!" }, JsonRequestBehavior.AllowGet));
                    }
                    break;
                }
                NSession.SaveOrUpdate(obj);
                NSession.Flush();
            }
            catch (Exception ee)
            {
                return(Json(new { Msg = "出错了" }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { Msg = obj.RealName + " 签到成功:" + AttentTime.ToString("yyyy-MM-dd HH:mm:ss") }, JsonRequestBehavior.AllowGet));
        }