Exemple #1
0
        protected void btnOk_Click(object sender, EventArgs e)
        {
            OracleAccess db     = new OracleAccess();
            string       strSql = "select * from Employee where Employee_ID=" + ViewState["EmployeeID"];
            DataRow      dr     = db.RunSqlDataSet(strSql).Tables[0].Rows[0];


            int orgID;

            if (ddlWorkgroup.SelectedValue != "0")
            {
                orgID = Convert.ToInt32(ddlWorkgroup.SelectedValue);
            }
            else
            {
                orgID = Convert.ToInt32(ddlWorkshop.SelectedValue);
            }

            OrganizationBLL organizationBLL         = new OrganizationBLL();
            EmployeeBLL     objEmployeeBll          = new EmployeeBLL();
            IList <RailExam.Model.Employee> objView =
                objEmployeeBll.GetEmployeeByWhereClause("GetStationOrgID(a.Org_ID)=" + organizationBLL.GetStationOrgID(orgID) +
                                                        " and Work_No='" + txtWorkNo.Text.Trim() + "'");

            if (objView.Count > 0)
            {
                SessionSet.PageMessage = "该员工编码在本单位已经存在!";
                return;
            }
            strSql = "update Employee "
                     + " set Employee_Name='" + txtName.Text + "',"
                     + "Org_ID=" + orgID + ","
                     + "Work_No='" + txtWorkNo.Text + "',"
                     + "identity_CardNo='" + txtPostNo.Text + "',"
                     + "PinYin_Code='" + Pub.GetChineseSpell(txtName.Text) + "' "
                     + " where Employee_ID=" + ViewState["EmployeeID"];
            db.ExecuteNonQuery(strSql);

            strSql = "insert into ZJ_Employee_Work "
                     + " values(Employee_Work_Seq.nextval,  "
                     + dr["EMPLOYEE_ID"]
                     + ", to_char(sysdate,'yyyy-mm-dd')," + dr["org_id"] + "," + orgID + ","
                     + dr["Post_ID"] + "," + dr["Post_ID"] + ","
                     + "'',sysdate,'" + PrjPub.CurrentLoginUser.EmployeeName + "',"
                     + "to_date('" + dr["Post_Date"] + "','YYYY-MM-DD HH24:MI:SS'))";
            db.ExecuteNonQuery(strSql);

            string transferID = Request.QueryString.Get("transferID");
            EmployeeTransferBLL objTransferBll = new EmployeeTransferBLL();

            objTransferBll.DeleteEmployeeTransfer(Convert.ToInt32(transferID));

            SystemLogBLL objLogBll = new SystemLogBLL();

            objLogBll.WriteLog("将" + dr["Employee_Name"] + "调至" + lblOrg.Text);

            Response.Write("<script>window.returnValue='true';window.close();</script>");
        }
        protected void btnUpper_Click(object sender, EventArgs e)
        {
            EmployeeBLL      objbll  = new EmployeeBLL();
            IList <Employee> objList = objbll.GetAllEmployees();

            foreach (Employee employee in objList)
            {
                employee.PinYinCode = Pub.GetChineseSpell(employee.EmployeeName);
                objbll.UpdateEmployeeWithOutLog(employee);
            }
            SessionSet.PageMessage = "生成成功!";
        }
        //保存数据
        private void saveData()
        {
            string type = Request.QueryString["Type"];//1为修改 2为新增
            string id   = Request.QueryString["ID"];

            OracleAccess db     = new OracleAccess();
            string       strSql = "";

            if (!string.IsNullOrEmpty(txtIDENTITY_CARDNO.Text.Trim()))
            {
                if (type == "1")
                {
                    strSql = "select a.*,GetOrgName(GetStationOrgID(a.Org_ID)) OrgName from Employee a where Identity_CardNo='" + txtIDENTITY_CARDNO.Text.Trim() +
                             "' and Employee_ID<>" + id;
                }
                else
                {
                    strSql = "select a.*,GetOrgName(GetStationOrgID(a.Org_ID)) OrgName from Employee a where Identity_CardNo='" + txtIDENTITY_CARDNO.Text.Trim() + "'";
                }

                DataSet ds = db.RunSqlDataSet(strSql);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    string strName = ds.Tables[0].Rows[0]["Employee_Name"].ToString();
                    string orgName = ds.Tables[0].Rows[0]["OrgName"].ToString();
                    SessionSet.PageMessage = "该身份证号码在系统中已存在,与【" + orgName + "】的【" + strName + "】身份证号相同!";
                    return;
                }
            }

            if (!string.IsNullOrEmpty(txtWORK_NO.Text.Trim()))
            {
                if (type == "1")
                {
                    strSql = "select a.*,GetOrgName(GetStationOrgID(a.Org_ID)) OrgName from Employee a where Work_No='" + txtWORK_NO.Text.Trim() +
                             "' and Employee_ID<>" + id;
                }
                else
                {
                    strSql = "select a.*,GetOrgName(GetStationOrgID(a.Org_ID)) OrgName from Employee a where Work_No='" + txtWORK_NO.Text.Trim() + "'";
                }

                DataSet ds = db.RunSqlDataSet(strSql);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    string strName = ds.Tables[0].Rows[0]["Employee_Name"].ToString();
                    string orgName = ds.Tables[0].Rows[0]["OrgName"].ToString();
                    SessionSet.PageMessage = "该岗位培训合格证书编号在系统中已存在,与【" + orgName + "】的【" + strName + "】岗位培训合格证书编号相同!";
                    //ClientScript.RegisterStartupScript(GetType(), "OK", "alert('该岗位培训合格证书编号在系统中已存在,\r\n与【" + orgName + "】的【" + strName + "】岗位培训合格证书编号相同!');", true);
                    return;
                }
            }

            string   sqlStr     = string.Empty;
            DateTime isnulldate = new DateTime(0001, 01, 01);
            DateTime birthday,
                     begin_date,
                     join_rail_date,
                     workgroupleader_order_date,
                     award_date;
            DateTime postDate,           //任现职名时间
                     technicalTitleDate, //技术职称聘任时间
                     technicalDate,      //技能等级取得时间
                     graduateDate;       //毕业时间
            string graduateUniversity,   //毕业院校
                   studyMajor,           //所学专业
                   universityType;       //学校类别

            if (!DateTime.TryParse(this.dateBIRTHDAY.DateValue.ToString(), out birthday))
            {
                birthday = isnulldate;
            }
            if (!DateTime.TryParse(this.dateBEGIN_DATE.DateValue.ToString(), out begin_date))
            {
                begin_date = isnulldate;
            }
            if (!DateTime.TryParse(this.dateJOIN_RAIL_DATE.DateValue.ToString(), out join_rail_date))
            {
                join_rail_date = isnulldate;
            }

            if (ddlWORKGROUPLEADER_TYPE_ID.SelectedValue != "-1")
            {
                if (!DateTime.TryParse(this.dateWORKGROUPLEADER_ORDER_DATE.DateValue.ToString(), out workgroupleader_order_date))
                {
                    workgroupleader_order_date = isnulldate;
                }
            }
            else
            {
                workgroupleader_order_date = isnulldate;
            }

            if (!DateTime.TryParse(this.dateAWARD_DATE.DateValue.ToString(), out award_date))
            {
                award_date = isnulldate;
            }
            if (!DateTime.TryParse(this.datePost.DateValue.ToString(), out postDate))
            {
                postDate = isnulldate;
            }
            if (!DateTime.TryParse(this.dateTechnicalDate.DateValue.ToString(), out technicalDate))
            {
                technicalDate = isnulldate;
            }
            if (!DateTime.TryParse(this.dateTechnicalTitle.DateValue.ToString(), out technicalTitleDate))
            {
                technicalTitleDate = isnulldate;
            }
            if (!DateTime.TryParse(this.dateGraduate.DateValue.ToString(), out graduateDate))
            {
                graduateDate = isnulldate;
            }
            if (this.txtMEMO.Text.ToString().Length > 50)
            {
                ClientScript.RegisterStartupScript(GetType(), "OK", "alert('备注不能超过50个字符!');", true);
                return;
            }

            OracleAccess ora = new OracleAccess();

            int ISONPOST = this.cbISONPOST.Checked == true ? 1 : 0;

            if (!string.IsNullOrEmpty(type))
            {
                int typeBool = int.Parse(type);
                if (typeBool == 1)
                {
                    sqlStr  = "update employee set org_id= '" + Convert.ToInt32(hfOrgID.Value) + "',";
                    sqlStr += "post_no= '" + this.txtPOST_NO.Text.Trim() + "',";
                    sqlStr += "employee_name= '" + this.txtEMPLOYEE_NAME.Text.Trim() + "',";
                    sqlStr += "pinyin_code= '" + this.txtPinYin.Text.Trim() + "',";
                    sqlStr += "post_id= '" + Convert.ToInt32(this.hfPostID.Value) + "',";
                    sqlStr += "now_post_id= " + (hfNowPostID.Value == "" ? "null" : "'" + hfNowPostID.Value + "'") + ",";
                    sqlStr += "sex= '" + this.ddlSex.SelectedValue + "',";
                    sqlStr += "birthday=to_date('" + birthday + "','yyyy-mm-dd hh24:mi:ss'),";
                    sqlStr += "native_place= '" + this.txtNATIVE_PLACE.Text.Trim() + "',";
                    sqlStr += "folk= '" + this.txtFOLK.Text.Trim() + "',";
                    sqlStr += "wedding= '" + Convert.ToInt32(this.rblWEDDING.SelectedValue) + "',";
                    sqlStr += "begin_date= to_date('" + begin_date + "','yyyy-mm-dd hh24:mi:ss'),";
                    sqlStr += "IsOnPost= '" + ISONPOST + "',";
                    sqlStr += "memo= '" + this.txtMEMO.Text.Trim() + "',";
                    sqlStr += "is_group_leader= '" + Convert.ToInt32(this.ddlIsGroup.SelectedValue) + "',";
                    sqlStr += "technician_type_id = '" + int.Parse(this.ddlTECHNICIAN_TYPE_ID.SelectedValue) + "',";
                    sqlStr += "technical_title_id='" + int.Parse(this.ddlTECHNICAL_TITLE_ID.SelectedValue) + "',";
                    sqlStr += "work_no='" + this.txtWORK_NO.Text.Trim() + "',";
                    sqlStr += "identity_cardno='" + this.txtIDENTITY_CARDNO.Text.Trim() + "',";
                    sqlStr += "political_status_id='" + int.Parse(this.ddlPOLITICAL_STATUS.SelectedValue) + "',";
                    sqlStr += "join_rail_date=to_date('" + join_rail_date + "','yyyy-mm-dd hh24:mi:ss'),";
                    sqlStr += "education_level_id='" + int.Parse(this.DDLeducation_level_id.SelectedValue) + "',";
                    sqlStr += "employee_type_id='" + int.Parse(this.ddlEMPLOYEE_TYPE_ID.SelectedValue) + "',";
                    sqlStr += "second_post_id=" + (this.hfSECOND_POST_ID.Value == "" ? "NULL" : hfSECOND_POST_ID.Value) +
                              ",";
                    sqlStr += "third_post_id=" + (this.hfTHIRD_POST_ID.Value == "" ? "NULL" : hfTHIRD_POST_ID.Value) +
                              ",";

                    sqlStr += "workgroupleader_type_id='" + int.Parse(this.ddlWORKGROUPLEADER_TYPE_ID.SelectedValue) +
                              "'," +
                              "workgroupleader_order_date=to_date('" + workgroupleader_order_date +
                              "','yyyy-mm-dd hh24:mi:ss')," +
                              "education_employee_type_id='" +
                              int.Parse(this.ddlEDUCATION_EMPLOYEE_TYPE_ID.SelectedValue) + "'," +
                              "committee_head_ship_id='" + int.Parse(this.ddlCOMMITTEE_HEAD_SHIP_ID.SelectedValue) +
                              "'," +
                              "isregistered='" + int.Parse(this.ddlISREGISTERED.SelectedValue) + "'," +
                              "employee_transport_type_id='" +
                              int.Parse(this.ddlEMPLOYEE_TRANSPORT_TYPE_ID.SelectedValue) + "'," +
                              "award_date=to_date('" + award_date + "','yyyy-mm-dd hh24:mi:ss')," +
                              "could_post_id='" + this.hfCOULD_POST_ID.Value.Trim().ToString() + "'," +
                              "TECHNICAL_DATE = to_date('" + technicalDate + "','yyyy-mm-dd hh24:mi:ss')," +
                              "TECHNICAL_TITLE_DATE = to_date('" + technicalTitleDate + "','yyyy-mm-dd hh24:mi:ss')," +
                              "POST_DATE = to_date('" + postDate + "','yyyy-mm-dd hh24:mi:ss')," +
                              "GRADUATE_DATE = to_date('" + graduateDate + "','yyyy-mm-dd hh24:mi:ss')," +
                              "GRADUATE_UNIVERSITY = '" + this.txtFinishSchool.Text + "'," +
                              "STUDY_MAJOR = '" + this.txtMajor.Text + "'," +
                              "UNIVERSITY_TYPE = '" + this.dropSchoolCategory.SelectedValue + "'," +
                              "TECHNICAL_CODE = '" + this.txtTechnicalCode.Text + "'," +
                              "Safe_Level_ID=" + (ddlSafe.SelectedValue == "" ? "NULL" : ddlSafe.SelectedValue) +
                              " where employee_id = " + id;
                }
                else if (typeBool == 2)
                {
                    sqlStr = "select EMPLOYEE_SEQ.NEXTVAL from dual";
                    id     = ora.RunSqlDataSet(sqlStr).Tables[0].Rows[0][0].ToString();

                    sqlStr = "insert into employee (employee_id," +
                             "org_id," +
                             "post_no," +
                             "employee_name," +
                             "pinyin_code," +
                             "post_id," +
                             "sex," +
                             "birthday," +
                             "native_place," +
                             "folk," +
                             "wedding," +
                             "begin_date," +
                             "IsOnPost," +
                             "memo," +
                             "is_group_leader," +
                             "technician_type_id," +
                             "technical_title_id," +
                             "work_no," +
                             //"photo," +
                             "identity_cardno," +
                             "political_status_id," +
                             "join_rail_date," +
                             "education_level_id," +
                             "employee_type_id," +
                             "second_post_id," +
                             "third_post_id," +
                             "workgroupleader_type_id," +
                             "workgroupleader_order_date," +
                             "education_employee_type_id," +
                             "committee_head_ship_id," +
                             "isregistered," +
                             "employee_transport_type_id," +
                             "award_date," +
                             "could_post_id," +
                             "TECHNICAL_DATE," +
                             "TECHNICAL_TITLE_DATE," +
                             "POST_DATE," +
                             "GRADUATE_UNIVERSITY," +
                             "GRADUATE_DATE," +
                             "STUDY_MAJOR," +
                             "UNIVERSITY_TYPE," +
                             "TECHNICAL_CODE,Safe_Level_ID,Now_Post_ID)" +
                             " values(" + id + "," +
                             Convert.ToInt32(this.hfOrgID.Value) + ",'" +
                             this.txtPOST_NO.Text.Trim().ToString() + "','" +
                             this.txtEMPLOYEE_NAME.Text.Trim().ToString() + "','" +
                             Pub.GetChineseSpell(this.txtEMPLOYEE_NAME.Text.Trim().ToString()) + "'," +
                             Convert.ToInt32(this.hfPostID.Value) + ",'" +
                             this.ddlSex.SelectedValue + "'," +
                             "to_date('" + birthday + "','yyyy-mm-dd hh24:mi:ss'),'" +
                             this.txtNATIVE_PLACE.Text.Trim().ToString() + "','" +
                             this.txtFOLK.Text.Trim().ToString() + "'," +
                             Convert.ToInt32(this.rblWEDDING.SelectedValue) + "," +
                             "to_date('" + begin_date + "','yyyy-mm-dd hh24:mi:ss')," +
                             ISONPOST + ",'" +
                             this.txtMEMO.Text.Trim().ToString() + "'," +
                             Convert.ToInt32(this.ddlIsGroup.SelectedValue) + "," +
                             int.Parse(this.ddlTECHNICIAN_TYPE_ID.SelectedValue) + "," +
                             int.Parse(this.ddlTECHNICAL_TITLE_ID.SelectedValue) + ",'" +
                             this.txtWORK_NO.Text.Trim().ToString() + "','" +
                             this.txtIDENTITY_CARDNO.Text.Trim().ToString() + "'," +
                             int.Parse(this.ddlPOLITICAL_STATUS.SelectedValue) + "," +
                             "to_date('" + join_rail_date + "','yyyy-mm-dd hh24:mi:ss')," +
                             int.Parse(this.DDLeducation_level_id.SelectedValue) + "," +
                             int.Parse(this.ddlEMPLOYEE_TYPE_ID.SelectedValue) + "," +
                             (this.hfSECOND_POST_ID.Value == "" ? "NULL" : hfSECOND_POST_ID.Value) + "," +
                             (this.hfTHIRD_POST_ID.Value == "" ? "NULL" : hfSECOND_POST_ID.Value) + "," +
                             int.Parse(this.ddlWORKGROUPLEADER_TYPE_ID.SelectedValue) + "," +
                             "to_date('" + workgroupleader_order_date + "','yyyy-mm-dd hh24:mi:ss')," +
                             int.Parse(this.ddlEDUCATION_EMPLOYEE_TYPE_ID.SelectedValue) + "," +
                             int.Parse(this.ddlCOMMITTEE_HEAD_SHIP_ID.SelectedValue) + "," +
                             int.Parse(this.ddlISREGISTERED.SelectedValue) + "," +
                             int.Parse(this.ddlEMPLOYEE_TRANSPORT_TYPE_ID.SelectedValue) + "," +
                             "to_date('" + award_date + "','yyyy-mm-dd hh24:mi:ss'),'" +
                             this.hfCOULD_POST_ID.Value.Trim().ToString() + "'," +
                             "to_date('" + technicalDate + "','yyyy-mm-dd hh24:mi:ss')," +
                             "to_date('" + technicalTitleDate + "','yyyy-mm-dd hh24:mi:ss')," +
                             "to_date('" + postDate + "','yyyy-mm-dd hh24:mi:ss')," +
                             "'" + this.txtFinishSchool.Text + "'," +
                             "to_date('" + graduateDate + "','yyyy-mm-dd hh24:mi:ss')," +
                             "'" + this.txtMajor.Text + "'," +
                             "'" + this.dropSchoolCategory.SelectedValue + "'," +
                             "'" + this.txtTechnicalCode.Text + "'," +
                             (ddlSafe.SelectedValue == "" ? "NULL" : ddlSafe.SelectedValue) + "," +
                             (hfNowPostID.Value == "" ? "null" : "'" + hfNowPostID.Value + "'") + ")";
                }

                try
                {
                    ora.ExecuteNonQuery(sqlStr);

                    if (typeBool == 2)
                    {
                        sqlStr = "insert into Employee_Photo values(" + id + ",null)";
                        ora.ExecuteNonQuery(sqlStr);
                    }

                    SystemUserBLL objSystemBll = new SystemUserBLL();
                    if (type == "1")
                    {
                        RailExam.Model.SystemUser objSystem = objSystemBll.GetUserByEmployeeID(Convert.ToInt32(id));
                        if (objSystem != null)
                        {
                            objSystem.UserID = txtWORK_NO.Text.Trim() == string.Empty
                                                   ? txtIDENTITY_CARDNO.Text.Trim()
                                                   : txtWORK_NO.Text.Trim();
                            objSystemBll.UpdateUser(objSystem);
                        }
                        else
                        {
                            objSystem            = new SystemUser();
                            objSystem.EmployeeID = Convert.ToInt32(id);
                            objSystem.Memo       = "";
                            objSystem.Password   = "******";
                            objSystem.RoleID     = 0;
                            objSystem.UserID     = txtWORK_NO.Text.Trim() == string.Empty
                                                   ? txtIDENTITY_CARDNO.Text.Trim()
                                                   : txtWORK_NO.Text.Trim();
                            objSystemBll.AddUser(objSystem);
                        }
                    }
                    else
                    {
                        RailExam.Model.SystemUser objSystem = new SystemUser();
                        objSystem.EmployeeID = Convert.ToInt32(id);
                        objSystem.Memo       = "";
                        objSystem.Password   = "******";
                        objSystem.RoleID     = 0;
                        objSystem.UserID     = txtWORK_NO.Text.Trim() == string.Empty
                                               ? txtIDENTITY_CARDNO.Text.Trim()
                                               : txtWORK_NO.Text.Trim();
                        objSystemBll.AddUser(objSystem);
                    }

                    if (!string.IsNullOrEmpty(fileUpload1.PostedFile.FileName))
                    {
                        string str = Server.MapPath("/RailExamBao/Excel/image");
                        if (!Directory.Exists(str))
                        {
                            Directory.CreateDirectory(str);
                        }

                        string strFileName = Path.GetFileName(fileUpload1.PostedFile.FileName);
                        string strPath     = Server.MapPath("/RailExamBao/Excel/image/" + strFileName);

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

                        FileInfo fi         = new FileInfo(fileUpload1.PostedFile.FileName);
                        string   extensions = ".jpg,.jpeg,.gif";
                        if (!extensions.Contains(fi.Extension.ToLower()))
                        {
                            this.ClientScript.RegisterStartupScript(this.GetType(), "OK",
                                                                    "alert('只能上传GIF, JPEG(JPG)格式的图片!');", true);
                            return;
                        }

                        ((HttpPostedFile)fileUpload1.PostedFile).SaveAs(strPath);

                        this.myImagePhoto.ImageUrl = strPath;
                        AddImage(Int32.Parse(id), strPath);
                    }
                    SystemLogBLL objLogBll = new SystemLogBLL();
                    objLogBll.WriteLog("保存职工:" + txtEMPLOYEE_NAME.Text + "的档案信息!");
                }
                catch (Exception ex)
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "OK", "alert('" + ex.Message + "');", true);
                    return;
                }
                string          OrgID  = this.hfOrgID.Value;
                OrganizationBLL objBll = new OrganizationBLL();
                string          idpath = Request.QueryString.Get("idpath");

                if (string.IsNullOrEmpty(Request.QueryString.Get("style")))
                {
                    string strQuery = Request.QueryString.Get("strQuery");
                    this.ClientScript.RegisterStartupScript(this.GetType(), "OK",
                                                            "this.location.href='EmployeeInfo.aspx?ID=" +
                                                            OrgID + "&idpath=" + idpath + "&type=Org&strQuery=" + strQuery + "';", true);
                }
                else
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "OK", "top.returnValue='true';top.close();",
                                                            true);
                }
            }
        }
        private void SaveEmployeeInfo()
        {
            EmployeeBLL objBll =new EmployeeBLL();
            RailExam.Model.Employee obj = new RailExam.Model.Employee();
            obj.EmployeeName = txtEmployeeNameEdit.Text;
            obj.WorkNo = txtWorkNoEdit.Text;
            obj.Address = txtAddress.Text;
            obj.BeginDate = DateTime.Parse(dateBeginDate.DateValue.ToString());
            obj.Birthday = DateTime.Parse(dateBirthday.DateValue.ToString());
            obj.Folk = txtFolk.Text;
            obj.PostID = Convert.ToInt32(hfPostID.Value);
            obj.OrgID = Convert.ToInt32(hfOrgID.Value);
            obj.Sex = ddlSex.SelectedValue;
            obj.NativePlace = txtNativePlace.Text;
            obj.Wedding = Convert.ToInt32(rblWedding.SelectedValue);
            obj.WorkPhone = txtWorkPhoneEdit.Text;
            obj.HomePhone = txtHomePhone.Text;
            obj.MobilePhone = txtMobilePhone.Text;
            obj.PostCode = txtPostCode.Text;
            obj.IsOnPost = !chDimission.Checked;
            obj.Memo = txtMemoEdit.Text;
            obj.IsGroupLeader = Convert.ToInt32(ddlIsGroup.SelectedValue);
            obj.TechnicianTypeID = Convert.ToInt32(ddlTech.SelectedValue);
            obj.PostNo = txtPostNo.Text;
            obj.PinYinCode = Pub.GetChineseSpell(obj.EmployeeName);

           SystemUserBLL objSystemBll = new SystemUserBLL();
            if (hfType.Value == "Edit")
            {
                obj.EmployeeID = Convert.ToInt32(Request.QueryString.Get("id"));
                objBll.UpdateEmployee(obj);

                RailExam.Model.SystemUser objSystem = objSystemBll.GetUserByEmployeeID(obj.EmployeeID);
                if(objSystem != null)
                {
                    objSystem.RoleID = Convert.ToInt32(ddlRoleNameEdit.SelectedValue);
                    objSystem.UserID = obj.WorkNo;
                    objSystemBll.UpdateUser(objSystem);
                }
                else
                {
                    objSystem = new SystemUser();
                    objSystem.EmployeeID = obj.EmployeeID;
                    objSystem.Memo = "";
                    objSystem.Password = "******";
                    objSystem.RoleID = Convert.ToInt32(ddlRoleNameEdit.SelectedValue);
                    objSystem.UserID = obj.WorkNo;
                    objSystemBll.AddUser(objSystem);
                }
            }
            else
            {
            	obj.LoginTime = 0;
            	obj.LoginCount = 0;
                int id = objBll.AddEmployee(obj);
                RailExam.Model.SystemUser objSystem = new SystemUser();
                objSystem.EmployeeID = id;
                objSystem.Memo = "";
                objSystem.Password = "******";
                objSystem.RoleID = Convert.ToInt32(ddlRoleNameEdit.SelectedValue);
                objSystem.UserID = obj.WorkNo;
                objSystemBll.AddUser(objSystem);
            }
        }
