using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Collections;
namespace BLL
{
    /// 
    /// 工种表
    /// 
   public static class PostService
    {
       public static Model.SGGLDB db = Funs.DB;
       /// 
       /// 记录数
       /// 
       private static int count
       {
           get;
           set;
       }
       /// 
       /// 获取分页列表
       /// 
       /// 
       /// 
       /// 
       /// 
       public static IEnumerable GetListData(string postName, int startRowIndex, int maximumRows)
       {
           IQueryable q = from x in db.Base_Post orderby x.PostName select x;
           if (!string.IsNullOrEmpty(postName))
           {
               q = q.Where(e => e.PostName.Contains(postName));
           }
           count = q.Count();
           if (count==0)
           {
               return new object[] { "" };
           }
           return from x in q.Skip(startRowIndex).Take(maximumRows)
                  select new
                  {
                      x.PostId,
                      x.PostName,
                      x.Remark
                  };
       }
       /// 
       /// 获取分页列表数
       /// 
       /// 
       /// 
       public static int GetListCount(string postName)
       {
           return count;
       }
       /// 
       /// 根据主键获取岗位信息
       /// 
       /// 
       /// 
       public static Model.Base_Post GetPostById(string postId)
       {
           return Funs.DB.Base_Post.FirstOrDefault(e => e.PostId == postId);
       }
       /// 
       /// 添加工种信息
       /// 
       /// 
       public static void AddPost(Model.Base_Post post)
       {
           Model.SGGLDB db = Funs.DB;
           Model.Base_Post newPost = new Model.Base_Post();
           newPost.PostId = post.PostId;
           newPost.PostName = post.PostName;
           newPost.Remark = post.Remark;
           db.Base_Post.InsertOnSubmit(newPost);
           db.SubmitChanges();
       }
       /// 
       /// 修改工种信息
       /// 
       /// 
       public static void UpdatePost(Model.Base_Post post)
       {
           Model.SGGLDB db = Funs.DB;
           Model.Base_Post newPost = db.Base_Post.FirstOrDefault(e => e.PostId == post.PostId);
           if (newPost != null)
           {
               newPost.PostName = post.PostName;
               newPost.Remark = post.Remark;
               db.SubmitChanges();
           }
       }
       /// 
       /// 根据主键删除工种信息
       /// 
       /// 
       public static void DeletePost(string postId)
       {
           Model.SGGLDB db = Funs.DB;
           Model.Base_Post newPost = db.Base_Post.FirstOrDefault(e => e.PostId == postId);
           if (newPost != null)
           {
               db.Base_Post.DeleteOnSubmit(newPost);
               db.SubmitChanges();
           }
       }
        public static string GetPostNameById(string postId)
        {
            string name = string.Empty;
            var q = Funs.DB.Base_Post.FirstOrDefault(e => e.PostId == postId);
            if (q != null)
            {
                name = q.PostName;
            }
            return name;
        }
        /// 
        ///  获取工种名称项
        /// 
        /// 
        /// 
        public static ListItem[] drpPostNameItemList()
       {
           var q = (from x in Funs.DB.Base_Post orderby x.PostName select x).ToList();
           ListItem[] list = new ListItem[q.Count()];
           for (int i = 0; i < list.Count(); i++)
           {
               list[i] = new ListItem(q[i].PostName ?? "", q[i].PostId);
           }
           return list;
       }
        public static void InitPostDownList(FineUIPro.DropDownList dropName, bool isShowPlease)
        {
            dropName.DataValueField = "Value";
            dropName.DataTextField = "Text";
            dropName.DataSource = drpPostNameItemList();
            dropName.DataBind();
            if (isShowPlease)
            {
                Funs.FineUIPleaseSelect(dropName);
            }
        }
    }
}