public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            NameValueCollection rp = context.Request.Form;
            string msg = string.Empty;
            try
            {
                string succesmsg = "";
                List<BaseEntity> list = new List<BaseEntity>();
                if (rp.AllKeys.Contains("ID"))
                {
                    //单条记录保存
                    YuanGongKaoQin entity = new YuanGongKaoQin();
                    if (string.IsNullOrEmpty(rp["ID"]))
                    {
                        entity.ID = Guid.NewGuid();
                        entity.CreateDate = DateTime.Now;
                        if (!string.IsNullOrEmpty(context.Session["UserName"] as string))
                        {
                            entity.CreaterID = new Guid(context.Session["UserID"].ToString());

                        }
                        else
                        {
                            entity.CreaterID = Guid.NewGuid();
                        }
                    }
                    else
                    {
                        entity.ID = new Guid(rp["ID"]);
                        entity.RecordStatus = StatusType.update;
                        if (!string.IsNullOrEmpty(context.Session["UserName"] as string))
                        {
                            entity.UpdaterID = new Guid(context.Session["UserID"].ToString());
                            entity.Updatedate = DateTime.Now;
                        }
                    }
                    entity.UserID = new Guid(rp["PersonID"]);
                    entity.UserName = rp["RealName"];
                    entity.StartTime = rp["StartTime"];
                    entity.EndTime = rp["EndTime"];
                    entity.KQRQ = DateTime.Parse(rp["KQRQ"]);
                    entity.SWStatus = rp["SWStatus"];
                    entity.Status = rp["Status"];
                    entity.Note = rp["Note"];
                    list.Add(entity);
                    succesmsg = "{\"success\":\"true\",\"ID\":\"" + entity.ID + "\"}";
                }
                else
                {
                    //多条记录保存
                    int rows = 0;
                    int.TryParse(rp["count"], out rows);
                    for (int i = 0; i < rows; i++)
                    {
                        string rowpix = string.Format("row[{0}]", i);
                        YuanGongKaoQin entity = new YuanGongKaoQin();
                        if (string.IsNullOrEmpty(rp[rowpix + "[ID]"]))
                        {
                            entity.ID = Guid.NewGuid();
                            entity.CreateDate = DateTime.Now;
                            if (!string.IsNullOrEmpty(context.Session["UserName"] as string))
                            {
                                entity.CreaterID = new Guid(context.Session["UserID"].ToString());

                            }
                            else
                            {
                                entity.CreaterID = Guid.NewGuid();
                            }
                        }
                        else
                        {
                            entity.ID = new Guid(rp[rowpix + "[ID]"]);
                            entity.RecordStatus = StatusType.update;
                            if (!string.IsNullOrEmpty(context.Session["UserName"] as string))
                            {
                                entity.UpdaterID = new Guid(context.Session["UserID"].ToString());
                                entity.Updatedate = DateTime.Now;
                            }
                        }
                        entity.UserID = new Guid(rp[rowpix + "[PersonID]"]);
                        entity.UserName = rp[rowpix + "[RealName]"];
                        entity.StartTime = rp[rowpix + "[StartTime]"];
                        entity.EndTime = rp[rowpix + "[EndTime]"];
                        entity.KQRQ = DateTime.Parse(rp["KQRQ"]);
                        entity.SWStatus = rp[rowpix + "[SWStatus]"];
                        entity.Status = rp[rowpix + "[Status]"];
                        entity.Note = rp[rowpix + "[Note]"];
                        list.Add(entity);
                    }
                    succesmsg = "{\"success\":\"true\" }";
                }

                YuanGongKaoQinManager manager = new YuanGongKaoQinManager();
                manager.Save(list);
                context.Response.Write(succesmsg);

            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            if (!string.IsNullOrEmpty(msg))
            {
                byte[] bytes = Encoding.UTF8.GetBytes(msg.Replace("\r\n", "<br/>"));
                string encode = Convert.ToBase64String(bytes);
                context.Response.Write("{\"success\":\"false\",\"msg\":\"" + encode + "\"}");
            }
            context.Response.End();
        }
Example #2
0
 /// <summary>
 /// 根据ID获取员工考勤实体
 /// </summary>
 /// <param name="guid">主键ID</param>
 /// <returns>返回员工考勤实体</returns> 
 public YuanGongKaoQin GetItemById(Guid guid)
 {
     YuanGongKaoQin tem = new YuanGongKaoQin();
     tem = Dal.Find<YuanGongKaoQin>(YuanGongKaoQin._.ID == guid);
     return tem;
 }