Exemple #5
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
        }
Exemple #6
0
        protected void btnImport_Click(object sender, EventArgs e)
        {
            if (File1.FileName == "")
            {
                SessionSet.PageMessage = "请浏览选择Excel文件!";
                return;
            }
            string strFileName = Path.GetFileName(File1.PostedFile.FileName);
            string strPath     = Server.MapPath("/RailExamBao/Excel/" + strFileName);

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

            ((HttpPostedFile)File1.PostedFile).SaveAs(strPath);

            string strSql;

            string strODConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strPath + "; Extended Properties=Excel 8.0;";

            strSql = "select 顺号,站段名称,车间,班组,姓名,系统,工种,职名,性别,工作证号,是否班组长,技能等级 from [Sheet1$]";
            OleDbConnection ODcon = new OleDbConnection(strODConn);
            DataSet         ds    = new DataSet();

            try
            {
                ODcon.Open();
                OleDbCommand     OCom = new OleDbCommand(strSql, ODcon);
                OleDbDataAdapter ODA  = new OleDbDataAdapter(OCom);
                ODA.Fill(ds);
            }
            catch
            {
                SessionSet.PageMessage = "请核对Excel文件的格式!";
                return;
            }
            finally
            {
                ODcon.Close();
            }

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

            try
            {
                DataTable  dt     = new DataTable();
                DataColumn dcnew1 = dt.Columns.Add("ExcelNo");
                DataColumn dcnew2 = dt.Columns.Add("WorkNo");
                DataColumn dcnew3 = dt.Columns.Add("EmployeeName");
                DataColumn dcnew4 = dt.Columns.Add("Sex");
                DataColumn dcnew5 = dt.Columns.Add("OrgPath");
                DataColumn dcnew6 = dt.Columns.Add("PostPath");
                DataColumn dcnew7 = dt.Columns.Add("IsGroup");
                DataColumn dcnew8 = dt.Columns.Add("Tech");

                OrganizationBLL objOrgBll    = new OrganizationBLL();
                PostBLL         objPostBll   = new PostBLL();
                EmployeeBLL     objBll       = new EmployeeBLL();
                SystemUserBLL   objSystemBll = new SystemUserBLL();

                if (ds.Tables[0].Rows.Count == 0)
                {
                    SessionSet.PageMessage = "Excel中没有任何记录,请核对!";
                    return;
                }

                if (ds.Tables[0].Rows[0]["站段名称"].ToString() != txtOrg.Text.Substring(txtOrg.Text.IndexOf('/') + 1))
                {
                    SessionSet.PageMessage = "站段选择错误,请核对!";
                    return;
                }

                //objBll.DeleteEmployeeByOrgID(Convert.ToInt32(hfOrg.Value));

                Hashtable htOrg  = GetOrgHash(Convert.ToInt32(hfOrg.Value));
                Hashtable htPost = GetPostHash();

                DataColumn dc1 = ds.Tables[0].Columns.Add("OrgPath");
                DataColumn dc2 = ds.Tables[0].Columns.Add("PostPath");
                DataColumn dc3 = ds.Tables[0].Columns.Add("OrgID");
                DataColumn dc4 = ds.Tables[0].Columns.Add("PostID");
                DataColumn dc5 = ds.Tables[0].Columns.Add("IsGroup");
                DataColumn dc6 = ds.Tables[0].Columns.Add("TechID");
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if (dr["班组"].ToString() != "")
                    {
                        dr["OrgPath"] = dr["站段名称"].ToString().Trim() + "-" + dr["车间"].ToString().Trim() + "-" + dr["班组"].ToString().Trim();
                    }
                    else
                    {
                        dr["OrgPath"] = dr["站段名称"].ToString().Trim() + "-" + dr["车间"].ToString().Trim();
                    }
                    dr["PostPath"] = dr["系统"].ToString().Trim() + "-" + dr["工种"].ToString().Trim() + "-" + dr["职名"].ToString().Trim();

                    //dr["OrgID"] = objOrgBll.GetOrgIDByOrgNamePath(dr["OrgPath"].ToString()).ToString();
                    //dr["PostID"] = objPostBll.GetPostIDByPostNamePath(dr["PostPath"].ToString()).ToString();

                    if (dr["是否班组长"].ToString() == "是")
                    {
                        dr["IsGroup"] = "1";
                    }
                    else
                    {
                        dr["IsGroup"] = "0";
                    }

                    if (dr["技能等级"].ToString() == "高级技师")
                    {
                        dr["TechID"] = "3";
                    }
                    else if (dr["技能等级"].ToString() == "技师")
                    {
                        dr["TechID"] = "2";
                    }
                    else
                    {
                        dr["TechID"] = "1";
                    }

                    if (!htOrg.ContainsKey(dr["OrgPath"].ToString()) || !htPost.ContainsKey(dr["PostPath"].ToString()) || dr["工作证号"].ToString() == "")
                    {
                        DataRow drnew = dt.NewRow();
                        drnew["ExcelNo"]      = dr["顺号"].ToString();
                        drnew["WorkNo"]       = dr["工作证号"].ToString();
                        drnew["EmployeeName"] = dr["姓名"].ToString();
                        drnew["Sex"]          = dr["性别"].ToString();
                        drnew["OrgPath"]      = dr["OrgPath"].ToString();
                        drnew["PostPath"]     = dr["PostPath"].ToString();
                        drnew["IsGroup"]      = dr["是否班组长"].ToString();
                        drnew["Tech"]         = dr["技能等级"].ToString();
                        dt.Rows.Add(drnew);
                    }
                    else
                    {
                        dr["OrgID"]  = htOrg[dr["OrgPath"].ToString()].ToString();
                        dr["PostID"] = htPost[dr["PostPath"].ToString()].ToString();
                        RailExam.Model.Employee obj = new RailExam.Model.Employee();
                        obj.EmployeeName     = dr["姓名"].ToString().Trim();
                        obj.OrgID            = Convert.ToInt32(dr["OrgID"].ToString());
                        obj.PostID           = Convert.ToInt32(dr["PostID"].ToString());
                        obj.Sex              = dr["性别"].ToString().Trim();
                        obj.WorkNo           = dr["工作证号"].ToString().Trim();
                        obj.IsGroupLeader    = Convert.ToInt32(dr["IsGroup"].ToString());
                        obj.TechnicianTypeID = Convert.ToInt32(dr["TechID"].ToString());
                        obj.PinYinCode       = Pub.GetChineseSpell(obj.EmployeeName);
                        obj.IsOnPost         = true;
                        objEmployeeList.Add(obj);
                    }
                }

                Grid1.DataSource = dt;
                Grid1.DataBind();

                lbltitle.Visible = true;
                Grid1.Visible    = true;
                btnExcel.Visible = false;

                objBll.AddEmployeeImport(objEmployeeList);
            }
            catch
            {
                SessionSet.PageMessage = "导入失败!";
                return;
            }
        }
