Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="area"></param>
        /// <param name="username"></param>
        /// <param name=""></param>
        /// <returns></returns>
        public DataTable getAllEmployee(string area, string username = "", bool isShowNum = false, string hasOrder = "")
        {
            DataTable dt       = GetList(0, area, false);
            string    sqlwhere = "";

            if (!string.IsNullOrEmpty(username))
            {
                sqlwhere = " and (user_name like '%" + username + "%' or real_name like '%" + username + "%')";
            }
            DataSet ds = new BLL.manager().GetList(" is_lock=0 " + sqlwhere + "");

            if (!string.IsNullOrEmpty(username))
            {
                DataTable nDt = dt.Clone();
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        filerData(dt, nDt, Utils.ObjToInt(ds.Tables[0].Rows[i]["departID"], 0));
                    }
                    //保持原有顺序
                    DataTable newDT1 = nDt.Clone();
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DataRow[] ndr = nDt.Select("de_id = " + dt.Rows[i]["de_id"] + "");
                        if (ndr != null && ndr.Length > 0)
                        {
                            DataRow row = newDT1.NewRow(); //创建新行
                                                           //循环查找列数量赋值
                            for (int j = 0; j < dt.Columns.Count; j++)
                            {
                                row[dt.Columns[j].ColumnName] = dt.Rows[i][dt.Columns[j].ColumnName];
                            }
                            newDT1.Rows.Add(row);
                        }
                    }
                    dt = newDT1;
                }
                else
                {
                    return(null);
                }
            }

            DataTable newDT = dt.Clone();

            newDT.Columns.Add("detailDepart");
            if (dt != null)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    DataRow ndr = newDT.NewRow();
                    //循环查找列数量赋值
                    for (int j = 0; j < dr.Table.Columns.Count; j++)
                    {
                        ndr[dr.Table.Columns[j].ColumnName] = dr[dr.Table.Columns[j].ColumnName];
                    }
                    newDT.Rows.Add(ndr);
                    DataRow[] drs = ds.Tables[0].Select("departID=" + dr["de_id"] + "");
                    foreach (DataRow drr in drs)
                    {
                        ndr = newDT.NewRow();
                        ndr["de_parentid"]  = dr["de_id"];
                        ndr["de_type"]      = "4";
                        ndr["de_area"]      = drr["area"];
                        ndr["de_subname"]   = drr["user_name"];
                        ndr["de_name"]      = drr["real_name"];
                        ndr["detailDepart"] = drr["detaildepart"];
                        ndr["class_layer"]  = Convert.ToInt32(dr["class_layer"]) + 1;
                        newDT.Rows.Add(ndr);
                    }
                }
            }
            //显示人员的订单数量
            DataTable lastDT = newDT.Copy();

            lastDT.Columns.Add("orderCount");
            if (isShowNum)
            {
                DataTable orderNumDT = new BLL.Order().getAllDStatusOrder(hasOrder);
                foreach (DataRow dr in lastDT.Rows)
                {
                    dr["orderCount"] = "0";
                    if (Utils.ObjectToStr(dr["de_type"]) == "4")
                    {
                        DataRow[] drs = orderNumDT.Select("op_number='" + dr["de_subname"] + "' and op_name='" + dr["de_name"] + "'");
                        if (drs != null && drs.Length > 0)
                        {
                            dr["orderCount"] = Utils.ObjectToStr(drs[0]["ordernum"]);
                        }
                    }
                }
            }
            return(lastDT);
        }