Exemplo n.º 1
0
        /// <summary>
        /// 取得部門員工資料
        /// </summary>
        /// <param name="deptID"></param>
        /// <param name="deptAbbreviate"></param>
        /// <param name="deptName"></param>
        /// <param name="sort"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        public static List <DeptDataEntity> GetUserNameData(string deptID = null, string deptAbbreviate = null, string deptName = null, string sort = null, string order = null)
        {
            var strSQL = @"
                    SELECT * FROM LBOM_DEPT D JOIN LBOM_LOGIN_USER U
                    ON D.DEPTID = U.DEPTID
                    WHERE DEPTABBREVIATE = ISNULL(@DEPTABBREVIATE, DEPTABBREVIATE)
                    AND DEPTNAME= ISNULL(@DEPTNAME, DEPTNAME)
                    AND D.DEPTID=ISNULL(@DEPTID, D.DEPTID)
            ";

            deptAbbreviate = string.IsNullOrEmpty(deptAbbreviate) ? null : deptAbbreviate;
            deptName       = string.IsNullOrEmpty(deptName) ? null : deptName;

            if (!string.IsNullOrEmpty(sort) && !string.IsNullOrEmpty(order))
            {
                strSQL += string.Format("ORDER BY {0} {1} ", sort, order);
            }

            SqlParameter[] parms =
            {
                new SqlParameter("@DEPTABBREVIATE", (object)deptAbbreviate ?? DBNull.Value),
                new SqlParameter("@DEPTNAME",       (object)deptName ?? DBNull.Value),
                new SqlParameter("@DEPTID",         (object)deptID ?? DBNull.Value)
            };

            //var lst = ReadData<ProductDataEntity>(strSQL, parms);
            //-----------------------------------------------------------------------------
            var lst = new List <DeptDataEntity>();

            using (var conn = new SqlConnection(ConnectionString))
                using (var cmd = new SqlCommand(strSQL, conn))
                {
                    cmd.Parameters.AddRange(parms);
                    conn.Open();
                    using (var dp = cmd.ExecuteReader())
                    {
                        if (dp.HasRows)
                        {
                            while (dp.Read())
                            {
                                DeptDataEntity dept = new DeptDataEntity()
                                {
                                    deptID         = dp["deptID"].ToString(),
                                    deptAbbreviate = dp["deptAbbreviate"].ToString(),
                                    deptName       = dp["deptName"].ToString(),
                                    loginuserName  = dp["loginuserName"].ToString()
                                };
                                lst.Add(dept);
                            }
                            //Mapper.CreateMap<IDataReader, LoginUserInfoDataEntity>();
                            //user = Mapper.Map<IDataReader, IList<LoginUserInfoDataEntity>>(dr).ToList().First();
                        }
                    }
                }
            return(lst);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 新增部門資料
        /// </summary>
        /// <param name="uData"></param>
        /// <returns></returns>
        public string NewDeptData(DeptDataEntity uData)
        {
            uData.deptID = Guid.NewGuid().ToString();
            var depts = new List <DeptDataEntity>()
            {
                uData
            };

            DeptDataAccess.AddDeptData(depts);

            return(JsonConvert.SerializeObject(new { success = true, errorMsg = "" }));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 修改部門資料
        /// </summary>
        /// <param name="uData"></param>
        /// <returns></returns>
        public string EditDeptData(DeptDataEntity uData)
        {
            var depts = new List <DeptDataEntity>()
            {
                uData
            };

            var errorMsg  = string.Empty;
            var isSuccess = true;

            try { DeptDataAccess.UpdateDeptData(depts); }
            catch (Exception ex)
            {
                isSuccess = false;
                errorMsg  = ex.Message.Replace("\n", "");
            }

            return(JsonConvert.SerializeObject(new { success = isSuccess, errorMsg = errorMsg }));
        }