Exemple #7
0
        protected void btnModify_Click(object sender, EventArgs e)
        {
            //不符合数据的数据源
            DataTable  dt     = new DataTable();
            DataColumn dcnew1 = dt.Columns.Add("ExcelNo");
            DataColumn dcnew2 = dt.Columns.Add("WorkNo");
            DataColumn dcnew3 = dt.Columns.Add("EmployeeName");
            DataColumn dcnew4 = dt.Columns.Add("Sex");
            DataColumn dcnew5 = dt.Columns.Add("OrgPath");
            DataColumn dcnew6 = dt.Columns.Add("PostPath");
            DataColumn dcnew7 = dt.Columns.Add("IsGroup");
            DataColumn dcnew8 = dt.Columns.Add("Tech");
            DataColumn dcnew9 = dt.Columns.Add("ErrorReason");

            Hashtable htOrg  = GetOrgHash(0);
            Hashtable htPost = GetPostHash();


            #region 读取Excel文件
            if (File1.FileName == "")
            {
                SessionSet.PageMessage = "请浏览选择Excel文件!";
                return;
            }
            string strFileName = Path.GetFileName(File1.PostedFile.FileName);
            string strPath     = Server.MapPath("/RailExamBao/Excel/" + strFileName);

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

            ((HttpPostedFile)File1.PostedFile).SaveAs(strPath);

            string strSql;

            string strODConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strPath + "; Extended Properties=Excel 8.0;";
            strSql = "select 序号,员工编码,工作证号,性别,姓名,单位,工作岗位,员工编码,是否离职 from [Sheet1$]";
            OleDbConnection ODcon = new OleDbConnection(strODConn);
            DataSet         ds    = new DataSet();
            try
            {
                ODcon.Open();
                OleDbCommand     OCom = new OleDbCommand(strSql, ODcon);
                OleDbDataAdapter ODA  = new OleDbDataAdapter(OCom);
                ODA.Fill(ds);
            }
            catch
            {
                SessionSet.PageMessage = "请核对Excel文件的格式!";
                return;
            }
            finally
            {
                ODcon.Close();
            }
            #endregion

            #region 检验数据合理性
            try
            {
                if (ds.Tables[0].Rows.Count == 0)
                {
                    SessionSet.PageMessage = "Excel中没有任何记录,请核对!";
                    return;
                }

                DataColumn dc1 = ds.Tables[0].Columns.Add("OrgID");
                DataColumn dc2 = ds.Tables[0].Columns.Add("PostID");
                DataColumn dc3 = ds.Tables[0].Columns.Add("Dimission");

                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if (dr["是否离职"].ToString() == "是")
                    {
                        dr["Dimission"] = "1";
                    }
                    else
                    {
                        dr["Dimission"] = "0";
                    }

                    if (!htOrg.ContainsKey(dr["单位"].ToString()))
                    {
                        DataRow drnew = dt.NewRow();
                        drnew["ExcelNo"]      = dr["序号"].ToString();
                        drnew["WorkNo"]       = dr["员工编码"].ToString();
                        drnew["EmployeeName"] = dr["姓名"].ToString();
                        drnew["Sex"]          = dr["性别"].ToString();
                        drnew["OrgPath"]      = dr["单位"].ToString();
                        drnew["PostPath"]     = dr["工作岗位"].ToString();
                        drnew["IsGroup"]      = "";
                        drnew["Tech"]         = "";
                        drnew["ErrorReason"]  = "组织机构(单位)在系统中不存在";
                        dt.Rows.Add(drnew);
                    }

                    if (!htPost.ContainsKey(dr["工作岗位"].ToString()))
                    {
                        DataRow drnew = dt.NewRow();
                        drnew["ExcelNo"]      = dr["序号"].ToString();
                        drnew["WorkNo"]       = dr["员工编码"].ToString();
                        drnew["EmployeeName"] = dr["姓名"].ToString();
                        drnew["Sex"]          = dr["性别"].ToString();
                        drnew["OrgPath"]      = dr["单位"].ToString();
                        drnew["PostPath"]     = dr["工作岗位"].ToString();
                        drnew["IsGroup"]      = "";
                        drnew["Tech"]         = "";
                        drnew["ErrorReason"]  = "工作岗位在系统中不存在";
                        dt.Rows.Add(drnew);
                    }

                    if (dr["员工编码"].ToString() == "")
                    {
                        DataRow drnew = dt.NewRow();
                        drnew["ExcelNo"]      = dr["序号"].ToString();
                        drnew["WorkNo"]       = dr["员工编码"].ToString();
                        drnew["EmployeeName"] = dr["姓名"].ToString();
                        drnew["Sex"]          = dr["性别"].ToString();
                        drnew["OrgPath"]      = dr["单位"].ToString();
                        drnew["PostPath"]     = dr["工作岗位"].ToString();
                        drnew["IsGroup"]      = "";
                        drnew["Tech"]         = "";
                        drnew["ErrorReason"]  = "员工编码不能为空";
                        dt.Rows.Add(drnew);
                    }
                }
            }
            catch
            {
                SessionSet.PageMessage = "请检查单位和工作岗位是否设置正确!";
                return;
            }
            #endregion

            #region 检验Excel中员工编码
            string str    = "";
            string strLen = "";

            Hashtable htWorkNo = new Hashtable();

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                if (htWorkNo.ContainsKey(dr["员工编码"].ToString().Trim()))
                {
                    if (str == "")
                    {
                        str += dr["员工编码"].ToString();
                    }
                    else
                    {
                        str += "," + dr["员工编码"].ToString();
                    }

                    DataRow drnew = dt.NewRow();
                    drnew["ExcelNo"]      = dr["序号"].ToString();
                    drnew["WorkNo"]       = dr["员工编码"].ToString();
                    drnew["EmployeeName"] = dr["姓名"].ToString();
                    drnew["Sex"]          = dr["性别"].ToString();
                    drnew["OrgPath"]      = dr["单位"].ToString();
                    drnew["PostPath"]     = dr["工作岗位"].ToString();
                    drnew["IsGroup"]      = "";
                    drnew["Tech"]         = "";
                    drnew["ErrorReason"]  = "员工编码在Excel中重复";
                    dt.Rows.Add(drnew);
                }
                else
                {
                    if (dr["员工编码"].ToString() != "")
                    {
                        htWorkNo[dr["员工编码"].ToString()] = dr["员工编码"].ToString();
                    }
                }

                if (dr["员工编码"].ToString().Trim().Length > 10)
                {
                    if (strLen == "")
                    {
                        strLen += dr["员工编码"].ToString();
                    }
                    else
                    {
                        strLen += "," + dr["员工编码"].ToString();
                    }

                    DataRow drnew = dt.NewRow();
                    drnew["ExcelNo"]      = dr["序号"].ToString();
                    drnew["WorkNo"]       = dr["员工编码"].ToString();
                    drnew["EmployeeName"] = dr["姓名"].ToString();
                    drnew["Sex"]          = dr["性别"].ToString();
                    drnew["OrgPath"]      = dr["单位"].ToString();
                    drnew["PostPath"]     = dr["工作岗位"].ToString();
                    drnew["IsGroup"]      = "";
                    drnew["Tech"]         = "";
                    drnew["ErrorReason"]  = "员工编码不能大于10位";
                    dt.Rows.Add(drnew);
                }
            }

            #endregion

            #region 检验全局员工编码
            str = "";
            EmployeeBLL objBll = new EmployeeBLL();
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                if (dr["员工编码"].ToString().Trim() != null)
                {
                    int count = objBll.GetEmployeeByWorkNo(dr["员工编码"].ToString());
                    if (count > 0)
                    {
                        if (str == "")
                        {
                            str += dr["员工编码"].ToString();
                        }
                        else
                        {
                            str += "," + dr["员工编码"].ToString();
                        }

                        DataRow drnew = dt.NewRow();
                        drnew["ExcelNo"]      = dr["序号"].ToString();
                        drnew["WorkNo"]       = dr["员工编码"].ToString();
                        drnew["EmployeeName"] = dr["姓名"].ToString();
                        drnew["Sex"]          = dr["性别"].ToString();
                        drnew["OrgPath"]      = dr["单位"].ToString();
                        drnew["PostPath"]     = dr["工作岗位"].ToString();
                        drnew["IsGroup"]      = "";
                        drnew["Tech"]         = "";
                        drnew["ErrorReason"]  = "员工编码在系统中重复";
                        dt.Rows.Add(drnew);
                    }
                }
            }

            lbltitle.Text    = "不符合要求的数据!";
            lbltitle.Visible = true;
            Grid1.Visible    = true;

            //if (str != "")
            //{
            //    SessionSet.PageMessage = "有重复的工作证号:" + str;
            //    return;
            //}
            #endregion

            int n = 0;
            foreach (DataRow dr in dt.Rows)
            {
                if (dr["ExcelNo"].ToString() != "" || dr["WorkNo"].ToString() != "" || dr["OrgPath"].ToString() != "" || dr["PostPath"].ToString() != "")
                {
                    n = n + 1;
                }
            }

            if (n > 0)
            {
                Grid1.DataSource = dt;
                Grid1.DataBind();

                lbltitle.Text          = "不符合要求的数据";
                lbltitle.Visible       = true;
                Grid1.Visible          = true;
                SessionSet.PageMessage = "请核对Excel数据后,再重新导入!";
                return;
            }
            else
            {
                lbltitle.Text = "";
            }

            #region 导入数据
            //try
            //{
            IList <RailExam.Model.Employee> objEmployeeUpdateList = new List <RailExam.Model.Employee>();
            IList <RailExam.Model.Employee> objEmployeeAddList    = new List <RailExam.Model.Employee>();
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                if (dr["员工编码"].ToString() != "")
                {
                    dr["OrgID"]  = htOrg[dr["单位"].ToString().Trim()].ToString();
                    dr["PostID"] = htPost[dr["工作岗位"].ToString().Trim()].ToString();
                    RailExam.Model.Employee obj = new RailExam.Model.Employee();
                    obj.EmployeeID   = Convert.ToInt32(dr["员工编码"].ToString());
                    obj.EmployeeName = dr["姓名"].ToString().Trim();
                    obj.OrgID        = Convert.ToInt32(dr["OrgID"].ToString());
                    obj.PostID       = Convert.ToInt32(dr["PostID"].ToString());
                    obj.Sex          = dr["性别"].ToString().Trim();
                    obj.WorkNo       = dr["员工编码"].ToString().Trim();
                    obj.PostNo       = dr["工作证号"].ToString();
                    obj.PinYinCode   = Pub.GetChineseSpell(obj.EmployeeName);
                    if (dr["Dimission"].ToString() == "1")
                    {
                        obj.IsOnPost = false;
                    }
                    else
                    {
                        obj.IsOnPost = true;
                    }
                    objEmployeeUpdateList.Add(obj);
                }
                else
                {
                    dr["OrgID"]  = htOrg[dr["单位"].ToString().Trim()].ToString();
                    dr["PostID"] = htPost[dr["工作岗位"].ToString().Trim()].ToString();
                    RailExam.Model.Employee obj = new RailExam.Model.Employee();
                    obj.EmployeeName     = dr["姓名"].ToString().Trim();
                    obj.OrgID            = Convert.ToInt32(dr["OrgID"].ToString());
                    obj.PostID           = Convert.ToInt32(dr["PostID"].ToString());
                    obj.Sex              = dr["性别"].ToString().Trim();
                    obj.WorkNo           = dr["员工编码"].ToString().Trim();
                    obj.PostNo           = dr["工作证号"].ToString();
                    obj.PinYinCode       = Pub.GetChineseSpell(obj.EmployeeName);
                    obj.IsOnPost         = true;
                    obj.TechnicianTypeID = 1;
                    obj.IsGroupLeader    = 0;
                    objEmployeeAddList.Add(obj);
                }
            }
            objBll.UpdateEmployee(objEmployeeUpdateList, objEmployeeAddList);

            SessionSet.PageMessage = "导入成功!";
            dt.Clear();
            Grid1.DataSource = dt;
            Grid1.DataBind();
            //}
            //catch(Exception ex)
            //{
            //    SessionSet.PageMessage = "导入失败:" + ex.Message;
            //    return;
            //}
            #endregion
        }
