protected void btnAdd_Click(object sender, EventArgs e)
    {
        var org = GetOrg(PageUtility.User);

        if (org == null)
        {
            return;
        }

        try
        {
            if (string.IsNullOrEmpty(Request["id"]))
            {
                _bll.AddOrganization(org);
            }
            else
            {
                _bll.ModifyOrganization(org);
            }
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
            return;
        }

        Response.Redirect("OrganizationManager.aspx");
    }
Exemple #2
0
        public ActionResult AddOrganization(Organizations organization)
        {
            Users users = Session["Login"] as Users;

            organization.UserID = users.UserID;

            organizationBLL.AddOrganization(organization);
            return(RedirectToAction("OrganizationsList", "Organization"));
        }
Exemple #3
0
        // 导入
        private void ImportEmployeeExcel()
        {
            EmployeeBLL           objEmployeeBll       = new EmployeeBLL();
            EmployeeDetailBLL     objEmployeeDetailBll = new EmployeeDetailBLL();
            EmployeeErrorBLL      objErrorBll          = new EmployeeErrorBLL();
            IList <EmployeeError> objErrorList         = new List <EmployeeError>();

            string          orgID  = Request.QueryString.Get("OrgID");
            OrganizationBLL orgBll = new OrganizationBLL();

            RailExam.Model.Organization org = orgBll.GetOrganization(Convert.ToInt32(orgID));
            string strUnitName = org.ShortName;
            string strFileName = Server.UrlDecode(Request.QueryString.Get("FileName"));
            string jsBlock     = string.Empty;
            string strPath     = Server.MapPath("/RailExamBao/Excel/" + strFileName);
            bool   isClose     = false;
            string strMessage;

            objErrorBll.DeleteEmployeeErrorByOrgIDAndImportTypeID(Convert.ToInt32(orgID));

            #region 验证准备工作

            Hashtable htOrg             = GetOrgInfo();
            Hashtable htPost            = GetPostInfo();
            Hashtable htEducationLevel  = GetEducationLevel();
            Hashtable htPoliticalStatus = GetPoliticalStatus();
            Hashtable htShopNeedAdd     = new Hashtable();
            Hashtable htPostNeedAdd     = new Hashtable();
            Hashtable htIdentityCardNo  = new Hashtable();
            Hashtable htERP             = new Hashtable();

            PostBLL   objPostBll     = new PostBLL();
            ArrayList objPostNewList = new ArrayList();

            IList <RailExam.Model.EmployeeDetail> objEmployeeInsert = new List <RailExam.Model.EmployeeDetail>();
            IList <RailExam.Model.EmployeeDetail> objEmployeeUpdate = new List <RailExam.Model.EmployeeDetail>();

            #endregion

            // 获取Excel列头数据
            ISheet sheet = GetSheet(strPath);
            // 验证列头
            DataTable headLine = GetHeadLine(sheet);
            string    error;
            if (!ValidateHeadLine(headLine, out error))
            {
                Response.Write("<script>window.returnValue='" + error + "',window.close();</script>");
                return;
            }
            // 获取Excel数据行信息
            DataTable excelDataRows = GetDataRows(sheet, jsBlock);

            // 遍历、验证、保存

            // 添加滚动条效果
            System.Threading.Thread.Sleep(10);
            jsBlock = "<script>SetPorgressBar('正准备检测Excel数据','0.00'); </script>";
            Response.Write(jsBlock);
            Response.Flush();

            if (excelDataRows.Rows.Count == 0)
            {
                Response.Write("<script>window.returnValue='Excel中没有任何记录,请核对',window.close();</script>");
                return;
            }

            for (int i = 0; i < excelDataRows.Rows.Count; i++)
            {
                // 滚动条效果
                System.Threading.Thread.Sleep(10);
                jsBlock = "<script>SetPorgressBar('正在检测Excel数据','" +
                          ((double)((i + 1) * 100) / (double)excelDataRows.Rows.Count).ToString("0.00") + "'); </script>";
                Response.Write(jsBlock);
                Response.Flush();

                RailExam.Model.EmployeeDetail objEmployee = new RailExam.Model.EmployeeDetail();
                bool    isUpdate = false;
                DataRow dr       = excelDataRows.Rows[i];

                //if (dr["员工ID"] != DBNull.Value && dr["员工ID"].ToString().Trim() != string.Empty)
                //{
                //    isUpdate = false;
                //    try
                //    {
                //        objEmployee.EmployeeID = Convert.ToInt32(dr["员工ID"].ToString().Trim());
                //    }
                //    catch
                //    {
                //        AddError(objErrorList, dr, "员工ID填写错误");
                //        continue;
                //    }
                //}
                //else
                //{
                //    isUpdate = true;
                //}

                // 单位
                if (dr["单位"].ToString().Trim() != strUnitName &&
                    dr["单位"].ToString().Trim().Replace("神华包神铁路有限责任公司", "") != strUnitName)
                {
                    AddError(objErrorList, dr, "单位填写错误");
                    continue;
                }


                // 部门
                if (dr["部门"].ToString().Trim() == "")
                {
                    AddError(objErrorList, dr, "部门不能为空");
                    continue;
                }

                string strWorkShop = dr["部门"].ToString().Trim();
                if (strWorkShop.IndexOf("包神铁路公司" + strUnitName) >= 0)
                {
                    strWorkShop = dr["部门"].ToString().Trim().Replace("包神铁路公司" + strUnitName, "");
                }

                //组织机构
                string strOrg;
                if (dr["员工组"].ToString().Trim() == string.Empty)
                {
                    strOrg = strUnitName + "-" + strWorkShop;
                }
                else
                {
                    strOrg = strUnitName + "-" + strWorkShop + "-" + dr["员工组"].ToString().Trim();
                }
                // 判断上面拼接的字符串是否存在于组织机构中
                if (!htOrg.ContainsKey(strOrg))
                {
                    if (dr["员工组"].ToString().Trim() == string.Empty)
                    {
                        if (!htShopNeedAdd.ContainsKey(strWorkShop))
                        {
                            htShopNeedAdd.Add(strWorkShop, new Hashtable());
                        }

                        //如果组织机构需要新增
                        objEmployee.Memo = strOrg;
                    }
                    else
                    {
                        if (!htShopNeedAdd.ContainsKey(strWorkShop))
                        {
                            htShopNeedAdd.Add(strWorkShop, new Hashtable());
                        }

                        Hashtable htGroupNeedAdd = (Hashtable)htShopNeedAdd[strWorkShop];
                        if (!htGroupNeedAdd.ContainsKey(dr["员工组"].ToString().Trim()))
                        {
                            htGroupNeedAdd.Add(dr["员工组"].ToString().Trim(), dr["员工组"].ToString().Trim());
                            htShopNeedAdd[strWorkShop] = htGroupNeedAdd;
                        }

                        //如果组织机构需要新增
                        objEmployee.Memo = strOrg;
                    }
                }
                else
                {
                    objEmployee.OrgID = Convert.ToInt32(htOrg[strOrg]);
                    objEmployee.Memo  = string.Empty;
                }
                // 姓名
                if (dr["姓名"].ToString().Trim() == string.Empty)
                {
                    AddError(objErrorList, dr, "员工姓名不能为空");
                    continue;
                }
                else
                {
                    if (dr["姓名"].ToString().Trim().Length > 20)
                    {
                        AddError(objErrorList, dr, "员工姓名不能超过20位");
                        continue;
                    }

                    objEmployee.EmployeeName = dr["姓名"].ToString().Trim();
                    objEmployee.PinYinCode   = Pub.GetChineseSpell(dr["姓名"].ToString().Trim());
                }

                //身份证件号
                if (dr["身份证件号"].ToString().Trim() == string.Empty && dr["员工编码"].ToString().Trim() == string.Empty)
                {
                    AddError(objErrorList, dr, "身份证件号和员工编码不能同时为空");
                    continue;
                }
                else if (dr["身份证件号"].ToString().Trim() != string.Empty)
                {
                    if (dr["员工编码"].ToString().Trim() != string.Empty)
                    {
                        IList <RailExam.Model.Employee> objOldList =
                            objEmployeeBll.GetEmployeeByWhereClause("Work_NO='" + dr["员工编码"].ToString().Trim() + "' and Employee_Name='" + dr["姓名"].ToString().Trim() + "' and Identity_CardNo='" + dr["身份证件号"].ToString().Trim() + "'");
                        if (objOldList.Count > 0)
                        {
                            isUpdate = true;
                            objEmployee.EmployeeID = objOldList[0].EmployeeID;
                        }
                        else
                        {
                            isUpdate = false;
                        }

                        if (!isUpdate)
                        {
                            IList <RailExam.Model.Employee> objNowList = objEmployeeBll.GetEmployeeByWhereClause("Work_NO='" + dr["员工编码"].ToString().Trim() + "'");
                            if (objNowList.Count > 0)
                            {
                                AddError(objErrorList, dr, "员工编码与系统中【" + objNowList[0].OrgName + "的" + objNowList[0].EmployeeName + "】的员工编号重复");
                                continue;
                            }
                        }


                        //员工编码在Excel中不能重复
                        if (htERP.ContainsKey(dr["员工编码"].ToString().Trim()))
                        {
                            AddError(objErrorList, dr, "员工编码在Excel中与序号为" + htERP[dr["员工编码"].ToString().Trim()] + "的员工编码重复");
                            continue;
                        }
                        else
                        {
                            htERP.Add(dr["员工编码"].ToString().Trim(), dr["序号"].ToString().Trim());
                        }

                        objEmployee.WorkNo = dr["员工编码"].ToString().Trim();
                    }
                    else
                    {
                        IList <RailExam.Model.Employee> objOldList =
                            objEmployeeBll.GetEmployeeByWhereClause("Employee_Name='" + dr["姓名"].ToString().Trim() + "' and Identity_CardNo='" + dr["身份证件号"].ToString().Trim() + "'");
                        if (objOldList.Count > 0)
                        {
                            isUpdate = true;
                            objEmployee.EmployeeID = objOldList[0].EmployeeID;
                        }
                        else
                        {
                            isUpdate = false;
                        }
                    }

                    if (dr["身份证件号"].ToString().Trim().Length > 18)
                    {
                        AddError(objErrorList, dr, "身份证件号不能超过18位");
                        continue;
                    }

                    //身份证件号在Excel中不能重复
                    if (htIdentityCardNo.ContainsKey(dr["身份证件号"].ToString().Trim()))
                    {
                        AddError(objErrorList, dr, "身份证件号在Excel中与序号为" + htIdentityCardNo[dr["身份证件号"].ToString().Trim()] + "的身份证件号重复");
                        continue;
                    }
                    else
                    {
                        htIdentityCardNo.Add(dr["身份证件号"].ToString().Trim(), dr["序号"].ToString().Trim());
                    }


                    IList <RailExam.Model.Employee> objList =
                        objEmployeeBll.GetEmployeeByWhereClause("identity_CardNo='" + dr["身份证件号"].ToString().Trim() + "'");
                    if (objList.Count > 0)
                    {
                        if (isUpdate)
                        {
                            if (objList.Count > 1)
                            {
                                AddError(objErrorList, dr, "与该员工身份证件号完全相同的员工已经存在");
                                continue;
                            }
                        }
                        else
                        {
                            AddError(objErrorList, dr, "该员工身份证件号与【" + objList[0].OrgName + "】中【" + objList[0].EmployeeName + "】的身份证件号完全相同");
                            continue;
                        }
                    }

                    objEmployee.IdentifyCode = dr["身份证件号"].ToString().Trim();
                }
                else if (dr["身份证件号"].ToString().Trim() == string.Empty)
                {
                    IList <RailExam.Model.Employee> objOldList =
                        objEmployeeBll.GetEmployeeByWhereClause("Work_NO='" + dr["员工编码"].ToString().Trim() + "' and Employee_Name='" + dr["姓名"].ToString().Trim() + "'");
                    if (objOldList.Count > 0)
                    {
                        isUpdate = true;
                        objEmployee.EmployeeID = objOldList[0].EmployeeID;
                    }
                    else
                    {
                        isUpdate = false;
                    }

                    //员工编码在Excel中不能重复
                    if (htERP.ContainsKey(dr["员工编码"].ToString().Trim()))
                    {
                        AddError(objErrorList, dr, "员工编码在Excel中与序号为" + htERP[dr["员工编码"].ToString().Trim()] + "的员工编码重复");
                        continue;
                    }
                    else
                    {
                        htERP.Add(dr["员工编码"].ToString().Trim(), dr["序号"].ToString().Trim());
                    }

                    objEmployee.WorkNo = dr["员工编码"].ToString().Trim();
                }

                //性别
                if (dr["性别"].ToString().Trim() != "男" && dr["性别"].ToString().Trim() != "女")
                {
                    AddError(objErrorList, dr, "性别必须为男或女");
                    continue;
                }
                else
                {
                    objEmployee.Sex = dr["性别"].ToString().Trim();
                }
                //籍贯
                if (dr["籍贯"].ToString().Trim().Length > 20)
                {
                    AddError(objErrorList, dr, "籍贯不能超过20位");
                    continue;
                }
                else
                {
                    objEmployee.NativePlace = dr["籍贯"].ToString().Trim();
                }
                //最高学历
                if (dr["最高学历"].ToString().Trim() == string.Empty)
                {
                    AddError(objErrorList, dr, "最高学历不能为空");
                    continue;
                }
                else
                {
                    if (!htEducationLevel.ContainsKey(dr["最高学历"].ToString().Trim()))
                    {
                        AddError(objErrorList, dr, "最高学历在系统中不存在");
                        continue;
                    }
                    else
                    {
                        objEmployee.EducationLevelID = Convert.ToInt32(htEducationLevel[dr["最高学历"].ToString().Trim()]);
                    }
                }
                //政治面貌
                if (dr["政治面貌"].ToString().Trim() != string.Empty)
                {
                    if (!htPoliticalStatus.ContainsKey(dr["政治面貌"].ToString().Trim()))
                    {
                        AddError(objErrorList, dr, "政治面貌在系统中不存在");
                        continue;
                    }
                    else
                    {
                        objEmployee.PoliticalStatusID = Convert.ToInt32(htPoliticalStatus[dr["政治面貌"].ToString().Trim()]);
                    }
                }
                else
                {
                    objEmployee.PoliticalStatusID = 1;
                }
                //出生日期
                if (dr["出生日期"].ToString().Trim() == string.Empty)
                {
                    AddError(objErrorList, dr, "出生日期不能为空");
                    continue;
                }
                else
                {
                    try
                    {
                        string strBirth = dr["出生日期"].ToString().Trim().Replace(".", "");
                        if (strBirth.IndexOf("-") >= 0)
                        {
                            objEmployee.Birthday = Convert.ToDateTime(strBirth);
                        }
                        else
                        {
                            if (strBirth.Length != 8)
                            {
                                AddError(objErrorList, dr, "出生日期填写错误");
                                continue;
                            }
                            else
                            {
                                strBirth             = strBirth.Insert(4, "-");
                                strBirth             = strBirth.Insert(7, "-");
                                objEmployee.Birthday = Convert.ToDateTime(strBirth);
                            }
                        }

                        if (Convert.ToDateTime(strBirth) < Convert.ToDateTime("1900-1-1") ||
                            Convert.ToDateTime(strBirth) > Convert.ToDateTime("2000-12-31"))
                        {
                            AddError(objErrorList, dr, "出生日期填写错误");
                            continue;
                        }
                    }
                    catch
                    {
                        AddError(objErrorList, dr, "出生日期填写错误");
                        continue;
                    }
                }

                //进入本公司时间
                if (dr["进入本公司时间"].ToString().Trim() == string.Empty)
                {
                    AddError(objErrorList, dr, "进入本公司时间不能为空");
                    continue;
                }
                else
                {
                    try
                    {
                        string strJoin = dr["进入本公司时间"].ToString().Trim().Replace(".", "");
                        if (strJoin.IndexOf("-") >= 0)
                        {
                            objEmployee.WorkDate = Convert.ToDateTime(strJoin);
                        }
                        else
                        {
                            if (strJoin.Length != 8)
                            {
                                AddError(objErrorList, dr, "进入本公司时间填写错误");
                                continue;
                            }
                            else
                            {
                                strJoin = strJoin.Insert(4, "-");
                                strJoin = strJoin.Insert(7, "-");
                                objEmployee.WorkDate = Convert.ToDateTime(strJoin);
                            }
                        }

                        if (Convert.ToDateTime(strJoin) < Convert.ToDateTime("1900-1-1"))
                        {
                            AddError(objErrorList, dr, "进入本公司时间填写错误");
                            continue;
                        }
                    }
                    catch
                    {
                        AddError(objErrorList, dr, "进入本公司时间填写错误");
                        continue;
                    }
                }
                //参加工作日期
                if (dr["参加工作时间"].ToString().Trim() == string.Empty)
                {
                    AddError(objErrorList, dr, "参加工作时间不能为空");
                    continue;
                }
                else
                {
                    try
                    {
                        string strJoin = dr["参加工作时间"].ToString().Trim().Replace(".", "");
                        if (strJoin.IndexOf("-") >= 0)
                        {
                            objEmployee.BeginDate = Convert.ToDateTime(strJoin);
                        }
                        else
                        {
                            if (strJoin.Length != 8)
                            {
                                AddError(objErrorList, dr, "参加工作时间填写错误");
                                continue;
                            }
                            else
                            {
                                strJoin = strJoin.Insert(4, "-");
                                strJoin = strJoin.Insert(7, "-");
                                objEmployee.BeginDate = Convert.ToDateTime(strJoin);
                            }
                        }

                        if (Convert.ToDateTime(strJoin) < Convert.ToDateTime("1900-1-1"))
                        {
                            AddError(objErrorList, dr, "参加工作时间填写错误");
                            continue;
                        }
                    }
                    catch
                    {
                        AddError(objErrorList, dr, "参加工作时间填写错误");
                        continue;
                    }
                }
                //职名
                if (dr["岗位名称"].ToString().Trim() == string.Empty)
                {
                    AddError(objErrorList, dr, "岗位名称不能为空!");
                    continue;
                }
                else
                {
                    IList <RailExam.Model.Post> objPost =
                        objPostBll.GetPostsByWhereClause("Post_Level=3 and Post_Name='" + dr["岗位名称"].ToString().Trim() + "'");
                    if (objPost.Count == 0)
                    {
                        if (htPostNeedAdd.ContainsKey(dr["岗位名称"].ToString().Trim()))
                        {
                            objPostNewList = (ArrayList)htPostNeedAdd[dr["岗位名称"].ToString().Trim()];
                            int x;
                            if (isUpdate)
                            {
                                x = objEmployeeUpdate.Count;
                            }
                            else
                            {
                                x = objEmployeeInsert.Count;
                            }
                            objPostNewList.Add(x + "|" + isUpdate);
                            htPostNeedAdd[dr["岗位名称"].ToString().Trim()] = objPostNewList;
                        }
                        else
                        {
                            objPostNewList = new ArrayList();
                            int x;
                            if (isUpdate)
                            {
                                x = objEmployeeUpdate.Count;
                            }
                            else
                            {
                                x = objEmployeeInsert.Count;
                            }
                            objPostNewList.Add(x + "|" + isUpdate);
                            htPostNeedAdd.Add(dr["岗位名称"].ToString().Trim(), objPostNewList);
                        }
                    }

                    objEmployee.PostID = Convert.ToInt32(htPost[dr["岗位名称"].ToString().Trim()]);
                }
                // 因dateAWARD_DATE未加入对象中, 所以此处缺失验证进入神华系统时间

                if (dr["在岗"] == DBNull.Value || dr["在岗"].ToString() == "" || dr["在岗"].ToString() == "否" || dr["在岗"].ToString() == "0")
                {
                    objEmployee.IsOnPost = false;
                }
                else if (dr["在岗"] != DBNull.Value && (dr["在岗"].ToString() == "是" || dr["在岗"].ToString() == "1"))
                {
                    objEmployee.IsOnPost = true;
                }

                if (dr["在册"] == DBNull.Value || dr["在册"].ToString() == "" || dr["在册"].ToString() == "否" || dr["在册"].ToString() == "0")
                {
                    objEmployee.Dimission = false;
                }
                else if (dr["在册"] != DBNull.Value && (dr["在册"].ToString() == "是" || dr["在册"].ToString() == "1"))
                {
                    objEmployee.Dimission = true;
                }

                // 赋值默认值
                if (!isUpdate)
                {
                    //职工类型
                    objEmployee.EmployeeTypeID = 0;
                    // 在册
                    objEmployee.Dimission = true;
                    // 在岗
                    objEmployee.IsOnPost = true;
                    // 运输业职工类型
                    objEmployee.EmployeeTransportTypeID = 0;

                    objEmployeeInsert.Add(objEmployee);
                }
                else
                {
                    objEmployeeUpdate.Add(objEmployee);
                }
            }

            // 处理完成
            jsBlock = "<script>SetCompleted('Excel数据检测完毕'); </script>";
            Response.Write(jsBlock);
            Response.Flush();

            if (objErrorList.Count > 0)
            {
                // 处理完成
                jsBlock = "<script>SetCompleted('正在统计不符合要求的数据,请等待......'); </script>";
                Response.Write(jsBlock);
                Response.Flush();

                objErrorBll.AddEmployeeError(objErrorList);

                if (File.Exists(strPath))
                {
                    File.Delete(strPath);
                }
                Response.Write("<script>window.returnValue='refresh|请检查Excel数据',window.close();</script>");
                return;
            }

            if (!string.IsNullOrEmpty(Request.QueryString.Get("mode")))
            {
                Response.Write("<script>window.returnValue='refresh|数据检查成功',window.close();</script>");
                return;
            }

            #region 导入数据

            System.Threading.Thread.Sleep(10);
            jsBlock = "<script>SetPorgressBar('正在导入部门名称、班组','0.00'); </script>";
            Response.Write(jsBlock);
            Response.Flush();

            Database db = DatabaseFactory.CreateDatabase();

            DbConnection connection = db.CreateConnection();
            connection.Open();
            DbTransaction transaction = connection.BeginTransaction();

            try
            {
                Hashtable htWorkshop = GetWorkShop(db, transaction);
                int       count      = 1;
                foreach (System.Collections.DictionaryEntry obj in htShopNeedAdd)
                {
                    int nWorkShopID;
                    if (!htWorkshop.ContainsKey(obj.Key.ToString()))
                    {
                        RailExam.Model.Organization objshop = new RailExam.Model.Organization();
                        objshop.FullName  = obj.Key.ToString();
                        objshop.ShortName = obj.Key.ToString();
                        objshop.ParentId  = Convert.ToInt32(orgID);
                        objshop.Memo      = "";
                        nWorkShopID       = orgBll.AddOrganization(db, transaction, objshop);
                    }
                    else
                    {
                        nWorkShopID = Convert.ToInt32(htWorkshop[obj.Key.ToString()]);
                    }

                    Hashtable htGroup = (Hashtable)obj.Value;
                    if (htGroup.Count != 0)
                    {
                        foreach (System.Collections.DictionaryEntry objGroupNeedAdd in htGroup)
                        {
                            RailExam.Model.Organization objGroup = new RailExam.Model.Organization();
                            objGroup.FullName  = objGroupNeedAdd.Key.ToString();
                            objGroup.ShortName = objGroupNeedAdd.Key.ToString();
                            objGroup.ParentId  = nWorkShopID;
                            objGroup.Memo      = "";
                            orgBll.AddOrganization(db, transaction, objGroup);
                        }
                    }

                    System.Threading.Thread.Sleep(10);
                    jsBlock = "<script>SetPorgressBar('正在导入部门名称、班组','" + ((double)(count * 100) / (double)(htShopNeedAdd.Count + objEmployeeInsert.Count)).ToString("0.00") + "'); </script>";
                    Response.Write(jsBlock);
                    Response.Flush();
                    count = count + 1;
                }

                htWorkshop = GetWorkShop(db, transaction);
                Hashtable htNowOrg = GetOrgInfo(db, transaction);

                foreach (RailExam.Model.EmployeeDetail objEmployee in objEmployeeInsert)
                {
                    if (objEmployee.Memo.ToString() != string.Empty)
                    {
                        if (objEmployee.Memo.Split('-').Length == 2)
                        {
                            objEmployee.OrgID = Convert.ToInt32(htWorkshop[objEmployee.Memo.Split('-')[1]]);
                        }
                        else
                        {
                            objEmployee.OrgID = Convert.ToInt32(htNowOrg[objEmployee.Memo.ToString()].ToString().Split('-')[0]);
                        }
                    }

                    if (objEmployee.OrgID == 0)
                    {
                        throw new Exception("aaaa");
                    }

                    objEmployee.Memo = "";


                    System.Threading.Thread.Sleep(10);
                    jsBlock = "<script>SetPorgressBar('正在导入部门名称、班组','" + ((double)(count * 100) / (double)(htShopNeedAdd.Count + objEmployeeInsert.Count + objEmployeeUpdate.Count)).ToString("0.00") + "'); </script>";
                    Response.Write(jsBlock);
                    Response.Flush();
                    count = count + 1;
                }

                foreach (RailExam.Model.EmployeeDetail objEmployee in objEmployeeUpdate)
                {
                    if (objEmployee.Memo.ToString() != string.Empty)
                    {
                        if (objEmployee.Memo.Split('-').Length == 2)
                        {
                            objEmployee.OrgID = Convert.ToInt32(htWorkshop[objEmployee.Memo.Split('-')[1]]);
                        }
                        else
                        {
                            objEmployee.OrgID = Convert.ToInt32(htNowOrg[objEmployee.Memo.ToString()].ToString().Split('-')[0]);
                        }
                    }

                    if (objEmployee.OrgID == 0)
                    {
                        throw new Exception("aaaa");
                    }

                    objEmployee.Memo = "";

                    System.Threading.Thread.Sleep(10);
                    jsBlock = "<script>SetPorgressBar('正在导入部门名称、班组','" + ((double)(count * 100) / (double)(htShopNeedAdd.Count + objEmployeeInsert.Count + objEmployeeUpdate.Count)).ToString("0.00") + "'); </script>";
                    Response.Write(jsBlock);
                    Response.Flush();
                    count = count + 1;
                }

                System.Threading.Thread.Sleep(10);
                jsBlock = "<script>SetPorgressBar('正在导入干部职名','0.00'); </script>";
                Response.Write(jsBlock);
                Response.Flush();

                count = 1;
                foreach (System.Collections.DictionaryEntry objPostNeed in htPostNeedAdd)
                {
                    RailExam.Model.Post objPost = new RailExam.Model.Post();
                    objPost.ParentId    = 1550; // 649通用-其他, 1550 其他-其他
                    objPost.PostName    = objPostNeed.Key.ToString();
                    objPost.Technician  = 0;
                    objPost.Promotion   = 0;
                    objPost.Description = string.Empty;
                    objPost.Memo        = string.Empty;
                    int postID = objPostBll.AddPost(db, transaction, objPost);

                    ArrayList objPostList = (ArrayList)objPostNeed.Value;
                    for (int i = 0; i < objPostList.Count; i++)
                    {
                        string[] strPost = objPostList[i].ToString().Split('|');
                        if (strPost[1] == "false" || strPost[1] == "False")
                        {
                            objEmployeeInsert[Convert.ToInt32(strPost[0])].PostID = postID;
                        }
                        else
                        {
                            objEmployeeUpdate[Convert.ToInt32(strPost[0])].PostID = postID;
                        }
                    }

                    System.Threading.Thread.Sleep(10);
                    jsBlock = "<script>SetPorgressBar('正在导入职名','" + ((double)(count * 100) / (double)(htPostNeedAdd.Count)).ToString("0.00") + "'); </script>";
                    Response.Write(jsBlock);
                    Response.Flush();
                    count = count + 1;
                }

                System.Threading.Thread.Sleep(10);
                jsBlock = "<script>SetPorgressBar('正在导入员工信息','0.00'); </script>";
                Response.Write(jsBlock);
                Response.Flush();

                OracleAccess access = new OracleAccess();
                string       strSql;

                count = 1;
                for (int i = 0; i < objEmployeeInsert.Count; i++)
                {
                    int employeeid = objEmployeeDetailBll.AddEmployee(db, transaction, objEmployeeInsert[i]);

                    System.Threading.Thread.Sleep(10);
                    jsBlock = "<script>SetPorgressBar('正在导入员工信息','" + ((double)(count * 100) / (double)(objEmployeeInsert.Count + objEmployeeUpdate.Count)).ToString("0.00") + "'); </script>";
                    Response.Write(jsBlock);
                    Response.Flush();
                    count = count + 1;
                }


                for (int i = 0; i < objEmployeeUpdate.Count; i++)
                {
                    objEmployeeDetailBll.UpdateEmployee(db, transaction, objEmployeeUpdate[i]);
                    System.Threading.Thread.Sleep(10);
                    jsBlock = "<script>SetPorgressBar('正在导入员工信息','" + ((double)(count * 100) / (double)(objEmployeeInsert.Count + objEmployeeUpdate.Count)).ToString("0.00") + "'); </script>";
                    Response.Write(jsBlock);
                    Response.Flush();
                    count = count + 1;
                }

                strMessage = "导入成功!";
                transaction.Commit();
            }
            catch (Exception ex)
            {
                strMessage = "导入失败!";
                transaction.Rollback();
                //Response.Write(EnhancedStackTrace(ex));
            }
            finally
            {
                connection.Close();
            }

            if (File.Exists(strPath))
            {
                File.Delete(strPath);
            }
            Response.Write("<script>window.returnValue='refresh|" + strMessage + "';window.close();</script>");
            #endregion
        }
        private void Import(int type, string strID)
        {
            EmployeeErrorBLL objBll   = new EmployeeErrorBLL();
            EmployeeError    objError = new EmployeeError();

            objError = objBll.GetEmployeeError(Convert.ToInt32(strID));

            #region 检测员工信息
            Hashtable htOrg                   = GetOrgInfo();
            Hashtable htPost                  = GetPostInfo();
            Hashtable htEducationLevel        = GetEducationLevel();
            Hashtable htPoliticalStatus       = GetPoliticalStatus();
            Hashtable htEmployeeType          = GetEmployeeType();
            Hashtable htWorkGroupLeaderType   = GetWorkGroupLeaderType();
            Hashtable htEducationEmployeeType = GetEducationEmployeeType();
            Hashtable htCommitteeHeadship     = GetCommitteeHeadship();
            Hashtable htEmployeeTransportType = GetEmployeeTransportType();
            Hashtable htTechnicalTitle        = GetTechnicalTitle();
            Hashtable htSkillLevel            = GetSkillLevel();
            Hashtable htEmployeeLevel         = GetEmployeeLevel();
            Hashtable htTeacherType           = GetTeacherType();

            Hashtable htShopNeedAdd = new Hashtable();
            Hashtable htPostNo      = new Hashtable();        //为检测Excel中员工编码是否重复
            Hashtable htPostNeedAdd = new Hashtable();
            Hashtable htSalaryNo    = new Hashtable();

            PostBLL objPostBll = new PostBLL();

            EmployeeBLL                   objEmployeeBll = new EmployeeBLL();
            EmployeeDetailBLL             objDetailBll   = new EmployeeDetailBLL();
            RailExam.Model.EmployeeDetail objEmployee    = new RailExam.Model.EmployeeDetail();

            if (type == 2)
            {
                objEmployee = objDetailBll.GetEmployee(objError.EmployeeID);
            }

            //单位名称
            if (objError.OrgName != txtOrg.Text)
            {
                SessionSet.PageMessage = "单位名称填写错误";
                return;
            }

            if (objError.OrgPath == "")
            {
                SessionSet.PageMessage = "部门名称不能为空";
                return;
            }

            //组织机构
            string strOrg;
            if (string.IsNullOrEmpty(objError.GroupName))
            {
                strOrg = objError.OrgName + "-" + objError.OrgPath;
            }
            else
            {
                strOrg = objError.OrgName + "-" + objError.OrgPath + "-" + objError.GroupName;
            }

            if (!htOrg.ContainsKey(strOrg))
            {
                if (string.IsNullOrEmpty(objError.GroupName))
                {
                    if (!htShopNeedAdd.ContainsKey(objError.OrgPath))
                    {
                        htShopNeedAdd.Add(objError.OrgPath, new Hashtable());
                    }

                    //如果组织机构需要新增
                    objEmployee.Memo = strOrg;
                }
                else
                {
                    if (!htShopNeedAdd.ContainsKey(objError.OrgPath))
                    {
                        htShopNeedAdd.Add(objError.OrgPath, new Hashtable());
                    }

                    Hashtable htGroupNeedAdd = (Hashtable)htShopNeedAdd[objError.OrgPath];
                    if (!htGroupNeedAdd.ContainsKey(objError.GroupName))
                    {
                        htGroupNeedAdd.Add(objError.GroupName, objError.GroupName);
                        htShopNeedAdd[objError.OrgPath] = htGroupNeedAdd;
                    }

                    //如果组织机构需要新增
                    objEmployee.Memo = strOrg;
                }
            }
            else
            {
                objEmployee.OrgID = Convert.ToInt32(htOrg[strOrg]);
                objEmployee.Memo  = string.Empty;
            }

            //姓名不能为空
            if (string.IsNullOrEmpty(objError.EmployeeName))
            {
                SessionSet.PageMessage = "员工姓名不能为空";
                return;
            }
            else
            {
                if (objError.EmployeeName.Length > 20)
                {
                    SessionSet.PageMessage = "员工姓名不能超过20位";
                    return;
                }

                objEmployee.EmployeeName = objError.EmployeeName;
                objEmployee.PinYinCode   = Pub.GetChineseSpell(objError.EmployeeName);
            }

            //身份证号不能为空
            if (string.IsNullOrEmpty(objError.IdentifyCode))
            {
                SessionSet.PageMessage = "身份证号不能为空";
                return;
            }
            else
            {
                if (objError.IdentifyCode.Length > 18)
                {
                    SessionSet.PageMessage = "身份证号不能超过18位";
                    return;
                }

                objEmployee.IdentifyCode = objError.IdentifyCode;
            }

            //工作证号
            if (!string.IsNullOrEmpty(objError.PostNo))
            {
                if (objError.PostNo.Length > 14)
                {
                    SessionSet.PageMessage = "工作证号不能超过14位";
                    return;
                }

                objEmployee.PostNo = objError.PostNo;
            }
            else
            {
                objEmployee.PostNo = "";
            }

            //性别
            if (objError.Sex != "男" && objError.Sex != "女")
            {
                SessionSet.PageMessage = "性别必须为男或女";
                return;
            }
            else
            {
                objEmployee.Sex = objError.Sex;
            }

            //籍贯
            if (!string.IsNullOrEmpty(objError.NativePlace))
            {
                if (objError.NativePlace.Length > 20)
                {
                    SessionSet.PageMessage = "籍贯不能超过20位";
                    return;
                }
                else
                {
                    objEmployee.NativePlace = objError.NativePlace;
                }
            }
            else
            {
                objEmployee.NativePlace = string.Empty;
            }


            //民族
            if (!string.IsNullOrEmpty(objError.Folk))
            {
                if (objError.Folk.Length > 10)
                {
                    SessionSet.PageMessage = "民族不能超过10位";
                    return;
                }
                else
                {
                    objEmployee.Folk = objError.Folk;
                }
            }
            else
            {
                objEmployee.Folk = string.Empty;
            }

            //婚姻状况
            if (objError.Wedding == "未婚")
            {
                objEmployee.Wedding = 0;
            }
            else
            {
                objEmployee.Wedding = 1;
            }

            //现文化程度
            if (string.IsNullOrEmpty(objError.EducationLevel))
            {
                SessionSet.PageMessage = "现文化程度不能为空";
                return;
            }
            else
            {
                if (!htEducationLevel.ContainsKey(objError.EducationLevel))
                {
                    SessionSet.PageMessage = "现文化程度在系统中不存在";
                    return;
                }
                else
                {
                    objEmployee.EducationLevelID = Convert.ToInt32(htEducationLevel[objError.EducationLevel]);
                }
            }

            //政治面貌
            if (!string.IsNullOrEmpty(objError.PoliticalStatus))
            {
                if (!htPoliticalStatus.ContainsKey(objError.PoliticalStatus))
                {
                    SessionSet.PageMessage = "政治面貌在系统中不存在";
                    return;
                }
                else
                {
                    objEmployee.PoliticalStatusID = Convert.ToInt32(htPoliticalStatus[objError.PoliticalStatus]);
                }
            }

            //毕(肄)业学校(单位)
            if (!string.IsNullOrEmpty(objError.GraduateUniversity))
            {
                if (objError.GraduateUniversity.Length > 50)
                {
                    SessionSet.PageMessage = "毕(肄)业学校(单位)不能超过50位";
                    return;
                }
                else
                {
                    objEmployee.GraduateUniversity = objError.GraduateUniversity;
                }
            }
            else
            {
                objError.GraduateUniversity = string.Empty;
            }

            //所学专业
            if (!string.IsNullOrEmpty(objEmployee.StudyMajor))
            {
                if (objEmployee.StudyMajor.Length > 50)
                {
                    SessionSet.PageMessage = "所学专业不能超过50位";
                    return;
                }
                else
                {
                    objEmployee.StudyMajor = objEmployee.StudyMajor;
                }
            }
            else
            {
                objEmployee.StudyMajor = string.Empty;
            }

            //工作地址
            if (!string.IsNullOrEmpty(objError.Address))
            {
                if (objError.Address.Length > 100)
                {
                    SessionSet.PageMessage = "工作地址不能超过100位";
                    return;
                }
                else
                {
                    objEmployee.Address = objError.Address;
                }
            }
            else
            {
                objEmployee.Address = string.Empty;
            }

            //邮政编码
            if (!string.IsNullOrEmpty(objEmployee.PostCode))
            {
                if (objError.PostCode.Length > 6)
                {
                    SessionSet.PageMessage = "邮政编码不能超过6位";
                    return;
                }
                else
                {
                    objEmployee.PostCode = objError.PostCode;
                }
            }
            else
            {
                objEmployee.PostCode = string.Empty;
            }

            //职务级别
            if (!string.IsNullOrEmpty(objError.EmployeeLevel))
            {
                if (!htEmployeeLevel.ContainsKey(objError.EmployeeLevel))
                {
                    SessionSet.PageMessage = "职务级别在系统中不存在";
                    return;
                }
                else
                {
                    objEmployee.EmployeeLevelID = Convert.ToInt32(htEmployeeLevel[objError.EmployeeLevel]);
                }
            }

            //出生日期
            try
            {
                string strBirth = objError.Birthday;
                if (strBirth.IndexOf("-") >= 0)
                {
                    objEmployee.Birthday = Convert.ToDateTime(strBirth);
                }
                else
                {
                    if (strBirth.Length != 8)
                    {
                        SessionSet.PageMessage = "出生日期填写错误";
                        return;
                    }
                    else
                    {
                        strBirth             = strBirth.Insert(4, "-");
                        strBirth             = strBirth.Insert(7, "-");
                        objEmployee.Birthday = Convert.ToDateTime(strBirth);
                    }
                }

                if (Convert.ToDateTime(strBirth) < Convert.ToDateTime("1775-1-1") ||
                    Convert.ToDateTime(strBirth) > Convert.ToDateTime("1993-12-31"))
                {
                    SessionSet.PageMessage = "出生日期填写错误";
                    return;
                }
            }
            catch
            {
                SessionSet.PageMessage = "出生日期填写错误";
                return;
            }

            //入路工作日期
            try
            {
                string strJoin = objError.WorkDate;
                if (strJoin.IndexOf("-") >= 0)
                {
                    objEmployee.WorkDate = Convert.ToDateTime(strJoin);
                }
                else
                {
                    if (strJoin.Length != 8)
                    {
                        SessionSet.PageMessage = "入路工作日期填写错误";
                        return;
                    }
                    else
                    {
                        strJoin = strJoin.Insert(4, "-");
                        strJoin = strJoin.Insert(7, "-");
                        objEmployee.WorkDate = Convert.ToDateTime(strJoin);
                    }
                }

                if (Convert.ToDateTime(strJoin) < Convert.ToDateTime("1775-1-1"))
                {
                    SessionSet.PageMessage = "入路工作日期填写错误";
                    return;
                }
            }
            catch
            {
                SessionSet.PageMessage = "入路工作日期填写错误";
                return;
            }


            //参加工作日期
            try
            {
                string strJoin = objError.BeginDate;
                if (strJoin.IndexOf("-") >= 0)
                {
                    objEmployee.BeginDate = Convert.ToDateTime(strJoin);
                }
                else
                {
                    if (strJoin.Length != 8)
                    {
                        SessionSet.PageMessage = "参加工作日期填写错误";
                        return;
                    }
                    else
                    {
                        strJoin = strJoin.Insert(4, "-");
                        strJoin = strJoin.Insert(7, "-");
                        objEmployee.BeginDate = Convert.ToDateTime(strJoin);
                    }
                }

                if (Convert.ToDateTime(strJoin) < Convert.ToDateTime("1775-1-1"))
                {
                    SessionSet.PageMessage = "参加工作日期填写错误";
                    return;
                }
            }
            catch
            {
                SessionSet.PageMessage = "参加工作日期填写错误";
                return;
            }

            //干部工人标识
            if (string.IsNullOrEmpty(objError.EmployeeType))
            {
                SessionSet.PageMessage = "干部工人标识不能为空!";
                return;
            }
            else
            {
                if (!htEmployeeType.ContainsKey(objError.EmployeeType))
                {
                    SessionSet.PageMessage = "干部工人标识在系统中不存在!";
                    return;
                }
                else
                {
                    objEmployee.EmployeeTypeID = Convert.ToInt32(htEmployeeType[objError.EmployeeType]);
                }
            }

            if (objEmployee.EmployeeTypeID == 1)
            {
                //岗位
                if (string.IsNullOrEmpty(objError.PostPath))
                {
                    SessionSet.PageMessage = "岗位不能为空!";
                    return;
                }
                else
                {
                    IList <RailExam.Model.Post> objPost =
                        objPostBll.GetPostsByWhereClause("Post_Level=3 and Post_Name='" + objError.PostPath + "'");
                    if (objPost.Count == 0)
                    {
                        SessionSet.PageMessage = "岗位在系统中不存在!";
                        return;
                    }

                    objEmployee.PostID = Convert.ToInt32(htPost[objError.PostPath]);
                }
            }
            else
            {
                //岗位
                if (string.IsNullOrEmpty(objError.PostPath))
                {
                    SessionSet.PageMessage = "职务不能为空!";
                    return;
                }
                else
                {
                    IList <RailExam.Model.Post> objPost =
                        objPostBll.GetPostsByWhereClause("Post_Level=3 and Post_Name='" + objError.PostPath + "'");
                    if (objPost.Count == 0)
                    {
                        htPostNeedAdd.Add(objError.PostPath, objError.PostPath);
                    }
                    else
                    {
                        objEmployee.PostID = objPost[0].PostId;
                    }
                }
            }



            //班组长类型
            if (string.IsNullOrEmpty(objError.WorkGroupLeader))
            {
                objEmployee.IsGroupLeader = 0;
            }
            else
            {
                if (!htWorkGroupLeaderType.ContainsKey(objError.WorkGroupLeader))
                {
                    SessionSet.PageMessage = "班组长类型在系统中不存在!";
                    return;
                }

                objEmployee.WorkGroupLeaderTypeID = Convert.ToInt32(htWorkGroupLeaderType[objError.WorkGroupLeader]);
                objEmployee.IsGroupLeader         = 1;
            }


            if (!string.IsNullOrEmpty(objError.EducationEmployee))
            {
                if (!htEducationEmployeeType.ContainsKey(objError.EducationEmployee))
                {
                    SessionSet.PageMessage = "职教干部类型在系统中不存在!";
                    return;
                }
                else
                {
                    objEmployee.EducationEmployeeTypeID = Convert.ToInt32(htEducationEmployeeType[objError.EducationEmployee]);
                }
            }

            //职教委员会职务
            if (!string.IsNullOrEmpty(objError.CommitteeHeadShip))
            {
                if (!htCommitteeHeadship.ContainsKey(objError.CommitteeHeadShip))
                {
                    SessionSet.PageMessage = "职教委员会职务在系统中不存在!";
                    return;
                }
                else
                {
                    objEmployee.CommitteeHeadShipID = Convert.ToInt32(htCommitteeHeadship[objError.CommitteeHeadShip]);
                }
            }

            //教师类别
            if (!string.IsNullOrEmpty(objError.TeacherType))
            {
                if (!htTeacherType.ContainsKey(objError.TeacherType))
                {
                    SessionSet.PageMessage = "教师类别在系统中不存在";
                    return;
                }
                else
                {
                    objEmployee.TeacherTypeID = Convert.ToInt32(htTeacherType[objError.TeacherType]);
                }
            }

            //人员岗位状态
            if (objError.OnPost != "在岗工作")
            {
                objEmployee.Dimission = true;
            }
            else
            {
                objEmployee.Dimission = false;
            }

            //在岗职工按岗位分组
            if (string.IsNullOrEmpty(objError.EmployeeTransportType))
            {
                //SessionSet.PageMessage = "当单位名称为“运输业”时,在岗职工按岗位分组不能为空!";
                //return;
            }
            else
            {
                if (!htEmployeeTransportType.ContainsKey(objError.EmployeeTransportType))
                {
                    SessionSet.PageMessage = "在岗职工按岗位分组在系统中不存在!";
                    return;
                }
                else
                {
                    objEmployee.EmployeeTransportTypeID = Convert.ToInt32(htEmployeeTransportType[objError.EmployeeTransportType]);
                }
            }

            //现技术职务名称
            if (objEmployee.EmployeeTypeID == 1)
            {
                if (!string.IsNullOrEmpty(objError.TechnicalTitle))
                {
                    SessionSet.PageMessage = "当干部工人标识为“工人”时,现技术职务名称必须为空!";
                    return;
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(objError.TechnicalTitle))
                {
                    if (!htTechnicalTitle.ContainsKey(objError.TechnicalTitle))
                    {
                        SessionSet.PageMessage = "现技术职务名称在系统中不存在!";
                        return;
                    }
                    else
                    {
                        objEmployee.TechnicalTitleID = Convert.ToInt32(htTechnicalTitle[objError.TechnicalTitle]);
                    }
                }
            }

            //技术等级
            if (objEmployee.EmployeeTypeID == 1)
            {
                if (!string.IsNullOrEmpty(objError.TechnicalSkill))
                {
                    if (!htSkillLevel.ContainsKey(objError.TechnicalSkill))
                    {
                        SessionSet.PageMessage = "技术等级在系统中不存在!";
                        return;
                    }
                    else
                    {
                        objEmployee.TechnicianTypeID = Convert.ToInt32(htSkillLevel[objError.TechnicalSkill]);
                    }
                }
                else
                {
                    objEmployee.TechnicianTypeID = 1;
                }
            }
            else
            {
                objEmployee.TechnicianTypeID = 1;
            }

            //岗位培训合格证编号

            if (!string.IsNullOrEmpty(objError.SalaryNo))
            {
                if (objError.SalaryNo.Length > 20)
                {
                    SessionSet.PageMessage = "岗位培训合格证编号不能超过20位";
                    return;
                }

                //工作证号在Excel中不能重复

                if (htPostNo.ContainsKey(objError.SalaryNo))
                {
                    SessionSet.PageMessage = "岗位培训合格证编号在Excel中与序号为" + htPostNo[objError.SalaryNo] + "的岗位培训合格证编号重复";
                    return;
                }
                else
                {
                    htPostNo.Add(objError.SalaryNo, objError.ExcelNo);
                }

                IList <RailExam.Model.Employee> objView = new List <RailExam.Model.Employee>();

                if (type == 1)
                {
                    objView = objEmployeeBll.GetEmployeeByWhereClause("Home_Phone='" + objError.SalaryNo + "'");
                }
                else if (type == 2)
                {
                    objView = objEmployeeBll.GetEmployeeByWhereClause("a.Employee_ID != " + objEmployee.EmployeeID + " and Home_Phone='" + objError.SalaryNo + "'");
                }

                if (objView.Count > 0)
                {
                    SessionSet.PageMessage = "岗位培训合格证编号已在系统中存在";
                    return;
                }

                objEmployee.HomePhone = objError.SalaryNo;
            }
            else
            {
                objEmployee.HomePhone = string.Empty;
            }


            if (!string.IsNullOrEmpty(objError.WorkNo))
            {
                if (objError.WorkNo.Length > 20)
                {
                    SessionSet.PageMessage = "工资编号不能超过20位";
                    return;
                }

                //工作证号在Excel中不能重复

                if (htSalaryNo.ContainsKey(objError.WorkNo))
                {
                    SessionSet.PageMessage = "工资编号在Excel中与序号为" + htSalaryNo[objError.WorkNo] + "的工资编号重复";
                    return;
                }
                else
                {
                    htSalaryNo.Add(objError.WorkNo, objError.ExcelNo);
                }


                IList <RailExam.Model.EmployeeDetail> objView = new List <RailExam.Model.EmployeeDetail>();

                if (type == 1)
                {
                    objView = objDetailBll.GetEmployeeByWhereClause("GetStationOrgID(a.Org_ID)=" + hfOrg.Value + " and Work_No='" + objError.WorkNo + "'");
                }
                else if (type == 2)
                {
                    objView = objDetailBll.GetEmployeeByWhereClause("a.Employee_ID != " + objEmployee.EmployeeID + " and GetStationOrgID(a.Org_ID)=" + hfOrg.Value + " and Work_No='" + objError.WorkNo + "'");
                }

                if (objView.Count > 0)
                {
                    SessionSet.PageMessage = "工资编号已在系统中存在";
                    return;
                }

                objEmployee.WorkNo = objError.WorkNo;
            }
            else
            {
                SessionSet.PageMessage = "工资编号不能为空!";
                return;
            }


            #endregion

            if (type == 1)
            {
                #region 新增
                Database db = DatabaseFactory.CreateDatabase();

                DbConnection connection = db.CreateConnection();
                connection.Open();
                DbTransaction   transaction = connection.BeginTransaction();
                OrganizationBLL orgBll      = new OrganizationBLL();
                try
                {
                    Hashtable htWorkshop = GetWorkShop(db, transaction);
                    foreach (System.Collections.DictionaryEntry obj in htShopNeedAdd)
                    {
                        int nWorkShopID;
                        if (!htWorkshop.ContainsKey(obj.Key.ToString()))
                        {
                            RailExam.Model.Organization objshop = new RailExam.Model.Organization();
                            objshop.FullName  = obj.Key.ToString();
                            objshop.ShortName = obj.Key.ToString();
                            objshop.ParentId  = Convert.ToInt32(hfOrg.Value);
                            objshop.Memo      = "";
                            nWorkShopID       = orgBll.AddOrganization(db, transaction, objshop);
                        }
                        else
                        {
                            nWorkShopID = Convert.ToInt32(htWorkshop[obj.Key.ToString()]);
                        }

                        Hashtable htGroup = (Hashtable)obj.Value;
                        if (htGroup.Count != 0)
                        {
                            foreach (System.Collections.DictionaryEntry objGroupNeedAdd in htGroup)
                            {
                                RailExam.Model.Organization objGroup = new RailExam.Model.Organization();
                                objGroup.FullName  = objGroupNeedAdd.Key.ToString();
                                objGroup.ShortName = objGroupNeedAdd.Key.ToString();
                                objGroup.ParentId  = nWorkShopID;
                                objGroup.Memo      = "";
                                orgBll.AddOrganization(db, transaction, objGroup);
                            }
                        }
                    }

                    htWorkshop = GetWorkShop(db, transaction);
                    Hashtable htNowOrg = GetOrgInfo(db, transaction);

                    if (!string.IsNullOrEmpty(objEmployee.Memo))
                    {
                        if (objEmployee.Memo.Split('-').Length == 2)
                        {
                            objEmployee.OrgID = Convert.ToInt32(htWorkshop[objEmployee.Memo.Split('-')[1]]);
                        }
                        else
                        {
                            objEmployee.OrgID = Convert.ToInt32(htNowOrg[objEmployee.Memo.ToString()].ToString().Split('-')[0]);
                        }
                    }

                    if (objEmployee.OrgID == 0)
                    {
                        throw new Exception("aaaa");
                    }

                    objEmployee.Memo = "";


                    foreach (System.Collections.DictionaryEntry objPostNeed in htPostNeedAdd)
                    {
                        RailExam.Model.Post objPost = new RailExam.Model.Post();
                        objPost.ParentId    = 373;
                        objPost.PostName    = objPostNeed.Key.ToString();
                        objPost.Technician  = 0;
                        objPost.Promotion   = 0;
                        objPost.Description = string.Empty;
                        objPost.Memo        = string.Empty;
                        int postID = objPostBll.AddPost(db, transaction, objPost);

                        objEmployee.PostID = postID;
                    }

                    objDetailBll.AddEmployee(db, transaction, objEmployee);


                    transaction.Commit();
                }
                catch
                {
                    transaction.Rollback();
                    SessionSet.PageMessage = "新增失败!";
                    return;
                }
                finally
                {
                    connection.Close();
                }

                #endregion
            }
            else
            {
                #region 修改
                Database db = DatabaseFactory.CreateDatabase();

                DbConnection connection = db.CreateConnection();
                connection.Open();
                DbTransaction   transaction = connection.BeginTransaction();
                OrganizationBLL orgBll      = new OrganizationBLL();
                try
                {
                    Hashtable htWorkshop = GetWorkShop(db, transaction);
                    foreach (System.Collections.DictionaryEntry obj in htShopNeedAdd)
                    {
                        int nWorkShopID;
                        if (!htWorkshop.ContainsKey(obj.Key.ToString()))
                        {
                            RailExam.Model.Organization objshop = new RailExam.Model.Organization();
                            objshop.FullName  = obj.Key.ToString();
                            objshop.ShortName = obj.Key.ToString();
                            objshop.ParentId  = Convert.ToInt32(hfOrg.Value);
                            objshop.Memo      = "";
                            nWorkShopID       = orgBll.AddOrganization(db, transaction, objshop);
                        }
                        else
                        {
                            nWorkShopID = Convert.ToInt32(htWorkshop[obj.Key.ToString()]);
                        }

                        Hashtable htGroup = (Hashtable)obj.Value;
                        if (htGroup.Count != 0)
                        {
                            foreach (System.Collections.DictionaryEntry objGroupNeedAdd in htGroup)
                            {
                                RailExam.Model.Organization objGroup = new RailExam.Model.Organization();
                                objGroup.FullName  = objGroupNeedAdd.Key.ToString();
                                objGroup.ShortName = objGroupNeedAdd.Key.ToString();
                                objGroup.ParentId  = nWorkShopID;
                                objGroup.Memo      = "";
                                orgBll.AddOrganization(db, transaction, objGroup);
                            }
                        }
                    }

                    htWorkshop = GetWorkShop(db, transaction);
                    Hashtable htNowOrg = GetOrgInfo(db, transaction);

                    if (!string.IsNullOrEmpty(objEmployee.Memo))
                    {
                        if (objEmployee.Memo.Split('-').Length == 2)
                        {
                            objEmployee.OrgID = Convert.ToInt32(htWorkshop[objEmployee.Memo.Split('-')[1]]);
                        }
                        else
                        {
                            objEmployee.OrgID = Convert.ToInt32(htNowOrg[objEmployee.Memo.ToString()].ToString().Split('-')[0]);
                        }
                    }

                    if (objEmployee.OrgID == 0)
                    {
                        throw new Exception("aaaa");
                    }

                    objEmployee.Memo = "";

                    foreach (System.Collections.DictionaryEntry objPostNeed in htPostNeedAdd)
                    {
                        RailExam.Model.Post objPost = new RailExam.Model.Post();
                        objPost.ParentId    = 373;
                        objPost.PostName    = objPostNeed.Key.ToString();
                        objPost.Technician  = 0;
                        objPost.Promotion   = 0;
                        objPost.Description = string.Empty;
                        objPost.Memo        = string.Empty;
                        int postID = objPostBll.AddPost(db, transaction, objPost);

                        objEmployee.PostID = postID;
                    }


                    objDetailBll.UpdateEmployee(db, transaction, objEmployee);


                    transaction.Commit();
                }
                catch
                {
                    transaction.Rollback();
                    SessionSet.PageMessage = "修改失败!";
                    return;
                }
                finally
                {
                    connection.Close();
                }

                #endregion

                SystemUserBLL objUserBll = new SystemUserBLL();
                SystemUser    objUser    = objUserBll.GetUserByEmployeeID(objEmployee.EmployeeID);
                objUser.UserID = objEmployee.WorkNo;
                objUserBll.UpdateUser(objUser);
            }

            objBll.DeleteEmployeeError(Convert.ToInt32(strID));
        }