public HttpResponseMessage RiZhiYo(string userid,string seeid,string logtick)
        {
            string res = "";
            BaseService baseservice = new BaseService();
            string sqlstr = "";
                if (logtick == "0")
                {
                    sqlstr = "with cte as " +
                                "( " +
                                " select row=row_number()over(order by getdate()), * from WktuserShareUserId where SharePresonid =  " + userid.ToString() + "and WktUserId=" + seeid.ToString() + " and WktuserShareUserId.STATE = 0 and WriteTime > " + logtick.ToString() +
                                ") " +
                                " select * from cte where row between " + "1" + " and " + "10";
                }
                else
                {
                    sqlstr = "with cte as " +
                                "( " +
                                " select row=row_number()over(order by getdate()), * from WktuserShareUserId where SharePresonid =  " + userid.ToString() + "and WktUserId=" + seeid.ToString() + " and WktuserShareUserId.STATE = 0 and WriteTime < " + logtick.ToString() +
                                ") " +
                                " select * from cte where row between " + "1" + " and " + "10";

                }
                IList nbhstaff = baseservice.ExecuteSQL(sqlstr);
                List<RiZhiinfo> stafflist = new List<RiZhiinfo>();
                if (nbhstaff != null && nbhstaff.Count > 0)
                {
                    for (int i = 0; i < nbhstaff.Count; i++)
                    {
                        object[] sf = (object[])nbhstaff[i];
                        RiZhiinfo st = new RiZhiinfo();
                        // Personinfo p = new Personinfo();
                        st.PersonId = sf[3].ToString();//分享人的ID
                        st.PersonName = sf[6].ToString();//分享人的姓名
                        WkTUser user = new WkTUser();
                        user = (WkTUser)baseservice.loadEntity(user, Convert.ToInt64(st.PersonId));
                        long m = user.Kdid.Id;
                        WkTDept dept = new WkTDept();
                        dept = (WkTDept)baseservice.loadEntity(dept, m);
                        st.PersonDept = dept.KdName;//分享人的部门
                        st.Logtick = sf[4].ToString();
                        st.PersonMD5code = user.ImgMD5Code;
                        st.Contenttxt140 = HtmlToReguFormat140(sf[5].ToString());//日志内容去格式前140
                        //st.ContenttxtAll = sf[5].ToString();//日志全部内容
                        st.RizhiTime = new DateTime(Convert.ToInt64(sf[4].ToString())).ToString("yyyy年MM月dd日 HH:mm:ss");//日志时间
                        st.RizhiId = sf[7].ToString(); //日志id
                        st.Imglist = HtmlToReguForimg(sf[5].ToString());//日志图片
                        List<Comments> q = new List<Comments>();
                        List<comm> ps = new List<comm>();
                        IList c = baseservice.loadEntityList("from StaffLog where State=" + (int)IEntity.stateEnum.Normal + "and Id=" + st.RizhiId);
                        if (c != null && c.Count > 0)
                        {
                            foreach (StaffLog n in c)
                            {
                                IList<Comments> r = n.Comments;
                                foreach (Comments s in r)
                                {
                                    string sqql = "select u from WkTUser u where u.KuName='" + s.CommentPersonName.Trim() + "'";
                                    WkTUser ww = (WkTUser)baseservice.loadEntityList(sqql)[0];
                                    comm p = new comm();
                                    p.Id = ww.Id.ToString();
                                    p.Na = s.CommentPersonName;//评论人名字
                                    //IList d = baseservice.loadEntityList("from StaffLog where State=" + 758);
                                    //foreach(WkTUser d1 in d)
                                    //{
                                    //    p.Id = d1.Id;
                                    //}
                                    p.Co = s.Content;//评论内容
                                    p.Commtime = new DateTime(s.TimeStamp).ToString("yyyy年MM月dd日 HH:mm:ss");
                                    ps.Add(p);
                                }
                            }
                        }
                        st.Comments = ps;
                        stafflist.Add(st);
                    }
                    RiZhiAll l = new RiZhiAll();
                    l.List = stafflist;
                    res = "成功";
                    string data = JsonTools.ObjectToJson(l);
                    var jsonStr = "{\"Message\":" + "\"" + res + "\"" + "," + "\"data\":" + data + "}";
                    var result = new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new StringContent(jsonStr, Encoding.UTF8, "text/json")
                    };
                    return result;
                }
                else
                {
                    res = "没有内容";
                    string data = "1";//JsonTools.ObjectToJson(l);
                    var jsonStr = "{\"Message\":" + "\"" + res + "\"" + "," + "\"data\":" + data + "}";
                    var result = new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new StringContent(jsonStr, Encoding.UTF8, "text/json")
                    };
                    return result;
                }
        }
        public HttpResponseMessage GetUserInfo(string uid)
        {
            string res = "错误";

            string data = "1";

            BaseService baseService = new BaseService();

            string perid = uid;
            long id = long.Parse(perid);
            WkTUser w = new WkTUser();
            w = (WkTUser)baseService.loadEntity(w, id);

            if (w.Id.ToString() == uid)
            {
                res = "成功";

                PersonInfo p = new PersonInfo();
                p.Id = w.Id.ToString();
                p.PersonName = w.KuName;
                if (w.KuPhone != null)
                {
                    p.PersonPhone = w.KuPhone.Trim();

                }
                p.MD5code = w.ImgMD5Code.Trim();

                Dept d = new Dept();
                d.Id = w.Kdid.Id.ToString();
                d.DeptName = w.Kdid.KdName.Trim();
                p.PersonDept = d;

                data = JsonTools.ObjectToJson(p);

            }

            var jsonStr = "{\"Message\":" + "\"" + res + "\"" + "," + " \"data\":" + data + "}";
            var result = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(jsonStr, Encoding.UTF8, "text/json")
            };
            return result;
        }
        public HttpResponseMessage GetRiZhi2(string userid, string seeid, string logtick)
        {
            string res = "";
            string sql1 = "select u from WkTUser u where u.KuName='" + userid + "'";
            string sql2 = "select u from WkTUser u where u.Id='" + seeid + "'";
            string sql3 = "select u.DeptId from Wktuser_M_Dept u where u.WktuserId=" + userid + " and u.State = " + (int)IEntity.stateEnum.Normal;
            BaseService baseservice = new BaseService();
            List<WkTDept> theDepts = new List<WkTDept>();
            IList theone = baseservice.loadEntityList(sql3);
            if (theone != null && theone.Count > 0)
            {
                List<RiZhiinfo> stafflist = new List<RiZhiinfo>();
                WkTUser user = new WkTUser();
                user = (WkTUser)baseservice.loadEntity(user, Convert.ToInt64(seeid));
                string m = user.Kdid.Id.ToString();
                int flog = 1;
                for (int i = 0; i < theone.Count; i++)
                {

                    string a = "";
                    a = ((WkTDept)theone[i]).Id.ToString();
                    if (a == m)
                    {
                        flog = 0;
                        string sqlstr = "";
                        if (logtick == "0")
                        {
                            sqlstr = "with cte as " +
                                        "( " +
                                        " select row=row_number()over(order by getdate()), * from LOG_T_STAFFLOG where WktUserId=" + seeid.ToString() + " and WriteTime > " + logtick.ToString() +
                                        ") " +
                                        " select * from cte where row between " + "1" + " and " + "10";
                        }
                        else
                        {
                            sqlstr = "with cte as " +
                                        "( " +
                                        " select row=row_number()over(order by getdate()), * from LOG_T_STAFFLOG where WktUserId=" + seeid.ToString() + " and WriteTime < " + logtick.ToString() +
                                        ") " +
                                        " select * from cte where row between " + "1" + " and " + "10";
                        }
                        IList one = baseservice.ExecuteSQL(sqlstr);

                        if (one != null && one.Count > 0)
                        {
                            for (int j = 0; j < one.Count; j++)
                            {
                                object[] sf = (object[])one[j];
                                RiZhiinfo st = new RiZhiinfo();
                                //// Personinfo p = new Personinfo();
                                st.PersonId = sf[4].ToString();//分享人的ID

                                WkTUser user1 = new WkTUser();
                                user1 = (WkTUser)baseservice.loadEntity(user1, Convert.ToInt64(st.PersonId));
                                st.PersonName = user1.KuLid;//分享人的姓名
                                //long mm = user1.Kdid.Id;
                                WkTDept dept = new WkTDept();
                                dept = (WkTDept)baseservice.loadEntity(dept, Convert.ToInt64(m));
                                st.PersonDept = dept.KdName;//分享人的部门
                                st.Logtick = sf[3].ToString();
                                st.PersonMD5code = user1.ImgMD5Code;
                                st.Contenttxt140 = HtmlToReguFormat140(sf[2].ToString());//日志内容去格式前140
                                ////st.ContenttxtAll = sf[5].ToString();//日志全部内容
                                st.RizhiTime = new DateTime(Convert.ToInt64(sf[3].ToString())).ToString("yyyy年MM月dd日 HH:mm:ss");//日志时间
                                st.RizhiId = sf[1].ToString(); //日志id
                                st.Imglist = HtmlToReguForimg(sf[2].ToString());//日志图片
                                List<Comments> q = new List<Comments>();
                                List<comm> ps = new List<comm>();
                                IList c = baseservice.loadEntityList("from StaffLog where State=" + (int)IEntity.stateEnum.Normal + "and Id=" + st.RizhiId);
                                if (c != null && c.Count > 0)
                                {
                                    foreach (StaffLog n in c)
                                    {
                                        IList<Comments> r = n.Comments;
                                        foreach (Comments s in r)
                                        {
                                            string sqql = "select u from WkTUser u where u.KuName='" + s.CommentPersonName.Trim() + "'";
                                            WkTUser ww = (WkTUser)baseservice.loadEntityList(sqql)[0];
                                            comm p = new comm();
                                            p.Id = ww.Id.ToString();
                                            p.Na = s.CommentPersonName;//评论人名字
                                            //IList d = baseservice.loadEntityList("from StaffLog where State=" + 758);
                                            //foreach(WkTUser d1 in d)
                                            //{
                                            //    p.Id = d1.Id;
                                            //}
                                            p.Co = s.Content;//评论内容
                                            p.Commtime = new DateTime(s.TimeStamp).ToString("yyyy年MM月dd日 HH:mm:ss");
                                            ps.Add(p);
                                        }
                                    }
                                }
                                st.Comments = ps;
                                stafflist.Add(st);
                            }
                        }
                    }
                }
                RiZhiAll l = new RiZhiAll();
                l.List = stafflist;
                res = "成功";
                string data = JsonTools.ObjectToJson(l);
                var jsonStr = "{\"Message\":" + "\"" + res + "\"" + "," + "\"data\":" + data + "}";
                var result = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(jsonStr, Encoding.UTF8, "text/json")
                };
                return result;

                if(flog==1)
                {
                    return RiZhiYo(userid, seeid, logtick);

                }
            }
            else
            {
                return RiZhiYo(userid, seeid, logtick);

            }
        }
        public HttpResponseMessage GetSendPhoneNum([FromUri]string phonenum,[FromUri]string uid)
        {
            BaseService baseService = new BaseService ();

            string res = "";
            string phoneNum = phonenum;
            string perid =uid;
            long id = long.Parse(perid);
            WkTUser w = new WkTUser();
            w = (WkTUser)baseService.loadEntity(w, id);

            w.KuPhone = phoneNum;
            try
            {
                baseService.SaveOrUpdateEntity(w);
                res = "成功";
            }
            catch(Exception ex)
            {
                res = ex.Message;
            }

            //string data = JsonTools.ObjectToJson(l);
            string data = "1";
            var jsonStr = "{\"Message\":" + "\"" + res + "\"" + "," + " \"data\":" + data + "}";
            var result = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(jsonStr, Encoding.UTF8, "text/json")
            };
            return result;
        }
        //签退
        public HttpResponseMessage GetsignExitInfo(int id)
        {
            string res = "";
            string timetxt = "";
            BaseService baseService = new BaseService();
            DateTime today;

            today = DateTime.Now;
            WkTUser user = new WkTUser();
            user = (WkTUser)baseService.loadEntity(user, id);

            if (CNDate.isworkDay(today.Date.Ticks))
            {
                IList attendanceList = baseService.loadEntityList("from Attendance where STATE=" + (int)IEntity.stateEnum.Normal + " and User="******" and SignDate=" + today.Date.Ticks);
                if (attendanceList != null && attendanceList.Count == 1)
                {
                    Attendance todaySignStart = (Attendance)attendanceList[0];
                    IList usuallyDayList = baseService.loadEntityList("from UsuallyDay where STATE=" + (int)IEntity.stateEnum.Normal + " and StartTime<=" + today.Date.Ticks + " order by StartTime desc");
                    if (usuallyDayList != null && usuallyDayList.Count == 1)
                    {
                        UsuallyDay u = (UsuallyDay)usuallyDayList[0];

                        if (u.WorkTimeEnd <= today.TimeOfDay.Ticks)//未早退
                        {
                            if (todaySignStart.LateOrLeaveEarly == (int)Attendance.lateOrLeaveEarlyEnum.LateAndEarly)  //登陆为LateAndEarly表示迟到
                            {
                                todaySignStart.LateOrLeaveEarly = (int)Attendance.lateOrLeaveEarlyEnum.Late; // 只是迟到
                            }
                            else
                            {
                                todaySignStart.LateOrLeaveEarly = (int)Attendance.lateOrLeaveEarlyEnum.Normal;  //  正常签到
                            }
                        }

                        else //早退
                        {
                            if (todaySignStart.LateOrLeaveEarly == (int)Attendance.lateOrLeaveEarlyEnum.LateAndEarly)
                            {
                                todaySignStart.LateOrLeaveEarly = (int)Attendance.lateOrLeaveEarlyEnum.LateAndEarly; //迟到并且早退
                            }
                            else
                            {
                                todaySignStart.LateOrLeaveEarly = (int)Attendance.lateOrLeaveEarlyEnum.Early; //只是早退
                            }
                        }

                    }
                    todaySignStart.SignEndTime = today.TimeOfDay.Ticks;
                    todaySignStart.SignDate = today.Date.Ticks;
                    todaySignStart.SignDay = today.Day;
                    todaySignStart.SignMonth = today.Month;
                    todaySignStart.SignYear = today.Year;
                    todaySignStart.State = (int)IEntity.stateEnum.Normal;
                    todaySignStart.TimeStamp = DateTime.Now.Ticks;
                    todaySignStart.User = user;
                    try
                    {
                        baseService.SaveOrUpdateEntity(todaySignStart);
                        res = "签退成功";
                    }
                    catch
                    {
                        res = "签退失败";

                    }
                    timetxt = CNDate.getTimeByTimeTicks(todaySignStart.SignStartTime) + "-" + CNDate.getTimeByTimeTicks(today.TimeOfDay.Ticks);
                }
            }

            var jsonStr = "{\"Message\":" + "\"" + res + "\"" + "," + " \"data\":\"" + timetxt + "\"}";
            var result = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(jsonStr, Encoding.UTF8, "text/json")
            };
            return result;
        }