Exemple #8
0
        protected void btnSave2_Click(object sender, EventArgs e)
        {
            OrganizationBLL objBll = new OrganizationBLL();

            if (txtTime.Text != "")
            {
                if (txtTime.Text.IndexOf(":") == -1)
                {
                    SessionSet.PageMessage = "同步时间格式错误!";
                    return;
                }
                else
                {
                    if (txtTime.Text.Length > 5 || txtTime.Text.Length < 4)
                    {
                        SessionSet.PageMessage = "同步时间格式错误!";
                        return;
                    }
                    else
                    {
                        string[] str = txtTime.Text.Split(':');
                        if (str.Length > 2)
                        {
                            SessionSet.PageMessage = "同步时间格式错误!";
                            return;
                        }
                        else
                        {
                            try
                            {
                                int h = Convert.ToInt32(str[0]);
                                int m = Convert.ToInt32(str[1]);

                                if (h > 23 || h < 0)
                                {
                                    SessionSet.PageMessage = "同步时间格式错误!";
                                    return;
                                }
                                if (m > 59 || m < 0)
                                {
                                    SessionSet.PageMessage = "同步时间格式错误!";
                                    return;
                                }
                            }
                            catch
                            {
                                SessionSet.PageMessage = "同步时间格式错误!";
                                return;
                            }
                        }
                    }
                }
            }
            objBll.UpdateOrgSynchronizeTime(Convert.ToInt32(OrgList.SelectedValue), txtTime.Text);

            string strPath = "C:\\oracle\\product\\10.2.0\\db_1\\NETWORK\\ADMIN\\tnsnames.ora";

            if (txtIPAddress.Text.Trim() != "")
            {
                if (!Regex.IsMatch(txtIPAddress.Text, "^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$"))
                {
                    SessionSet.PageMessage = "IP地址格式不正确!";
                    return;
                }

                if (File.Exists(strPath))
                {
                    string       strName    = Pub.GetChineseSpell(OrgList.SelectedItem.Text);
                    StreamReader objReader  = new StreamReader(strPath, true);
                    string       strContent = objReader.ReadToEnd();
                    objReader.Close();
                    string strOldIP = objBll.GetOrgIPAddress(Convert.ToInt32(OrgList.SelectedValue));
                    if (strContent.IndexOf(strOldIP) == -1 || strOldIP == "")
                    {
                        //新增
                        StreamWriter objWriter = new StreamWriter(strPath, true);
                        objWriter.WriteLine(strName + OrgList.SelectedValue + " =");
                        objWriter.WriteLine("  (DESCRIPTION =");
                        objWriter.WriteLine("    (ADDRESS_LIST =");
                        objWriter.WriteLine("      (ADDRESS = (PROTOCOL = TCP)(HOST = " + txtIPAddress.Text + ")(PORT = 1521))");
                        objWriter.WriteLine("    )");
                        objWriter.WriteLine("    (CONNECT_DATA =");
                        objWriter.WriteLine("      (SERVICE_NAME = RailExam)");
                        objWriter.WriteLine("    )");
                        objWriter.WriteLine("  )");
                        objWriter.WriteLine("");
                        objWriter.Close();
                    }
                    else
                    {
                        //修改
                        strContent = strContent.Replace(strOldIP, txtIPAddress.Text);
                        StreamWriter objWriter = new StreamWriter(strPath, false);
                        objWriter.Write(strContent);
                        objWriter.Close();
                    }
                    objBll.UpdateOrgService(Convert.ToInt32(OrgList.SelectedValue), strName + OrgList.SelectedValue, txtIPAddress.Text, chkUpload.Checked);
                }
            }
            else
            {
                if (File.Exists(strPath))
                {
                    string strOldIP   = objBll.GetOrgIPAddress(Convert.ToInt32(OrgList.SelectedValue));
                    string strNetName = objBll.GetOrgNetName(Convert.ToInt32(OrgList.SelectedValue));

                    if (strOldIP != "")
                    {
                        //删除
                        StreamReader objReader  = new StreamReader(strPath, true);
                        string       strContent = objReader.ReadToEnd();
                        objReader.Close();
                        string str = strNetName + "=" + "\r\n"
                                     + "  (DESCRIPTION =" + "\r\n"
                                     + "    (ADDRESS_LIST =" + "\r\n"
                                     + "      (ADDRESS = (PROTOCOL = TCP)(HOST = " + strOldIP + ")(PORT = 1521))" + "\r\n"
                                     + "    )" + "\r\n"
                                     + "    (CONNECT_DATA =" + "\r\n"
                                     + "      (SERVICE_NAME = RailExam)" + "\r\n"
                                     + "    )" + "\r\n"
                                     + "  )" + "\r\n";
                        strContent = strContent.Replace(str, "");
                        StreamWriter objWriter = new StreamWriter(strPath, false);
                        objWriter.Write(strContent);
                        objWriter.Close();
                    }
                    objBll.UpdateOrgService(Convert.ToInt32(OrgList.SelectedValue), "", txtIPAddress.Text, chkUpload.Checked);
                }
            }

            SetControlEnable(2, true);
        }
        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));
        }
        private void SaveEmployeeInfo()
        {
            EmployeeDetailBLL objBll = new EmployeeDetailBLL();

            RailExam.Model.EmployeeDetail obj = new RailExam.Model.EmployeeDetail();
            obj.EmployeeName     = txtEmployeeNameEdit.Text;
            obj.WorkNo           = txtWorkNoEdit.Text;
            obj.Address          = txtAddress.Text;
            obj.BeginDate        = DateTime.Parse(dateBeginDate.DateValue.ToString());
            obj.Birthday         = DateTime.Parse(dateBirthday.DateValue.ToString());
            obj.PostID           = Convert.ToInt32(hfPostID.Value);
            obj.OrgID            = Convert.ToInt32(hfOrgID.Value);
            obj.Sex              = ddlSex.SelectedValue;
            obj.Dimission        = chDimission.Checked;
            obj.HomePhone        = txtHomePhone.Text;
            obj.Memo             = txtMemoEdit.Text;
            obj.IsGroupLeader    = Convert.ToInt32(ddlIsGroup.SelectedValue);
            obj.TechnicianTypeID = Convert.ToInt32(ddlTech.SelectedValue);
            obj.PostNo           = txtPostNo.Text;
            obj.PinYinCode       = Pub.GetChineseSpell(obj.EmployeeName);

            obj.Folk        = txtFolk.Text;
            obj.NativePlace = txtNativePlace.Text;
            obj.Wedding     = Convert.ToInt32(rblWedding.SelectedValue);
            obj.WorkPhone   = txtWorkPhoneEdit.Text;
            obj.PostCode    = txtPostCode.Text;
            obj.MobilePhone = txtMobilePhone.Text;

            obj.WorkDate                = DateTime.Parse(workDate.DateValue.ToString());
            obj.EducationLevelID        = Convert.ToInt32(ddlEducationLevel.SelectedValue);
            obj.PoliticalStatusID       = Convert.ToInt32(ddlPolictical.SelectedValue);
            obj.GraduateUniversity      = txtUniversity.Text;
            obj.StudyMajor              = txtStudy.Text;
            obj.IdentifyCode            = txtIdentifyCode.Text;
            obj.EmployeeTypeID          = Convert.ToInt32(ddlEmployeeTypeID.SelectedValue);
            obj.TechnicalTitleID        = Convert.ToInt32(ddlTechTitle.SelectedValue);
            obj.EmployeeLevelID         = Convert.ToInt32(ddlEmployeeLevel.SelectedValue);
            obj.WorkGroupLeaderTypeID   = Convert.ToInt32(ddlWorkGroup.SelectedValue);
            obj.EducationEmployeeTypeID = Convert.ToInt32(ddlEducationEmployeeType.SelectedValue);
            obj.CommitteeHeadShipID     = Convert.ToInt32(ddlHeadship.SelectedValue);
            obj.EmployeeTransportTypeID = Convert.ToInt32(ddlEmployeeTransportType.SelectedValue);
            obj.TeacherTypeID           = Convert.ToInt32(ddlTeacherType.SelectedValue);

            chkApprove.Checked = (obj.ApprovePost == 1);

            SystemUserBLL objSystemBll = new SystemUserBLL();

            if (hfType.Value == "Edit")
            {
                obj.EmployeeID = Convert.ToInt32(Request.QueryString.Get("id"));
                objBll.UpdateEmployee(obj);

                RailExam.Model.SystemUser objSystem = objSystemBll.GetUserByEmployeeID(obj.EmployeeID);
                objSystem.RoleID = Convert.ToInt32(ddlRoleNameEdit.SelectedValue);
                objSystem.UserID = obj.WorkNo;
                objSystemBll.UpdateUser(objSystem);
            }
            else
            {
                obj.LoginTime  = 0;
                obj.LoginCount = 0;
                int id = objBll.AddEmployee(obj);
                RailExam.Model.SystemUser objSystem = objSystemBll.GetUserByEmployeeID(id);
                objSystem.RoleID = Convert.ToInt32(ddlRoleNameEdit.SelectedValue);
                objSystemBll.UpdateUser(objSystem);
            }
        }