/// <summary>
    /// 初始加载
    /// </summary>
    private void OnStart(object sender, EventArgs e)
    {
        Owen.Model.Model_Doctor model = new Owen.BLL.BLL_Doctor().GetEntity(doctorId);

        if (model == null) return;

        ddlDepartment.SelectedValue = model.DepartmentID.ToString();
        txtName.Text = model.Name;
        txtMobile.Text = model.Mobile;
        txtNativePlace.Text = model.NativePlace;
        txtJobTitle.Text = model.JobTitle;
        ddlSex.SelectedValue = model.Sex.ToString();
        ddlStatus.SelectedValue = model.Status.ToString();
        //医院Id
        int hosId = model.HospitalID;

        //根据医院Id得到所属的城市Id
        Owen.Model.Model_Hospital mHospital = new Owen.BLL.BLL_Hospital().GetEntity(hosId);
        if(mHospital == null ) return;
        int cityId = mHospital.CityID;

        //根据城市Id得到省(直辖市)Id
        Owen.Model.Model_City mCity = new Owen.BLL.BLL_City().GetEntity(cityId);
        if (mCity == null) return;
        int province = mCity.ProvinceID;

        ddlProvince.SelectedValue = province.ToString();
        ddlProvince_SelectedIndexChanged(sender, e);

        ddlCity.SelectedValue = cityId.ToString();
        ddlCity_SelectedIndexChanged(sender, e);

        ddlHospital.SelectedValue = hosId.ToString();
    }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public bool Register(string userName, string pwd)
        {
            bool b = false;
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(pwd))
                return b;

            Owen.Model.Model_UserInfo modelUserInfo = new Model.Model_UserInfo();
            modelUserInfo.UserName = userName;
            //密码已加密,所以,此处不用再加密
            modelUserInfo.Password = pwd;
            modelUserInfo.Age = 0;
            modelUserInfo.Address = string.Empty;
            modelUserInfo.Birth = string.Empty;
            modelUserInfo.Email = string.Empty;
            modelUserInfo.Gender = 0;
            modelUserInfo.Phone = string.Empty;
            modelUserInfo.Status = 0;
            modelUserInfo.UserType = 0;
            modelUserInfo.ZipCode = string.Empty;

            using (TransactionScope tranScope = new TransactionScope())
            {
                int id = dataFactory.UserInfoDal.AddEntity(modelUserInfo).UserID;

                Owen.Model.Model_UserGroupRole mUserGroupRole = new Model.Model_UserGroupRole();

                mUserGroupRole.UserID = id;
                mUserGroupRole.Remark = string.Empty;
                mUserGroupRole.State = 0;

                int rolesId = 0;
                //查询医生表
                Owen.Model.Model_Doctor mDoctor = new BLL_Doctor().GetEntity(string.Format(" Mobile = '{0}' ", userName));
                //查询经销商表
                Owen.Model.Model_Distributor mDistributor = new BLL_Distributor().GetEntity(string.Format(" Mobile = '{0}'", userName));
                //查询经销商员工表
                Owen.Model.Model_Employees mEmployees = new BLL_Employees().GetEntity(string.Format(" Mobile = '{0}'", userName));



                if (mDoctor != null)
                    rolesId = (int)Owen.Common.RolesValue.Doctor; //医生
                else if (mDistributor != null)
                    rolesId = (int)Owen.Common.RolesValue.Distributor; //经销商
                else if (mDistributor != null)
                    rolesId = (int)Owen.Common.RolesValue.Employees; //经销商员工
                else
                    rolesId = (int)Owen.Common.RolesValue.Patient; //病人


                mUserGroupRole.RolesID = rolesId;
                new BLL_UserGroupRole().AddEntity(mUserGroupRole);

                tranScope.Complete();
                b = true;
            }

            return b;
        }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Owen.BLL.BLL_Doctor bllDoctor = new Owen.BLL.BLL_Doctor();

        Owen.Model.Model_Doctor entity = bllDoctor.GetEntity(doctorId);

        if (entity == null)
            entity = new Owen.Model.Model_Doctor();

        if (string.IsNullOrEmpty(ddlProvince.SelectedValue))
        {
            JSHelper.Alert(this, "请选择省(直辖市)!");
            return;
        }
        if (string.IsNullOrEmpty(ddlCity.SelectedValue))
        {
            JSHelper.Alert(this, "请选择城市!");
            return;
        }
        if (string.IsNullOrEmpty(ddlHospital.SelectedValue))
        {
            JSHelper.Alert(this, "请选择医院!");
            return;
        }

        entity.HospitalID = int.Parse(ddlHospital.SelectedValue);

        if (string.IsNullOrEmpty(ddlDepartment.SelectedValue))
        {
            JSHelper.Alert(this, "请选择科室!");
            return;
        }
        entity.DistributorID = distributorID;
        entity.EmployeesID = employessID;
        entity.DepartmentID = int.Parse(ddlDepartment.SelectedValue);
        entity.Name = txtName.Text.Trim();
        entity.Mobile = txtMobile.Text.Trim();
        entity.NativePlace = txtNativePlace.Text.Trim();
        entity.JobTitle = txtJobTitle.Text.Trim();
        entity.Sex = int.Parse(ddlSex.SelectedValue);
        entity.Status = int.Parse(ddlStatus.SelectedValue);

        switch (action)
        {
            case "add":
                new Owen.BLL.BLL_Doctor().AddEntity(entity);
                JSHelper.Alert(this, "保存成功!", "DoctorList.aspx");
                break;
            case "edit":
                entity.DoctorID = doctorId;
                new Owen.BLL.BLL_Doctor().UpdateEntity(entity);
                JSHelper.Alert(this, "保存成功!", "DoctorList.aspx");
                break;
        }

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Owen.BLL.BLL_Doctor bllDoctor = new Owen.BLL.BLL_Doctor();

        Owen.Model.Model_Medical entity = null;

        if (entity == null)
            entity = new Owen.Model.Model_Medical();

        if (string.IsNullOrEmpty(ddlHospital.SelectedValue))
        {
            JSHelper.Alert(this, "请选择医院!");
            return;
        }
        if (string.IsNullOrEmpty(ddlDoctor.SelectedValue))
        {
            JSHelper.Alert(this, "请选择主治医生!");
            return;
        }
        entity.HospitalID = int.Parse(ddlHospital.SelectedValue);
        entity.DoctorID = int.Parse(ddlDoctor.SelectedValue);

        if (string.IsNullOrEmpty(txtHospitalNumber.Text))
        {
            JSHelper.Alert(this, "请输入住院号!");
            return;
        }
        entity.HospitalNumber = txtHospitalNumber.Text.Trim();

        if (string.IsNullOrEmpty(txtSurgery.Text))
        {
            JSHelper.Alert(this, "请输入手术名称!");
            return;
        }
        entity.Surgery = txtSurgery.Text.Trim();

        if (string.IsNullOrEmpty(txtPatientName.Text))
        {
            JSHelper.Alert(this, "请输入患者姓名!");
            return;
        }
        entity.PatientName = txtPatientName.Text.Trim();

        if (string.IsNullOrEmpty(txtPatientBirth.Text))
        {
            JSHelper.Alert(this, "请输入患者出生日期!");
            return;
        }
        entity.PatientBirth = txtPatientBirth.Text.Trim();

        if (string.IsNullOrEmpty(txtPatientAge.Text))
        {
            JSHelper.Alert(this, "请输入患者年龄!");
            return;
        }
        else
        {
            int age = 0;
            if (!int.TryParse(txtPatientAge.Text, out age))
            {
                JSHelper.Alert(this, "请输入正确的患者年龄!");
                return;
            }
            entity.PatientAge = age;
        }

        if (string.IsNullOrEmpty(txtPatientMobile.Text))
        {
            JSHelper.Alert(this, "请输入患者手机号码!");
            return;
        }
        else
        {
            //用户名(手机号码)格式错误,请输入正确的手机号码
            if (!Owen.Common.Validator.IsValidPhone(txtPatientMobile.Text))
            {
                JSHelper.Alert(this, "请输入患者手机号码!");
                return;
            }
        }
        
        entity.PatientMobile = txtPatientMobile.Text.Trim();
        entity.PatientSex = int.Parse(ddlPatientSex.SelectedValue);
        
        //完成度
        entity.Finish = 0.1M;
        entity.DistributorID = distributorID;
        entity.EmployeesID = employessID;


        switch (action)
        {
            case "add":
                entity.CreateDt = DateTime.Now;
                new Owen.BLL.BLL_Medical().AddEntity(entity);
                JSHelper.Alert(this, "创建成功!", "MedicalList.aspx");
                break;
            case "edit":
                entity.MedicalID = medicalId;
                new Owen.BLL.BLL_Medical().UpdateEntity(entity);
                JSHelper.Alert(this, "修改成功!", "MedicalManager.aspx?action=edit&medicalId="+ medicalId +"");
                break;
        }

    }
 /// <summary>
 /// 绑定医生
 /// </summary>
 private void BindDoctor(int hosId)
 {
     IList<Owen.Model.Model_Doctor> list = new Owen.BLL.BLL_Doctor().GetEntities(string.Format(" HospitalID = {0} ", hosId));
     ddlDoctor.DataTextField = "Name";
     ddlDoctor.DataValueField = "DoctorID";
     ddlDoctor.DataSource = list;
     ddlDoctor.DataBind();
     ddlDoctor.Items.Insert(0, new ListItem("--请选择主治医生--", ""));
 }