Beispiel #6
0
        public string Base64StringToImage(string base64Imgstring,int id)
        {
            string res;
            BaseService baseservice = new BaseService();
            String inputStr = "";
            string url = "";
            string md5code = "";
            try
            {
                                //FileStream ifs = new FileStream(txtFileName, FileMode.Open, FileAccess.Read);
                                //StreamReader sr = new StreamReader(ifs);
                                //byte[] buffer = Convert.FromBase64String(base64Imgstring);
                                //String textBase64 = Base64.encodeToString(textByte, Base64.DEFAULT);
                inputStr = base64Imgstring.Substring(22);
                byte[] arr = Convert.FromBase64String(inputStr);
                MemoryStream ms = new MemoryStream(arr);
                Bitmap bmp = new Bitmap(ms);

                                //bmp.Save(txtFileName + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                                //bmp.Save(txtFileName + ".bmp", ImageFormat.Bmp);
                                //bmp.Save(txtFileName + ".gif", ImageFormat.Gif);
                                //bmp.Save(txtFileName + ".png", ImageFormat.Png);

                ms.Close();

                url  = HttpContext.Current.Server.MapPath("/") +
                         @"\\Images\\Icons\\" + id + ".png";

                if (File.Exists(url))
                {
                 File.Delete(url);
                }

                bmp.Save(url,ImageFormat.Png);

                if (File.Exists(url))
                {
                    md5code =   GetMD5HashFromFile(url);

                   WkTUser w = new WkTUser();
                   w = (WkTUser)baseservice.loadEntity(w, id);

                   w.ImgMD5Code = md5code;
                   w.Base64Img = base64Imgstring;

                   baseservice.SaveOrUpdateEntity(w);

                }

                //sr.Close();
                //ifs.Close();
                //this.pictureBox2.Image = bmp;
                //if (File.Exists(txtFileName))
                //{
                    //File.Delete(txtFileName);
                //}
                res = "转换成功"; //+base64Imgstring.Length + "    " + md5code;
                //MessageBox.Show("转换成功!");
            }
            catch (Exception ex)
            {
                res = "Base64StringToImage 转换失败\nException:" + ex.Message; //+ "      00000" + md5code + inputStr;
                //MessageBox.Show("Base64StringToImage 转换失败\nException:" + ex.Message);
            }
            return res;
        }
        public HttpResponseMessage GetAttenceInfo(int id)
        {
            BaseService baseService = new BaseService ();
            string res = "";

            string timetxt = "" ;

            WkTUser user = new WkTUser ()  ;
            user = (WkTUser)baseService.loadEntity(user, id);
                   DateTime today;

                   today = DateTime.Now;

                    if (CNDate.isworkDay(today.Date.Ticks))//工作日登录
                    {
                        //查询最近的工作起始时间安排
                        IList attendanceList = baseService.loadEntityList("from Attendance where STATE=" + (int)IEntity.stateEnum.Normal + " and User="******" and SignDate=" + today.Date.Ticks);

                        if (attendanceList != null && attendanceList.Count == 1)//今天登录过
                        {
                            res = "今天登录过";
                            Attendance atd = (Attendance)attendanceList[0];
                            timetxt += atd.SignStartTime != 0 ? CNDate.getTimeByTimeTicks(atd.SignStartTime) : "";
                            timetxt += "-";
                            timetxt += atd.SignEndTime != 0 ? CNDate.getTimeByTimeTicks(atd.SignEndTime) : "未签退";
                        }

                        else // 今天没有登陆过
                        {
                            Attendance todaySignStart = new Attendance();//用于记录考勤信息
                            IList usuallyDayList = baseService.loadEntityList("from UsuallyDay where STATE="
                                + (int)IEntity.stateEnum.Normal + " and StartTime<=" + today.Date.Ticks +
                                " order by StartTime desc"); //查询作息时间
                            if (usuallyDayList != null && usuallyDayList.Count == 1) //存在作息时间设置
                            {
                                UsuallyDay u = (UsuallyDay)usuallyDayList[0];
                                if (u.WorkTimeStart >= today.TimeOfDay.Ticks)
                                {
                                    todaySignStart.LateOrLeaveEarly = (int)Attendance.lateOrLeaveEarlyEnum.Early; // 正常签到
                                }
                                else
                                {
                                    todaySignStart.LateOrLeaveEarly = (int)Attendance.lateOrLeaveEarlyEnum.LateAndEarly; // 迟到
                                }
                            }
                            todaySignStart.SignStartTime = today.TimeOfDay.Ticks;
                            todaySignStart.SignDate = today.Date.Ticks;
                            todaySignStart.SignDay = today.Day;
                            todaySignStart.SignMonth = today.Month;
                            todaySignStart.SignYear = today.Year;
                            todaySignStart.State = (int)IEntity.stateEnum.Normal;

                                todaySignStart.TimeStamp = DateTime.Now.Ticks;

                            todaySignStart.User = user;
                            try
                            {
                                baseService.SaveOrUpdateEntity(todaySignStart);
                                res = "签到成功";
                            }
                            catch
                            {
                                res = "签到失败";

                            }
                            timetxt = CNDate.getTimeByTimeTicks(todaySignStart.SignStartTime) + "-"+"未签退";
                        }
                    }
                    else
                    {
                        timetxt = "今天是休息日";

                        //this.attendance_label.Text = "今天是休息日";

                    }

            //string data = JsonTools.ObjectToJson(l);

                    var jsonStr = "{\"Message\":" + "\"" + res + "\"" + "," + " \"data\":\"" + timetxt + "\"}";
            var result = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(jsonStr, Encoding.UTF8, "text/json")
            };
            return result;
        }
        /// <summary>
        /// 获得所有的日程
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="rctime"></param>
        /// <returns></returns>
        public HttpResponseMessage GetAllRiCheng(string userid, string rctime)
        {
            string sqlstr = null;
            if (rctime == "0")
            {
                sqlstr = "with cte as " +
                            "( " +
                            " select row=row_number()over(order by getdate()), * from LOG_T_STAFFSCHEDULE where  ScheduleTime > " + rctime.ToString() +
                            ") " +
                            " select * from cte where row between " + "1" + " and " + "10";
            }
            else
            {
                sqlstr = "with cte as " +
                            "( " +
                            " select row=row_number()over(order by getdate()), * from LOG_T_STAFFSCHEDULE where  ScheduleTime < " + rctime.ToString() +
                            ") " +
                            " select * from cte where row between " + "1" + " and " + "10";
            }
            string res = "";
            BaseService baseservice = new BaseService();
            IList nbhstaff = baseservice.ExecuteSQL(sqlstr);
            List<RiChenginfo> info = new List<RiChenginfo>();
            if (nbhstaff.Count > 0 && nbhstaff != null)
            {
                for (int i = 0; i < nbhstaff.Count; i++)
                {
                    object[] rc = (object[])nbhstaff[i];
                    RiChenginfo ric = new RiChenginfo();

                    ric.RichengId = rc[1].ToString();
                    ric.PersonId = rc[6].ToString();
                    ric.RichengContent = rc[2].ToString();
                    ric.RichengTime = new DateTime(Convert.ToInt64(rc[3])).ToString("yyyy年MM月dd日 HH:mm:ss");
                    WkTUser user = new WkTUser();
                    user = (WkTUser)baseservice.loadEntity(user, Convert.ToInt64(rc[6]));
                    ric.PersonName = user.KuName;
                    ric.PersonDeptName = user.Kdid.KdName.ToString().Trim();
                    ric.RichengSub = rc[4].ToString();
                    ric.ArrangeManId = rc[10].ToString();
                    info.Add(ric);
                }

                RiChengAll l = new RiChengAll();
                l.List = info;
                res = "成功";
                string data = JsonTools.ObjectToJson(l);
                var jsonStr = "{\"Message\":" + "\"" + res + "\"" + "," + "\"data\":" + data + "}";
                var result = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(jsonStr, Encoding.UTF8, "text/json")
                };
                return result;
            }
            else
            {
                res = "没有内容";
                string data = "1";//JsonTools.ObjectToJson(l);
                var jsonStr = "{\"Message\":" + "\"" + res + "\"" + "," + "\"data\":" + data + "}";
                var result = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(jsonStr, Encoding.UTF8, "text/json")
                };
                return result;
            }
        }
        public HttpResponseMessage RiChengYo(string userid,string seeid,string rctime)
        {
            string res = null;
            string sqlstr = null;
            if (rctime == "0")
            {
                sqlstr = "with cte as " +
                            "( " +
                            " select row=row_number()over(order by getdate()), * from dbo.RiCheng where  ScheduleTime > " + rctime.ToString() + "and WkTUserId=" + userid.ToString() +"and SharePersonId="+seeid.ToString()+
                            ") " +
                            " select * from cte where row between " + "1" + " and " + "10";
            }
            else
            {
                sqlstr = "with cte as " +
                            "( " +
                            " select row=row_number()over(order by getdate()), * from dbo.RiCheng where  ScheduleTime < " + rctime.ToString() + "and WkTUserId=" + userid.ToString() + "and SharePersonId=" + seeid.ToString() +
                            ") " +
                            " select * from cte where row between " + "1" + " and " + "10";
            }
            BaseService baseservice = new BaseService();
            IList nbhstaff = baseservice.ExecuteSQL(sqlstr);
            List<RiChenginfo> info = new List<RiChenginfo>();
            if (nbhstaff.Count > 0 && nbhstaff != null)
            {
                for (int i = 0; i < nbhstaff.Count; i++)
                {
                    object[] rc = (object[])nbhstaff[i];
                    RiChenginfo ric = new RiChenginfo();
                    ric.RichengId = rc[9].ToString();//日程Id
                    ric.PersonId = rc[2].ToString();//分享人Id
                    ric.RichengContent = rc[5].ToString();//日程内容
                    ric.RichengTime = new DateTime(Convert.ToInt64(rc[4])).ToString("yyyy年MM月dd日 HH:mm:ss");//分享时间
                    ric.RemindTime = new DateTime(Convert.ToInt64(rc[7])).ToString("yyyy年MM月dd日 HH:mm:ss");//提醒时间
                    WkTUser user = new WkTUser();
                    user = (WkTUser)baseservice.loadEntity(user, Convert.ToInt64(rc[3]));
                    ric.PersonName = user.KuName;//分享人姓名
                    ric.PersonDeptName = user.Kdid.KdName.ToString();//分享人部门
                    ric.RichengSub = rc[6].ToString();//日程主题

                    ric.Logtick = rc[4].ToString();
                    //ric.Contenttxt140 = HtmlToReguFormat140(rc[2].ToString());//日志内容去格式前140

                    ric.TimeTick = rc[4].ToString();
                    ric.ArrangeManId = rc[11].ToString();
                    info.Add(ric);
                }

                RiChengAll l = new RiChengAll();
                l.List = info;
                res = "成功";
                string data = JsonTools.ObjectToJson(l);
                var jsonStr = "{\"Message\":" + "\"" + res + "\"" + "," + "\"data\":" + data + "}";
                var result = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(jsonStr, Encoding.UTF8, "text/json")
                };
                return result;
            }
            else
            {
                res = "没有内容";
                string data = "1";//JsonTools.ObjectToJson(l);
                var jsonStr = "{\"Message\":" + "\"" + res + "\"" + "," + "\"data\":" + data + "}";
                var result = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(jsonStr, Encoding.UTF8, "text/json")
                };
                return result;
            }
        }
        /// <summary>
        /// 上下级查看分享
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="seeid"></param>
        /// <param name="rctime"></param>
        /// <returns></returns>
        public HttpResponseMessage GetRiCheng2(string userid, string seeid, string rctime)
        {
            string res = "";
            string sql1 = "select u from WkTUser u where u.KuName='" + userid + "'";
            string sql2 = "select u from WkTUser u where u.Id='" + seeid + "'";
            string sql3 = "select u.DeptId from Wktuser_M_Dept u where u.WktuserId=" + userid + " and u.State = " + (int)IEntity.stateEnum.Normal;
            BaseService baseservice = new BaseService();
            List<WkTDept> theDepts = new List<WkTDept>();
            IList theone = baseservice.loadEntityList(sql3);
            if (theone != null && theone.Count > 0)
            {
                List<RiChenginfo> rlist = new List<RiChenginfo>();
                WkTUser user = new WkTUser();
                user = (WkTUser)baseservice.loadEntity(user, Convert.ToInt64(seeid));
                string m = user.Kdid.Id.ToString();
                int flog = 1;
                for (int i = 0; i < theone.Count; i++)
                {

                    string a = "";
                    a = ((WkTDept)theone[i]).Id.ToString();
                    if (a == m)
                    {
                        flog = 0;
                        string sqlstr = "";
                        if (rctime == "0")
                        {
                            sqlstr = "with cte as " +
                                        "( " +
                                        " select row=row_number()over(order by getdate()), * from LOG_T_STAFFSCHEDULE where WktUserId=" + seeid.ToString() + " and ScheduleTime > " + rctime.ToString() +
                                        ") " +
                                        " select * from cte where row between " + "1" + " and " + "10";
                        }
                        else
                        {
                            sqlstr = "with cte as " +
                                        "( " +
                                        " select row=row_number()over(order by getdate()), * from LOG_T_STAFFSCHEDULE where WktUserId=" + seeid.ToString() + " and ScheduleTime < " + rctime.ToString() +
                                        ") " +
                                        " select * from cte where row between " + "1" + " and " + "10";
                        }
                        IList one = baseservice.ExecuteSQL(sqlstr);

                        if (one != null && one.Count > 0)
                        {
                            for (int j = 0; j < one.Count; j++)
                            {
                                object[] sf = (object[])one[j];
                                RiChenginfo st = new RiChenginfo();
                                //// Personinfo p = new Personinfo();
                                st.PersonId = sf[6].ToString();//分享人的ID

                                WkTUser user1 = new WkTUser();
                                user1 = (WkTUser)baseservice.loadEntity(user1, Convert.ToInt64(st.PersonId));
                                st.PersonName = user1.KuName;//分享人的姓名
                                //long mm = user1.Kdid.Id;
                                WkTDept dept = new WkTDept();
                                dept = (WkTDept)baseservice.loadEntity(dept, Convert.ToInt64(m));
                                st.PersonDeptName = dept.KdName;//分享人的部门
                                st.Logtick = sf[3].ToString();
                                st.RichengTime = new DateTime(Convert.ToInt64(sf[3].ToString())).ToString("yyyy年MM月dd日 HH:mm:ss");//日程时间
                                st.RichengId = sf[1].ToString(); //日程id
                                st.RemindTime = new DateTime(Convert.ToInt64(sf[9].ToString())).ToString("yyyy年MM月dd日 HH:mm:ss");//提醒时间
                                st.RichengContent=sf[2].ToString();//日程内容
                                st.RichengSub=sf[4].ToString();//日程主题
                                st.ArrangeManId = sf[10].ToString();
                                st.TimeTick = sf[3].ToString();

                                rlist.Add(st);
                            }
                        }
                    }
                }
                RiChengAll l = new RiChengAll();
                l.List = rlist;
                res = "成功";
                string data = JsonTools.ObjectToJson(l);
                var jsonStr = "{\"Message\":" + "\"" + res + "\"" + "," + "\"data\":" + data + "}";
                var result = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(jsonStr, Encoding.UTF8, "text/json")
                };
                return result;

                if (flog == 1)
                {
                    return RiChengYo(userid, seeid, rctime);

                }
            }
            else
            {
                return RiChengYo(userid, seeid, rctime);

            }
        }
        public HttpResponseMessage addRicheng([FromBody]jd jdata)
        {
            BaseService baseService = new BaseService();

            string res = "";

            string json = jdata.jsondata;
            JavaScriptSerializer js = new JavaScriptSerializer();
            RiChengData list = js.Deserialize<RiChengData>(json);

            try
            {

                WkTUser ww = new WkTUser();
                ww = (WkTUser)baseService.loadEntity(ww, long.Parse(list.Uid));

                List<WkTUser> sharedUser = new List<WkTUser>();

                foreach (PersonInfo p in list.Sharelist)
                {

                    WkTUser w = new WkTUser();
                    w = (WkTUser)baseService.loadEntity(w, long.Parse(p.Id));

                    sharedUser.Add(w);
                }

                StaffSchedule staffSchedule = new StaffSchedule();
                staffSchedule.IfRemind = list.Isre ? (int)StaffSchedule.IfRemindEnum.Renmind : (int)StaffSchedule.IfRemindEnum.NotRemind;
                //会议时间
                staffSchedule.ScheduleTime = (DateTime.Parse(list.Dotime)).Ticks; //this.dateTimePicker2.Value.Ticks;//scheduleDate.Date.Ticks + dateTimePicker1.Value.TimeOfDay.Ticks;
                //提醒时间
                staffSchedule.RemindTime = (DateTime.Parse(list.Retime)).Ticks;//this.dateTimePicker1.Value.Ticks;//scheduleDate.Date.Ticks + dateTimePicker2.Value.TimeOfDay.Ticks;
                staffSchedule.Staff = ww;
                staffSchedule.StaffScheduleStaffs = sharedUser;
                staffSchedule.Subject = list.Title;
                staffSchedule.TimeStamp = DateTime.Now.Ticks;
                staffSchedule.State = (int)IEntity.stateEnum.Normal;
                staffSchedule.Content = list.Content;
                staffSchedule.ArrangeMan = ww;//user;

                baseService.SaveOrUpdateEntity(staffSchedule);

                res = "成功";
                string data = "1"; //JsonTools.ObjectToJson(list); //jdata.jsondata;//ss.Content;//JsonTools.ObjectToJson(ss);
                var jsonStr = "{\"Message\":" + "\"" + res + "\"" + "," + "\"data\":" + data + "}";
                var result = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(jsonStr, Encoding.UTF8, "text/json")
                };
                return result;

            }
            catch(Exception ex)
            {
                res = ex.Message;
                string data = "1"; //JsonTools.ObjectToJson(list); //jdata.jsondata;//ss.Content;//JsonTools.ObjectToJson(ss);
                var jsonStr = "{\"Message\":" + "\"" + res + "\"" + "," + "\"data\":" + data + "}";
                var result = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(jsonStr, Encoding.UTF8, "text/json")
                };
                return result;

            }
        }
        /// <summary>
        /// 获得自己的日程
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="rctime"></param>
        /// <returns></returns>
        public HttpResponseMessage GetOwnRiCheng(string userid, string rctime)
        {
            string res = "";
            string data = "1";

            BaseService baseservice = new BaseService();
            //List<RCDayBag> list = new List<RCDayBag>();
            RCDayBagList rrll = new RCDayBagList();

            long startick;
            long endtick;

            if (rctime == "0")
            {
                string fstr = "select top 1 LOG_T_STAFFSCHEDULE.ScheduleTime  from LOG_T_STAFFSCHEDULE  where WkTUserId = " + userid + " and STATE = 0 order by LOG_T_STAFFSCHEDULE.ScheduleTime desc";

                IList firres = baseservice.ExecuteSQL(fstr);

                object[] obj;
                if (firres != null && firres.Count > 0)
                {
                    obj  = (object[])firres[0];
                    DateTime d = new DateTime(long.Parse(obj[0].ToString()));
                    string str = d.ToString("yyyy-MM-dd");
                    long daytick = d.Date.Ticks;
                    startick = d.AddDays(1).Ticks;//daytick;
                    endtick = d.Date.Ticks;

                    for (int i = 0; i < 10; i++)
                    {

                        RCDayBag rdb1 = new RCDayBag();
                        rdb1.DayString = str;
                        rdb1.DayTick = daytick.ToString();

                        string sql1 = "with cte as " +
                            "( " +
                            " select row=row_number()over(order by LOG_T_STAFFSCHEDULE.ScheduleTime DESC ), * from LOG_T_STAFFSCHEDULE where  ScheduleTime < " + startick.ToString() + " and ScheduleTime > " + endtick.ToString() + "  and  WkTUserId=" + userid.ToString() +
                            ") " +
                            " select * from cte ";
                        //where row between " + "1" + " and " + "10";

                        IList nbhstaff1 = baseservice.ExecuteSQL(sql1);

                        //List<RiChenginfo> info = new List<RiChenginfo>();
                        if (nbhstaff1.Count > 0 && nbhstaff1 != null)
                        {
                            long tick2 = 0;
                            for (int i1 = 0; i1 < nbhstaff1.Count; i1++)
                            {
                                object[] rc = (object[])nbhstaff1[i1];
                                RiChenginfo ric = new RiChenginfo();

                                ric.RichengId = rc[1].ToString();
                                ric.PersonId = rc[6].ToString();
                                ric.RichengContent = rc[2].ToString();
                                ric.RichengTime = new DateTime(Convert.ToInt64(rc[3])).ToString("yyyy年MM月dd日 HH:mm:ss");
                                WkTUser user = new WkTUser();
                                user = (WkTUser)baseservice.loadEntity(user, Convert.ToInt64(rc[6]));
                                ric.PersonName = user.KuName;
                                ric.PersonDeptName = user.Kdid.KdName.ToString().Trim();
                                ric.RichengSub = rc[4].ToString();
                                ric.ArrangeManId = rc[10].ToString();
                                ric.TimeTick = rc[3].ToString();
                                ric.DoState = getDostate(rc[3].ToString(), rc[11]);//rc[11] == null ? rc[11].ToString() : "null";
                                ric.IsRemind = rc[5].ToString();

                                    ric.RemindTime = new DateTime(Convert.ToInt64(rc[9])).ToString("yyyy年MM月dd日 HH:mm:ss");

                                rdb1.RichengDayList.Add(ric);

                                //info.Add(ric);
                                tick2 = long.Parse(rc[3].ToString());

                            }
                            rrll.List.Add(rdb1);
                            //list.Add(rdb1);
                            //rdb1.RichengDayList = info;
                            string str2 = "select top 1 LOG_T_STAFFSCHEDULE.ScheduleTime  from LOG_T_STAFFSCHEDULE  where WkTUserId = " + userid + " and STATE = 0 and ScheduleTime < " + tick2.ToString() + " order by LOG_T_STAFFSCHEDULE.ScheduleTime desc";
                            IList firtick2 = baseservice.ExecuteSQL(str2);

                            if (firtick2 != null && firtick2.Count > 0)
                            {
                                object[] obj2 = (object[])firtick2[0];
                                DateTime d2 = new DateTime(long.Parse(obj2[0].ToString()));

                                str = d2.ToString("yyyy-MM-dd");
                                daytick = d2.Date.Ticks;
                                startick = d2.AddDays(1).Ticks;
                                endtick = daytick;// d2.AddDays(-1).Ticks;

                            }
                            else
                            {
                                break;

                            }

                        }
                        else
                        {

                            break;

                        }

                    }

                    res = "成功";
                    //RCDayBagList rl = new RCDayBagList();
                    //rl.List = list;
                    data = JsonTools.ObjectToJson(rrll);

                }
                else
                {

                    res = "没有内容";
                    data = "1";

                }

                var jsonStr = "{\"Message\":" + "\"" + res + "\"" + "," + "\"data\":" + data + "}";
                var result = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(jsonStr, Encoding.UTF8, "text/json")
                };

                return result;
            }
            else
            {

                DateTime d = new DateTime(long.Parse(rctime));
                string str = d.ToString("yyyy-MM-dd");

                long daytick = 0;//d.Date.Ticks;
                startick = 0;// d.AddDays(1).Ticks;//daytick;
                endtick = 0;// d.Date.Ticks;

                string str3 = "select top 1 LOG_T_STAFFSCHEDULE.ScheduleTime  from LOG_T_STAFFSCHEDULE  where WkTUserId = " + userid + " and STATE = 0 and ScheduleTime < " + rctime.ToString() + " order by LOG_T_STAFFSCHEDULE.ScheduleTime desc";
                IList firtick3 = baseservice.ExecuteSQL(str3);

                if (firtick3 != null && firtick3.Count > 0)
                {
                    object[] obj3 = (object[])firtick3[0];

                    DateTime d3 = new DateTime(long.Parse(obj3[0].ToString()));

                    str = d3.ToString("yyyy-MM-dd");
                    daytick = d3.Date.Ticks;
                    startick = d3.AddDays(1).Ticks;
                    endtick = daytick;// d2.AddDays(-1).Ticks;
                }
                else
                {

                    res = "没有内容";
                    data = "1";

                    var jsonStr1 = "{\"Message\":" + "\"" + res + "\"" + "," + "\"data\":" + data + "}";
                    var result1 = new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new StringContent(jsonStr1, Encoding.UTF8, "text/json")
                    };

                    return result1;

                }

                for (int i = 0; i < 10; i++)
                {

                    RCDayBag rdb1 = new RCDayBag();
                    rdb1.DayString = str;
                    rdb1.DayTick = daytick.ToString();

                    string sql1 = "with cte as " +
                        "( " +
                        " select row=row_number()over(order by LOG_T_STAFFSCHEDULE.ScheduleTime DESC ), * from LOG_T_STAFFSCHEDULE where  ScheduleTime < " + startick.ToString() + " and ScheduleTime > " + endtick.ToString() + "  and  WkTUserId=" + userid.ToString() +
                        ") " +
                        " select * from cte ";
                    //where row between " + "1" + " and " + "10";

                    IList nbhstaff1 = baseservice.ExecuteSQL(sql1);

                    //List<RiChenginfo> info = new List<RiChenginfo>();
                    if (nbhstaff1.Count > 0 && nbhstaff1 != null)
                    {
                        long tick2 = 0;
                        for (int i1 = 0; i1 < nbhstaff1.Count; i1++)
                        {
                            object[] rc = (object[])nbhstaff1[i1];
                            RiChenginfo ric = new RiChenginfo();

                            ric.RichengId = rc[1].ToString();
                            ric.PersonId = rc[6].ToString();
                            ric.RichengContent = rc[2].ToString();
                            ric.RichengTime = new DateTime(Convert.ToInt64(rc[3])).ToString("yyyy年MM月dd日 HH:mm:ss");
                            WkTUser user = new WkTUser();
                            user = (WkTUser)baseservice.loadEntity(user, Convert.ToInt64(rc[6]));
                            ric.PersonName = user.KuName;
                            ric.PersonDeptName = user.Kdid.KdName.ToString().Trim();
                            ric.RichengSub = rc[4].ToString();
                            ric.ArrangeManId = rc[10].ToString();
                            ric.DoState = getDostate(rc[3].ToString(), rc[11]);//rc[11]==null?rc[11].ToString():"null";
                            ric.TimeTick = rc[3].ToString();
                            //info.Add(ric);
                            rdb1.RichengDayList.Add(ric);

                            tick2 = long.Parse(rc[3].ToString());

                        }
                        //rdb1.RichengDayList = info;
                        rrll.List.Add(rdb1);
                        string str2 = "select top 1 LOG_T_STAFFSCHEDULE.ScheduleTime  from LOG_T_STAFFSCHEDULE  where WkTUserId = " + userid + " and STATE = 0 and ScheduleTime < " + tick2.ToString() + " order by LOG_T_STAFFSCHEDULE.ScheduleTime desc";
                        IList firtick2 = baseservice.ExecuteSQL(str2);

                        if (firtick2 != null && firtick2.Count > 0)
                        {
                            object[] obj = (object[])firtick2[0];
                            DateTime d2 = new DateTime(long.Parse(obj[0].ToString()));

                            str = d2.ToString("yyyy-MM-dd");
                            daytick = d2.Date.Ticks;
                            startick = d2.AddDays(1).Ticks;
                            endtick = daytick;// d2.AddDays(-1).Ticks;

                        }
                        else
                        {
                            break;

                        }

                    }
                    else
                    {

                        break;

                    }

                    //list.Add(rdb1);

                }

                res = "成功";
                //RCDayBagList rl = new RCDayBagList();
                //rl.List = list;
                data = JsonTools.ObjectToJson(rrll);

                //}
                //else
                //{

                //    res = "没有内容";
                //    data = "1";

                //}

                var jsonStr = "{\"Message\":" + "\"" + res + "\"" + "," + "\"data\":" + data + "}";
                var result = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(jsonStr, Encoding.UTF8, "text/json")
                };

                return result;

            }

            //string sqlstr = null;
            //if (rctime == "0")
            //{
            //    sqlstr = "with cte as " +
            //                "( " +
            //                " select row=row_number()over(order by getdate()), * from LOG_T_STAFFSCHEDULE where  ScheduleTime > " + rctime.ToString() + "and WkTUserId=" + userid.ToString() +
            //                ") " +
            //                " select * from cte where row between " + "1" + " and " + "10";
            //}
            //else
            //{
            //    sqlstr = "with cte as " +
            //                "( " +
            //                " select row=row_number()over(order by getdate()), * from LOG_T_STAFFSCHEDULE where  ScheduleTime < " + rctime.ToString() + "and WkTUserId=" + userid.ToString() +
            //                ") " +
            //                " select * from cte where row between " + "1" + " and " + "10";
            //}

            //IList nbhstaff = baseservice.ExecuteSQL(sqlstr);
            //List<RiChenginfo> info = new List<RiChenginfo>();
            //if (nbhstaff.Count > 0 && nbhstaff != null)
            //{
            //    for (int i = 0; i < nbhstaff.Count; i++)
            //    {
            //        object[] rc = (object[])nbhstaff[i];
            //        RiChenginfo ric = new RiChenginfo();

            //        ric.RichengId = rc[1].ToString();
            //        ric.PersonId = rc[6].ToString();
            //        ric.RichengContent = rc[2].ToString();
            //        ric.RichengTime = new DateTime(Convert.ToInt64(rc[3])).ToString("yyyy年MM月dd日 HH:mm:ss");
            //        WkTUser user = new WkTUser();
            //        user = (WkTUser)baseservice.loadEntity(user, Convert.ToInt64(rc[6]));
            //        ric.PersonName = user.KuName;
            //        ric.PersonDeptName = user.Kdid.KdName.ToString().Trim();
            //        ric.RichengSub = rc[4].ToString();
            //        ric.ArrangeManId = rc[10].ToString();
            //        ric.TimeTick = rc[3].ToString();
            //        info.Add(ric);
            //    }

            //    RiChengAll l = new RiChengAll();
            //    l.List = info;
            //    res = "成功";
            //    data = JsonTools.ObjectToJson(l);
            //    var jsonStr = "{\"Message\":" + "\"" + res + "\"" + "," + "\"data\":" + data + "}";
            //    var result = new HttpResponseMessage(HttpStatusCode.OK)
            //    {
            //        Content = new StringContent(jsonStr, Encoding.UTF8, "text/json")
            //    };
            //    return result;
            //}
            //else
            //{
            //    res = "没有内容";
            //    data = "1";//JsonTools.ObjectToJson(l);
            //    var jsonStr = "{\"Message\":" + "\"" + res + "\"" + "," + "\"data\":" + data + "}";
            //    var result = new HttpResponseMessage(HttpStatusCode.OK)
            //    {
            //        Content = new StringContent(jsonStr, Encoding.UTF8, "text/json")
            //    };
            //    return result;
            //}
        }