protected void btnAdd_Click(object sender, EventArgs e) { if (IsPageValid()) { try { string strAddress = txtAddress.Text.Trim(); string strCertificate = txtCertificate.Text.Trim(); string strEmployeeName = txtEmployeeName.Text.Trim(); string strIdentyNum = txtIdentyNum.Text.Trim(); string strMajor = txtMajor.Text.Trim(); string strNativePlace = txtNativePlace.Text.Trim(); string strSchool = txtSchool.Text.Trim(); string strEmail = txtEmail.Text.Trim(); string strHomephone = txtHomephone.Text.Trim(); string strMobile = txtMobile.Text.Trim(); string strPhoneExt = txtPhoneExt.Text.Trim(); string strOfficephone = txtOfficephone.Text.Trim(); DateTime dtBirthday = DateTime.Parse(txtBirthday.Text.Trim()); DateTime dtJobTime = DateTime.Parse(txtJobTime.Text.Trim()); DateTime dtJoinTime = DateTime.Parse(txtJoinTime.Text.Trim()); ContactInfo contact = new ContactInfo(); contact.Email = strEmail; contact.Homephone = strHomephone; contact.Mobile = strMobile; contact.PhoneExt = strPhoneExt; contact.Officephone = strOfficephone; contact.Save(); EmployeeInfo Em = new EmployeeInfo(); if (ddlDepart.SelectedValue != "") { Em.DepartId = Convert.ToInt32(ddlDepart.SelectedValue.ToString()); } if (ddlEducation.SelectedValue != "") { Em.EducationId = Convert.ToInt32(ddlEducation.SelectedValue); } if (ddlLanguage.SelectedValue != "") { Em.LanguageId = Convert.ToInt32(ddlLanguage.SelectedValue.ToString()); } if (ddlPosition.SelectedValue != "") { Em.PositionId = Convert.ToInt32(ddlPosition.SelectedValue.ToString()); } if (rblSex.SelectedValue != "") { Em.Sex = Convert.ToInt32(rblSex.SelectedValue.ToString()); } if (rbtnMarrage.SelectedValue != "") { int iMarrage = Convert.ToInt32(rbtnMarrage.SelectedValue.ToString()); } if (rblState.SelectedValue != "") { int iState = Convert.ToInt32(rblState.SelectedValue.ToString()); Em.State = iState; if (iState == 1) { Em.OffJobTime = Convert.ToDateTime(txtLeaveDate.Text.ToString()); } } if (ddlPolitics.SelectedValue != "") { Em.PoliticsId = Convert.ToInt32(ddlPolitics.SelectedValue.ToString()); } Em.EmLevelId = Convert.ToInt32(ddlLevel.SelectedValue.ToString()); Em.EmDangId = Convert.ToInt32(ddlDang.SelectedValue.ToString()); Em.ContactId = contact.ContactId; Em.Address = strAddress; Em.Birthday = dtBirthday; Em.Certificate = strCertificate; Em.EmployeeName = strEmployeeName; Em.IdentyNum = strIdentyNum; Em.JobTime = dtJobTime; Em.JoinTime = dtJoinTime; Em.Major = strMajor; Em.NativePlace = strNativePlace; Em.School = strSchool; Em.Image = "~/Photo/" + ViewState["ImgUrl"]; Em.Qq = txtQq.Text.ToString(); Em.TurnTime = txtTurntime.Text.ToString(); Em.Save(); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('添加用户成功!');</script>"); } catch (Exception Ex) { ClientScript.RegisterStartupScript(this.GetType(), "Save", "alert('添加用户失败:" + Ex.Message + "');", true); } } }