Esempio n. 1
0
    private void BindOfficialPopulation()
    {
        if ((int)ViewState["ID"] > 0)
        {
            Addr_OfficialCityPopulationBLL populationBindBll = new Addr_OfficialCityPopulationBLL((int)ViewState["ID"]);
            Addr_OfficialCityBLL           bll = new Addr_OfficialCityBLL((int)ViewState["ID"]);
            DataTable officialDatatable        = bll.GetAllChildNode();
            if (officialDatatable.Rows.Count <= 0)
            {
                pl_Details.Visible         = true;
                btn_SavePopulation.Visible = true;
                if (populationBindBll.Model == null)
                {
                    populationBindBll          = new Addr_OfficialCityPopulationBLL();
                    populationBindBll.Model.ID = bll.Model.ID;
                }

                pl_Details.BindData(populationBindBll.Model);
            }

            else
            {
                pl_Details.Visible         = false;
                btn_SavePopulation.Visible = false;
            }
        }
        else
        {
            pl_Details.Visible         = false;
            btn_SavePopulation.Visible = false;
        }
    }
Esempio n. 2
0
        /// <summary>
        /// 查询指定范围内的城市列表
        /// </summary>
        /// <param name="latitude1"></param>
        /// <param name="longitude1"></param>
        /// <param name="latitude2"></param>
        /// <param name="longitude2"></param>
        /// <param name="Level"></param>
        /// <returns></returns>
        public static IList <Addr_OfficialCity> GetOfficialCityByLatiLongitudeScope(double latitude1, double longitude1, double latitude2, double longitude2, int Level)
        {
            double latitude = 0;

            if (latitude1 > latitude2)
            {
                latitude  = latitude1;
                latitude1 = latitude2;
                latitude2 = latitude;
            }

            double longitude = 0;

            if (longitude1 > longitude2)
            {
                longitude  = longitude1;
                longitude1 = longitude2;
                longitude2 = longitude;
            }

            return(Addr_OfficialCityBLL.GetModelList("[Level]=" + Level.ToString() +
                                                     " AND ID IN (SELECT OfficialCity FROM MCS_GIS.dbo.GIS_OfficialCityGeo WHERE Latitude BETWEEN " +
                                                     latitude1.ToString() + " AND " + latitude2.ToString() + " AND Longitude BETWEEN " +
                                                     longitude1.ToString() + " AND " + longitude2.ToString() + ")"));
        }
Esempio n. 3
0
    protected void tr_OfficialCity_Selected(object sender, MCSControls.MCSWebControls.SelectedEventArgs e)
    {
        cbl_OfficialList.Items.Clear();
        DataTable dt = TreeTableBLL.GetAllChildByNodes("MCS_SYS.dbo.Addr_OfficialCity", "ID", "SuperID", tr_OfficialCity.SelectValue);

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            Addr_OfficialCityBLL city = new Addr_OfficialCityBLL((int)dt.Rows[i]["ID"]);
            if (city.Model.Level == 3)
            {
                string   fullname = TreeTableBLL.GetFullPathName("MCS_SYS.dbo.Addr_OfficialCity", city.Model.ID);
                ListItem item     = new ListItem(fullname, city.Model.ID.ToString());

                IList <Addr_OfficialCityInOrganizeCity> organizecitys = Addr_OfficialCityInOrganizeCityBLL.GetModelList("OfficialCity=" + city.Model.ID.ToString());
                if (organizecitys.Count > 0)
                {
                    Addr_OrganizeCity organizecity = new Addr_OrganizeCityBLL(organizecitys[0].OrganizeCity).Model;
                    if (organizecity != null)
                    {
                        item.Text += "; 已归属于片区:【" + organizecity.Name + "】";
                    }
                    item.Enabled = false;
                }

                cbl_OfficialList.Items.Add(item);
            }
        }
    }
Esempio n. 4
0
        public OfficialCity(int CityID)
        {
            Addr_OfficialCity c = new Addr_OfficialCityBLL(CityID).Model;

            if (c != null)
            {
                FillMode(c);
            }
        }
        /// <summary>
        /// 根据当前经纬度获取所在的城市信息
        /// </summary>
        /// <param name="AuthKey">授权码</param>
        /// <param name="Latitude">纬度</param>
        /// <param name="Longitude">经度</param>
        /// <returns></returns>
        public static OfficialCity GetCurrentOfficialCityByGPS(UserInfo User, float Latitude, float Longitude)
        {
            LogWriter.WriteLog("MemberService.GetCurrentOfficialCityByGPS:UserName="******",Latitude=" + Latitude.ToString() + ",Longitude=" + Longitude.ToString());
            if (User == null)
            {
                return(null);
            }
            try
            {
                double mgLat, mgLon;
                //转火星坐标
                WGSToGCJAPI.Transform((double)Latitude, (double)Longitude, out mgLat, out mgLon);

                Addr_OfficialCity city = null;

                ///默认根据Google地图API获取所在地
                string Provname, CityName, AreaName, FullAddress;
                int    ret = GoogleMapAPI.latLngToChineseDistrict((float)mgLat, (float)mgLon, out Provname, out CityName, out AreaName, out FullAddress);
                if (ret == 0)
                {
                    //省
                    IList <Addr_OfficialCity> _lists = Addr_OfficialCityBLL.GetModelList("Name LIKE '" + Provname + "%' AND [LEVEL]=1");
                    if (_lists.Count > 0)
                    {
                        city = _lists[0];

                        //市
                        _lists = Addr_OfficialCityBLL.GetModelList("Name LIKE '" + CityName + "%' AND SuperID=" + city.ID.ToString() + " AND [LEVEL]=2");
                        if (_lists.Count > 0)
                        {
                            city = _lists[0];

                            //区、县
                            _lists = Addr_OfficialCityBLL.GetModelList("Name LIKE '" + AreaName + "%' AND SuperID=" + city.ID.ToString() + " AND [LEVEL]=3");
                            if (_lists.Count > 0)
                            {
                                city = _lists[0];
                            }
                        }
                    }
                }
                else
                {
                    int cityid = GIS_OfficialCityGeoBLL.GetNearOfficialCityByLatLong(Latitude, Longitude);
                    city = new Addr_OfficialCityBLL(cityid).Model;
                }

                return(new OfficialCity(city));
            }
            catch (System.Exception err)
            {
                LogWriter.WriteLog("MemberService.GetCurrentOfficialCityByGPS Exception!UserName=" + User.UserName, err);
                return(null);
            }
        }
    protected void bt_AddSub_Click(object sender, EventArgs e)
    {
        tbx_Code.Text            = "";
        tbx_Name.Text            = "";
        tree_SuperID.SelectValue = ViewState["ID"].ToString();
        Addr_OfficialCityBLL officialCityBLL = new Addr_OfficialCityBLL((int)ViewState["ID"]);

        ViewState["ID"]    = 0;
        btn_Delete.Visible = false;
        bt_AddSub.Visible  = false;
        btn_Save.Text      = "保存";
    }
        /// <summary>
        /// 获取行政城市对应的省市县ID
        /// </summary>
        /// <param name="AuthKey">匿名用户登录后的认证码</param>
        /// <param name="OfficialCity">行政城市ID</param>
        /// <param name="ProvID">省</param>
        /// <param name="CityID">市</param>
        /// <param name="AreaID">县</param>
        /// <returns>当前城市的级别,1:省 2:市 3:县 4:镇,-1:城市ID不存在,-2:获取城市信息出错</returns>
        public static int GetSuperOfficialCity(UserInfo User, int OfficialCity, out int ProvID, out int CityID, out int AreaID)
        {
            ProvID = 0; CityID = 0; AreaID = 0;
            LogWriter.WriteLog("OfficialCityService.GetSuperCityID:UserName="******",OfficialCity=" + OfficialCity.ToString());

            Addr_OfficialCityBLL city = new Addr_OfficialCityBLL(OfficialCity);

            if (city.Model == null)
            {
                return(-1);
            }

            try
            {
                if (city.Model.Level == 4)
                {
                    //当前城市为乡镇
                    AreaID = city.Model.SuperID;
                    CityID = new Addr_OfficialCityBLL(AreaID).Model.SuperID;
                    ProvID = new Addr_OfficialCityBLL(CityID).Model.SuperID;
                }
                else if (city.Model.Level == 3)
                {
                    //当前城市为区/县
                    AreaID = city.Model.ID;
                    CityID = city.Model.SuperID;
                    ProvID = new Addr_OfficialCityBLL(CityID).Model.SuperID;
                }
                else if (city.Model.Level == 2)
                {
                    //当前城市为地级市
                    CityID = city.Model.ID;
                    ProvID = city.Model.SuperID;
                }
                else if (city.Model.Level == 1)
                {
                    //当前城市为省
                    ProvID = city.Model.ID;
                }
                else
                {
                    return(-2);
                }
            }
            catch (System.Exception err)
            {
                LogWriter.WriteLog("OfficialCityService.GetSuperCityID,Exception!", err);
                return(-2);
            }

            return(city.Model.Level);
        }
Esempio n. 8
0
    private void BindTree(TreeNodeCollection TNC, int SuperID)
    {
        Addr_OfficialCityBLL      _bll       = new Addr_OfficialCityBLL();
        IList <Addr_OfficialCity> _modellist = _bll._GetModelList("SuperID=" + SuperID.ToString());

        foreach (Addr_OfficialCity _model in _modellist)
        {
            TreeNode tn = new TreeNode();
            tn.Text  = _model.Name;
            tn.Value = _model.ID.ToString();
            TNC.Add(tn);
            if (_model.ID == 1)
            {
                BindTree(tn.ChildNodes, _model.ID);
            }
        }
    }
        /// <summary>
        /// 获取指定城市的下级城市,CityID=1时获取全国省份
        /// </summary>
        /// <param name="AuthKey">匿名用户登录后的认证码</param>
        /// <param name="CityID">上级城市ID</param>
        /// <returns></returns>
        public static List <OfficialCity> GetSubCitysBySuper(UserInfo User, int CityID)
        {
            LogWriter.WriteLog("OfficialCityService.GetSubCitysBySuper:UserName="******",CityID=" + CityID.ToString());

            if (User == null)
            {
                return(null);
            }

            IList <Addr_OfficialCity> citys = Addr_OfficialCityBLL.GetModelList("SuperID=" + CityID.ToString());

            List <OfficialCity> lists = new List <OfficialCity>(citys.Count);

            foreach (Addr_OfficialCity item in citys)
            {
                lists.Add(new OfficialCity(item));
            }
            return(lists);
        }
Esempio n. 10
0
    private void BindData(int ID)
    {
        ViewState["ID"] = ID;

        Addr_OfficialCityBLL _bll = new Addr_OfficialCityBLL(ID);

        lbl_ID.Text                         = _bll.Model.ID.ToString();
        tbx_Name.Text                       = _bll.Model.Name;
        tree_SuperID.SelectValue            = _bll.Model.SuperID.ToString();
        tbx_Code.Text                       = _bll.Model.Code;
        tbx_CallAreaCode.Text               = _bll.Model.CallAreaCode;
        tbx_PostCode.Text                   = _bll.Model.PostCode;
        tbx_Births.Text                     = _bll.Model.Births.ToString();
        ddl_CityAttributeFlag.SelectedValue = _bll.Model.Attribute.ToString();
        if (_bll.Model.Level != 0)
        {
            lbl_LevelName.Text = DictionaryBLL.GetDicCollections("Addr_OfficialCityLevel")[_bll.Model.Level.ToString()].Name;
        }

        btn_Save.Text      = "修改";
        btn_Save.ForeColor = System.Drawing.Color.Red;
        btn_Delete.Visible = true;
        MessageBox.ShowConfirm(btn_Delete, "数据删除将不可恢复,确定删除么?");
        btn_Cancel.Visible = true;
        bt_AddSub.Visible  = true;

        lbl_AlertInfo.Text = "";

        if ((int)ViewState["ID"] == 1)
        {
            btn_Save.Enabled = false;
        }
        else
        {
            btn_Save.Enabled = true;
        }

        btn_Delete.Visible = Addr_OfficialCityBLL.GetModelList("SuperID=" + ViewState["ID"].ToString()).Count == 0;

        BindOfficialPopulation();
    }
Esempio n. 11
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDropDown();

            if (Request.QueryString["OrganizeCity"] == null)
            {
                MessageBox.ShowAndClose(this, "参数错误!");
                return;
            }
            else
            {
                ViewState["OrganizeCity"] = int.Parse(Request.QueryString["OrganizeCity"]);

                Addr_OrganizeCityBLL organizecity = new Addr_OrganizeCityBLL((int)ViewState["OrganizeCity"]);
                if (organizecity.Model == null)
                {
                    MessageBox.ShowAndClose(this, "参数错误!");
                    return;
                }
                else if (organizecity.GetAllChildNode().Rows.Count != 0)
                {
                    MessageBox.ShowAndClose(this, "要加入的管理片区必须是最低一层的架构单元!");
                    return;
                }
                else
                {
                    lb_OrganizeCityName.Text = organizecity.Model.Name;

                    IList <Addr_OfficialCity> lists = Addr_OfficialCityBLL.GetModelList("Name like '%" + organizecity.Model.Name + "%'");
                    if (lists.Count > 0)
                    {
                        tr_OfficialCity.SelectValue = lists[0].ID.ToString();
                        tr_OfficialCity_Selected(null, null);
                    }
                }
            }
        }
    }
    protected void btn_SavePopulation_Click(object sender, EventArgs e)
    {
        Addr_OfficialCityPopulationBLL _populationBll = null;
        Addr_OfficialCityBLL _bll;
        int result = 0;
        if ((int)ViewState["ID"] > 0)
        {
            _bll = new Addr_OfficialCityBLL((int)ViewState["ID"]);

            DataTable officialPopulation = _bll.GetAllChildNode();
            if (officialPopulation.Rows.Count <= 0)
            {
                _populationBll = new Addr_OfficialCityPopulationBLL((int)ViewState["ID"]);
                if (_populationBll.Model == null)
                {
                    _populationBll = new Addr_OfficialCityPopulationBLL();
                    pl_Details.GetData(_populationBll.Model);
                    _populationBll.Model.ID = (int)ViewState["ID"];
                    result = _populationBll.Add();
                    if (result < 0)
                    {
                        lbl_AlertInfo.Text = "人口信息添加失败";
                    }

                }
                else
                {
                    pl_Details.GetData(_populationBll.Model);
                    result = _populationBll.Update();

                    if (result < 0)
                    {
                        lbl_AlertInfo.Text = "人口信息修改失败";
                    }

                }

            }
        }
    }
Esempio n. 13
0
    protected void btn_SavePopulation_Click(object sender, EventArgs e)
    {
        Addr_OfficialCityPopulationBLL _populationBll = null;
        Addr_OfficialCityBLL           _bll;
        int result = 0;

        if ((int)ViewState["ID"] > 0)
        {
            _bll = new Addr_OfficialCityBLL((int)ViewState["ID"]);

            DataTable officialPopulation = _bll.GetAllChildNode();
            if (officialPopulation.Rows.Count <= 0)
            {
                _populationBll = new Addr_OfficialCityPopulationBLL((int)ViewState["ID"]);
                if (_populationBll.Model == null)
                {
                    _populationBll = new Addr_OfficialCityPopulationBLL();
                    pl_Details.GetData(_populationBll.Model);
                    _populationBll.Model.ID = (int)ViewState["ID"];
                    result = _populationBll.Add();
                    if (result < 0)
                    {
                        lbl_AlertInfo.Text = "人口信息添加失败";
                    }
                }
                else
                {
                    pl_Details.GetData(_populationBll.Model);
                    result = _populationBll.Update();

                    if (result < 0)
                    {
                        lbl_AlertInfo.Text = "人口信息修改失败";
                    }
                }
            }
        }
    }
Esempio n. 14
0
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        Addr_OfficialCityBLL _bll = new Addr_OfficialCityBLL(int.Parse(lbl_ID.Text));

        if (_bll.Delete() < 0)
        {
            lbl_AlertInfo.Text = "该城市包含下级城市,请勿删除";
            return;
        }
        Addr_OfficialCityPopulationBLL populationbll = new Addr_OfficialCityPopulationBLL(_bll.Model.ID);

        if (populationbll != null)
        {
            if (populationbll.Delete() < 0)
            {
                lbl_AlertInfo.Text = "删除该区域人口统计信息时出错!";
                return;
            }
        }

        lbl_AlertInfo.Text = "";
        Response.Redirect("OfficialCityManage.aspx?SuperID=" + _bll.Model.SuperID.ToString());
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        Addr_OfficialCityBLL _bll = new Addr_OfficialCityBLL(int.Parse(lbl_ID.Text));

        if (_bll.Delete() < 0)
        {
            lbl_AlertInfo.Text = "该城市包含下级城市,请勿删除";
            return;
        }
        Addr_OfficialCityPopulationBLL populationbll = new Addr_OfficialCityPopulationBLL(_bll.Model.ID);

        if (populationbll != null)
        {
            if (populationbll.Delete() < 0)
            {
                lbl_AlertInfo.Text = "删除该区域人口统计信息时出错!";
                return;
            }
        }

        lbl_AlertInfo.Text = "";
        Response.Redirect("OfficialCityManage.aspx?SuperID=" + _bll.Model.SuperID.ToString());
    }
        /// <summary>
        /// 获取所有行政城市
        /// </summary>
        /// <param name="AuthKey"></param>
        /// <returns></returns>
        public static List <OfficialCity> GetAllOfficialCitys(UserInfo User)
        {
            LogWriter.WriteLog("OfficialCitySerice.GetAllOfficialCitys:UserName="******"MCS_SYS.dbo.Addr_OfficialCity", c.OfficialCity, 1);
                    if (prov > 0)
                    {
                        citys = Addr_OfficialCityBLL.GetModelList("Level<=3 AND Level1_SuperID=" + prov.ToString());
                    }
                }
            }

            if (citys == null)
            {
                citys = Addr_OfficialCityBLL.GetModelList("Level<=3");
            }

            List <OfficialCity> lists = new List <OfficialCity>(citys.Count);

            foreach (Addr_OfficialCity item in citys)
            {
                lists.Add(new OfficialCity(item));
            }
            return(lists);
        }
Esempio n. 17
0
 public OfficialCity(int CityID)
 {
     Addr_OfficialCity c = new Addr_OfficialCityBLL(CityID).Model;
     if (c != null) FillMode(c);
 }
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] == 1) return;

        Addr_OfficialCityBLL _bll;

        if ((int)ViewState["ID"] == 0)
        {
            _bll = new Addr_OfficialCityBLL();

        }
        else
        {
            _bll = new Addr_OfficialCityBLL((int)ViewState["ID"]);

        }

        _bll.Model.Name = tbx_Name.Text;
        _bll.Model.SuperID = int.Parse(tree_SuperID.SelectValue);
        _bll.Model.Code = tbx_Code.Text;
        _bll.Model.CallAreaCode = tbx_CallAreaCode.Text;
        _bll.Model.PostCode = tbx_PostCode.Text;
        _bll.Model.Level = new Addr_OfficialCityBLL(_bll.Model.SuperID).Model.Level + 1;
        _bll.Model.Births = int.Parse(tbx_Births.Text.Trim() == "" ? "0" : tbx_Births.Text.Trim());
        _bll.Model.Attribute = int.Parse(ddl_CityAttributeFlag.SelectedValue);
        if (DictionaryBLL.GetDicCollections("Addr_OfficialCityLevel")[_bll.Model.Level.ToString()] == null)
        {
            lbl_AlertInfo.Text = "添加城市失败,等级超出范围";
            return;
        }

        if ((int)ViewState["ID"] == 0)
        {
            int resultAdd = _bll.Add();
            if (resultAdd < 0)
            {
                lbl_AlertInfo.Text = "添加城市失败,城市名称已存在";
                return;
            }

        }
        else
        {
            int ret = _bll.Update();

            switch (ret)
            {
                case -1:
                    lbl_AlertInfo.Text = "更新城市失败,城市名称已存在";
                    return;
                case -2:
                    lbl_AlertInfo.Text = "更新城市失败,不能将当前城市设置为上级城市";
                    return;
                case -3:
                    lbl_AlertInfo.Text = "更新城市失败,不能将当前城市的子城市设置为上级城市";
                    return;
            }

        }

        Response.Redirect("OfficialCityManage.aspx?SuperID=" + _bll.Model.SuperID.ToString());
    }
    protected void bt_AddDetail_Click(object sender, EventArgs e)
    {
        SaveDataTable();

        if (ddl_WorkingClassify.SelectedValue == "0")
        {
            MessageBox.Show(this, "请先选择要增加的工作类型!");
            return;
        }
        else if (ddl_WorkingClassify.SelectedValue == "1" && string.IsNullOrEmpty(select_RelateClient.SelectValue))
        {
            MessageBox.Show(this, "请先选择你要拜访的客户!");
            return;
        }
        else if (ddl_WorkingClassify.SelectedValue == "2" && string.IsNullOrEmpty(select_RelateStaff.SelectValue))
        {
            MessageBox.Show(this, "请先选择你要协同拜访的员工!");
            return;
        }

        DateTime begindate = DateTime.Parse(tbx_Begin.Text);
        DateTime enddate   = DateTime.Parse(tbx_End.Text);

        if (begindate < (DateTime)ViewState["BeginDate"])
        {
            MessageBox.Show(this, "本工作项的开始日期不能小于整个计划开始日期!");
            return;
        }
        if (enddate > (DateTime)ViewState["EndDate"])
        {
            MessageBox.Show(this, "本工作项的截止日期不能大于整个计划截止日期!");
            return;
        }
        if (ViewState["WorkingPlanData"] != null)
        {
            DataTable dt = (DataTable)ViewState["WorkingPlanData"];

            DataRow dr = dt.NewRow();
            dr["WorkingClassify"]     = int.Parse(ddl_WorkingClassify.SelectedValue);
            dr["WorkingClassifyName"] = ddl_WorkingClassify.SelectedItem.Text;

            switch (ddl_WorkingClassify.SelectedValue)
            {
            case "1":
                #region 增加客户拜访计划
            {
                if (select_RelateClient.SelectValue == "" || select_RelateClient.SelectValue == "0")
                {
                    MessageBox.Show(this, "请选择要拜访的客户!");
                    return;
                }
                if (dt.Select("WorkingClassify=1 AND RelateClient=" + select_RelateClient.SelectValue).Length > 0)
                {
                    MessageBox.Show(this, "对不起,列表中已有相同的行了,不能重复添加!");
                    return;
                }

                dr["RelateClient"]     = int.Parse(select_RelateClient.SelectValue);
                dr["RelateClientName"] = select_RelateClient.SelectText;
                dr["RelateStaff"]      = 0;
            }
                #endregion
                break;

            case "2":
                #region 循环增加协同拜访员工计划
            {
                int staffid = 0;
                if (!int.TryParse(select_RelateStaff.SelectValue, out staffid))
                {
                    return;
                }
                if (staffid == int.Parse(select_PlanStaff.SelectValue))
                {
                    return;
                }
                Org_Staff staff = new Org_StaffBLL(staffid).Model;
                if (staff == null)
                {
                    return;
                }

                if (dt.Select("WorkingClassify=2 AND RelateStaff=" + staffid.ToString()).Length > 0)
                {
                    MessageBox.Show(this, "对不起,列表中已有相同的行了,不能重复添加!");
                    return;
                }
                ;


                dr["RelateStaff"]     = staffid;
                dr["RelateStaffName"] = staff.RealName;
                dr["RelateClient"]    = 0;

                if (staff.OfficialCity > 1)
                {
                    dr["OfficialCity"]     = staff.OfficialCity;
                    dr["OfficialCityName"] = TreeTableBLL.GetFullPathName("MCS_SYS.dbo.Addr_OfficialCity", staff.OfficialCity).Replace("->", " ");;
                }
                dt.Rows.Add(dr);
            }
                #endregion
                break;

            default:
                #region 增加其他工作计划
            {
                if (dt.Select("WorkingClassify=" + ddl_WorkingClassify.SelectedValue +
                              " AND Description='" + tbx_Description.Text +
                              "' AND OfficialCity=" + tr_OfficailCity.SelectValue).Length > 0)
                {
                    MessageBox.Show(this, "对不起,列表中已有相同的行了,不能重复添加!");
                    return;
                }

                dr["RelateStaff"]  = 0;
                dr["RelateClient"] = 0;
                dr["Description"]  = tbx_Description.Text;
            }
                #endregion
                break;
            }

            if (!string.IsNullOrEmpty(tr_OfficailCity.SelectValue) && tr_OfficailCity.SelectValue != "0")
            {
                dr["OfficialCity"]     = int.Parse(tr_OfficailCity.SelectValue);
                dr["OfficialCityName"] = new Addr_OfficialCityBLL(int.Parse(tr_OfficailCity.SelectValue)).Model.Name;
            }
            if (tbx_Cost1.Text != "")
            {
                dr["Cost1"] = decimal.Parse(tbx_Cost1.Text);
            }
            else
            {
                dr["Cost1"] = 0;
            }

            if (tbx_Cost2.Text != "")
            {
                dr["Cost2"] = decimal.Parse(tbx_Cost2.Text);
            }
            else
            {
                dr["Cost2"] = 0;
            }

            DateTime day = begindate;
            while (day <= enddate)
            {
                dr["P" + day.ToString("MMdd")] = true;
                day = day.AddDays(1);
            }

            dt.Rows.Add(dr);
            #region 清空已录入的工作计划数据,以便下次再录
            select_RelateStaff.SelectValue  = "";
            select_RelateStaff.SelectText   = "";
            select_RelateClient.SelectValue = "";
            select_RelateClient.SelectText  = "";
            if (ViewState["StaffOfficialCity"] != null)
            {
                tr_OfficailCity.SelectValue = ViewState["StaffOfficialCity"].ToString();
            }
            #endregion

            cb_DisplayCheckedOnly.Checked = false;
            BindGrid();
        }
    }
    private void BindTree(TreeNodeCollection TNC, int SuperID)
    {
        Addr_OfficialCityBLL _bll = new Addr_OfficialCityBLL();
        IList<Addr_OfficialCity> _modellist = _bll._GetModelList("SuperID=" + SuperID.ToString());

        foreach (Addr_OfficialCity _model in _modellist)
        {
            TreeNode tn = new TreeNode();
            tn.Text = _model.Name;
            tn.Value = _model.ID.ToString();
            TNC.Add(tn);
            if (_model.ID == 1)
                BindTree(tn.ChildNodes, _model.ID);
        }
    }
    protected void bt_OK_Click(object sender, EventArgs e)
    {
        Org_StaffBLL _staffbll = null;
        if ((int)ViewState["ID"] == 0)
        {
            _staffbll = new Org_StaffBLL();
        }
        else
        {
            _staffbll = new Org_StaffBLL((int)ViewState["ID"]);
        }

        int oldPosition = _staffbll.Model.Position;
        int oldOrganizeCity = _staffbll.Model.OrganizeCity;

        panel1.GetData(_staffbll.Model);

        if ((int)ViewState["ID"] != 0 && (oldPosition != _staffbll.Model.Position||oldOrganizeCity!=_staffbll.Model.OrganizeCity)&&
            EWF_Task_JobDecisionBLL.GetModelList("DecisionResult=1 AND RecipientStaff=" + ViewState["ID"].ToString()).Count > 0)
        {
             MessageBox.Show(this, "对不起,该人员还有未审批流程不能调整【职务】或【管理片区】信息!");
             return;
        }
        Addr_OfficialCityBLL citybll = new Addr_OfficialCityBLL(_staffbll.Model.OfficialCity);
        if (citybll != null && citybll.Model.Level < 2)
        {
            MessageBox.Show(this, "驻点所在城市必须选到市级!");
            return;
        }

        Org_Staff _staffM = new Org_StaffBLL((int)Session["UserID"]).Model;
        if (_staffM.Position == _staffbll.Model.Position && new Org_PositionBLL(_staffM.Position).Model.IsHeadOffice != "Y")
        {
            MessageBox.Show(this, "对不起,您没有权限新增职位与您相同的员工");
            return;
        }

        if (_staffbll.Model["OperateProperty"]=="0")
        {
            MessageBox.Show(this, "归属办事处类型必填!");
            return;
        }

        if ((int)ViewState["ID"] == 0)
        {
            #region 根据身份证号判断是否重复
            if (_staffbll.Model["IDCode"] != string.Empty &&
                Org_StaffBLL.GetStaffList("MCS_SYS.dbo.UF_Spilt(Org_Staff.ExtPropertys,'|',1)='" + _staffbll.Model["IDCode"] + "' AND Dimission=1").Count > 0)
            {
                MessageBox.Show(this, "对不起,该身份证号的员工已在系统中入职,请核实后再新增员工!");
                return;
            }
            #endregion

            if (Org_StaffNumberLimitBLL.CheckAllowAdd(_staffbll.Model.OrganizeCity, _staffbll.Model.Position) <= 0)
            {
                MessageBox.Show(this, "对不起当前城市该职位员工人数满额,要想继续新增请与人事经理联系");
                return;
            }
            _staffbll.Model.InsertStaff = (int)Session["UserID"];
            _staffbll.Model.InsertTime = DateTime.Now;
            _staffbll.Model.ApproveFlag = 1;            //未审批
            _staffbll.Model.Dimission = 1;              //在职
            ViewState["ID"] = _staffbll.Add();
        }
        else
        {
            if (!Org_StaffNumberLimitBLL.IsSameLimit(oldOrganizeCity, _staffbll.Model.OrganizeCity, oldPosition, _staffbll.Model.Position) &&
                Org_StaffNumberLimitBLL.CheckAllowAdd(_staffbll.Model.OrganizeCity, _staffbll.Model.Position) <= 0)
            {
                MessageBox.Show(this, "对不起当前城市该职位员工人数满额,要想继续新增请与人事经理联系");
                return;
            }
            _staffbll.Model.UpdateStaff = (int)Session["UserID"];
            _staffbll.Update();
        }
        MessageBox.ShowAndRedirect(this, "保存成功", "StaffDetail.aspx?ID=" + ViewState["ID"].ToString());
    }
    private void BindData(int ID)
    {
        ViewState["ID"] = ID;

        Addr_OrganizeCityBLL _bll = new Addr_OrganizeCityBLL(ID);

        lbl_ID.Text   = _bll.Model.ID.ToString();
        tbx_Name.Text = _bll.Model.Name;
        if (_bll.Model.SuperID != 0)
        {
            tree_SuperID.SelectValue = _bll.Model.SuperID.ToString();
        }
        tbx_Code.Text = _bll.Model.Code;

        if (_bll.Model.Manager != 0)
        {
            select_Manager.SelectValue = _bll.Model.Manager.ToString();
            select_Manager.SelectText  = new Org_StaffBLL(_bll.Model.Manager).Model.RealName;
        }
        else
        {
            select_Manager.SelectValue = "";
            select_Manager.SelectText  = "";
        }

        if (_bll.Model.Level != 0)
        {
            lbl_LevelName.Text = DictionaryBLL.GetDicCollections("Addr_OrganizeCityLevel")[_bll.Model.Level.ToString()].Name;
        }

        tbx_ManageRegion.Text = _bll.Model["ManageRegion"];

        if (ID == 1)
        {
            btn_Save.Visible   = false;
            btn_Delete.Visible = false;
        }
        else
        {
            btn_Save.Visible   = true;
            btn_Delete.Visible = true;
        }
        bt_AddSub.Visible = true;
        MessageBox.ShowConfirm(btn_Delete, "数据删除将不可恢复,确定删除么?");

        btn_Delete.Visible = Addr_OrganizeCityBLL.GetModelList("SuperID=" + ViewState["ID"].ToString()).Count == 0;
        lbl_AlertInfo.Text = "";


        #region 绑定已关联的行政区县列表
        if (_bll.Model.Level.ToString() == ConfigHelper.GetConfigString("OrganizeCity-CityLevel"))
        {
            tb_OfficialCityInOrganizeCity.Visible = true;
            cb_CheckAll.Checked = false;
            cbl_OfficialList.Items.Clear();
            IList <Addr_OfficialCityInOrganizeCity> lists = Addr_OfficialCityInOrganizeCityBLL.GetModelList("OrganizeCity = " + ID.ToString());
            foreach (Addr_OfficialCityInOrganizeCity e in lists)
            {
                Addr_OfficialCityBLL city = new Addr_OfficialCityBLL(e.OfficialCity);
                string   fullname         = TreeTableBLL.GetFullPathName("MCS_SYS.dbo.Addr_OfficialCity", city.Model.ID);
                ListItem item             = new ListItem(fullname, e.ID.ToString());

                cbl_OfficialList.Items.Add(item);
            }
            bt_AddOfficialCity.OnClientClick = "PopAddOfficialCity(" + ID.ToString() + ")";
        }
        else
        {
            tb_OfficialCityInOrganizeCity.Visible = false;
        }
        #endregion
    }
 protected void bt_AddSub_Click(object sender, EventArgs e)
 {
     tbx_Code.Text = "";
     tbx_Name.Text = "";
     tree_SuperID.SelectValue = ViewState["ID"].ToString();
     Addr_OfficialCityBLL officialCityBLL = new Addr_OfficialCityBLL((int)ViewState["ID"]);
     ViewState["ID"] = 0;
     btn_Delete.Visible = false;
     bt_AddSub.Visible = false;
     btn_Save.Text = "保存";
     pl_Details.Visible = false;
     btn_SavePopulation.Visible = false;
 }
        /// <summary>
        /// 根据当前经纬度获取所在的城市信息
        /// </summary>
        /// <param name="AuthKey">授权码</param>
        /// <param name="Latitude">纬度</param>
        /// <param name="Longitude">经度</param>
        /// <returns></returns>
        public static OfficialCity GetCurrentOfficialCityByGPS(UserInfo User, float Latitude, float Longitude)
        {
            LogWriter.WriteLog("MemberService.GetCurrentOfficialCityByGPS:UserName="******",Latitude=" + Latitude.ToString() + ",Longitude=" + Longitude.ToString());
            if (User == null) return null;
            try
            {
                double mgLat, mgLon;
                //转火星坐标
                WGSToGCJAPI.Transform((double)Latitude, (double)Longitude, out mgLat, out mgLon);

                Addr_OfficialCity city = null;

                ///默认根据Google地图API获取所在地
                string Provname, CityName, AreaName, FullAddress;
                int ret = GoogleMapAPI.latLngToChineseDistrict((float)mgLat, (float)mgLon, out Provname, out  CityName, out  AreaName, out FullAddress);
                if (ret == 0)
                {
                    //省
                    IList<Addr_OfficialCity> _lists = Addr_OfficialCityBLL.GetModelList("Name LIKE '" + Provname + "%' AND [LEVEL]=1");
                    if (_lists.Count > 0)
                    {
                        city = _lists[0];

                        //市
                        _lists = Addr_OfficialCityBLL.GetModelList("Name LIKE '" + CityName + "%' AND SuperID=" + city.ID.ToString() + " AND [LEVEL]=2");
                        if (_lists.Count > 0)
                        {
                            city = _lists[0];

                            //区、县
                            _lists = Addr_OfficialCityBLL.GetModelList("Name LIKE '" + AreaName + "%' AND SuperID=" + city.ID.ToString() + " AND [LEVEL]=3");
                            if (_lists.Count > 0) city = _lists[0];
                        }
                    }

                }
                else
                {
                    int cityid = GIS_OfficialCityGeoBLL.GetNearOfficialCityByLatLong(Latitude, Longitude);
                    city = new Addr_OfficialCityBLL(cityid).Model;
                }

                return new OfficialCity(city);
            }
            catch (System.Exception err)
            {
                LogWriter.WriteLog("MemberService.GetCurrentOfficialCityByGPS Exception!UserName=" + User.UserName, err);
                return null;
            }
        }
        /// <summary>
        /// 获取行政城市对应的省市县ID
        /// </summary>
        /// <param name="AuthKey">匿名用户登录后的认证码</param>
        /// <param name="OfficialCity">行政城市ID</param>
        /// <param name="ProvID">省</param>
        /// <param name="CityID">市</param>
        /// <param name="AreaID">县</param>
        /// <returns>当前城市的级别,1:省 2:市 3:县 4:镇,-1:城市ID不存在,-2:获取城市信息出错</returns>
        public static int GetSuperOfficialCity(UserInfo User, int OfficialCity, out int ProvID, out int CityID, out int AreaID)
        {
            ProvID = 0; CityID = 0; AreaID = 0;
            LogWriter.WriteLog("OfficialCityService.GetSuperCityID:UserName="******",OfficialCity=" + OfficialCity.ToString());

            Addr_OfficialCityBLL city = new Addr_OfficialCityBLL(OfficialCity);
            if (city.Model == null) return -1;

            try
            {
                if (city.Model.Level == 4)
                {
                    //当前城市为乡镇
                    AreaID = city.Model.SuperID;
                    CityID = new Addr_OfficialCityBLL(AreaID).Model.SuperID;
                    ProvID = new Addr_OfficialCityBLL(CityID).Model.SuperID;

                }
                else if (city.Model.Level == 3)
                {
                    //当前城市为区/县
                    AreaID = city.Model.ID;
                    CityID = city.Model.SuperID;
                    ProvID = new Addr_OfficialCityBLL(CityID).Model.SuperID;

                }
                else if (city.Model.Level == 2)
                {
                    //当前城市为地级市
                    CityID = city.Model.ID;
                    ProvID = city.Model.SuperID;
                }
                else if (city.Model.Level == 1)
                {
                    //当前城市为省
                    ProvID = city.Model.ID;
                }
                else
                {
                    return -2;
                }
            }
            catch (System.Exception err)
            {
                LogWriter.WriteLog("OfficialCityService.GetSuperCityID,Exception!", err);
                return -2;
            }

            return city.Model.Level;
        }
    protected void bt_OK_Click(object sender, EventArgs e)
    {
        CM_ClientBLL _bll = null;

        if (ViewState["ClientID"] == null)
        {
            _bll = new CM_ClientBLL();
        }
        else
        {
            _bll = new CM_ClientBLL((int)ViewState["ClientID"]);
            if (CM_LinkManBLL.GetModelList("ClientID=" + ViewState["ClientID"].ToString()).Count == 0)
            {
                MessageBox.Show(this, "对不起,请至少提供一名客户联系人!");
                return;
            }
        }

        string IsRMSClient = _bll.Model["IsRMSClient"];

        pl_detail.GetData(_bll.Model);


        #region 判断必填项
        if (_bll.Model.OrganizeCity == 0)
        {
            MessageBox.Show(this, "所属的管理片区必填!");
            return;
        }
        if (_bll.Model.OfficalCity == 0)
        {
            MessageBox.Show(this, "所属的行政城市必填!");
            return;
        }
        if (_bll.Model.Supplier == 0)
        {
            MessageBox.Show(this, "供货商信息必填!");
            return;
        }
        if (_bll.Model["Supplier2"] == "")
        {
            MessageBox.Show(this, "赠品供货商信息必填!");
            return;
        }
        if (_bll.Model["OperateProperty"] == "0")
        {
            MessageBox.Show(this, "归属办事处类型必填!");
            return;
        }
        if (new Addr_OfficialCityBLL(_bll.Model.OfficalCity).Model.Level < 3)
        {
            MessageBox.Show(this, "门店所在行政城市必须到区或县城!");
            return;
        }
        if (_bll.Model["RTChannel"] == "0")
        {
            MessageBox.Show(this, "门店渠道必填!");
            return;
        }
        if ((_bll.Model["RTChannel"] == "1" || _bll.Model["RTChannel"] == "2") && _bll.Model["VestKA"] == "0")
        {
            MessageBox.Show(this, "当门店渠道为LKA,或NKA时,KA系统必填!");
            return;
        }
        if (_bll.Model["Classification"] == "" || _bll.Model["Classification"] == "0")
        {
            MessageBox.Show(this, "“门店归类”必填!");
            return;
        }
        if ((_bll.Model["MarketType"] == "" || _bll.Model["MarketType"] == "0"))
        {
            MessageBox.Show(this, "“市场类型”必填!");
            return;
        }
        #endregion

        if (_bll.Model["IsRMSClient"] == "2" && IsRMSClient != "2")
        {
            _bll.Model["RMSCloseDate"] = DateTime.Now.ToString("yyyy-MM-dd");
        }

        string[] RTChannelLimit1    = ConfigHelper.GetConfigString("RTChannelLimit1").Split(',');
        string[] RTChannelLimit2    = ConfigHelper.GetConfigString("RTChannelLimit2").Split(',');
        string[] RT_Classification1 = ConfigHelper.GetConfigString("Classification1").Split(',');
        string[] RT_Classification2 = ConfigHelper.GetConfigString("Classification2").Split(',');
        if (RTChannelLimit1.Contains(_bll.Model["RTChannel"]) && !RT_Classification1.Contains(_bll.Model["Classification"]) ||
            RTChannelLimit2.Contains(_bll.Model["RTChannel"]) && !RT_Classification2.Contains(_bll.Model["Classification"]))
        {
            MessageBox.Show(this, "“门店渠道”与“门店归类”匹配不规范,请重新选填!");
            return;
        }


        #region 判断活跃标志
        if (_bll.Model.ActiveFlag == 1 && _bll.Model.CloseTime != new DateTime(1900, 1, 1))
        {
            _bll.Model.CloseTime = new DateTime(1900, 1, 1);
        }

        if (_bll.Model.ActiveFlag == 2 && _bll.Model.CloseTime == new DateTime(1900, 1, 1))
        {
            _bll.Model.CloseTime = DateTime.Now;
        }
        #endregion

        #region 自动设定“是否促销店”字段
        switch (_bll.Model["RTClassify"])
        {
        case "2":          //返利店
            _bll.Model["IsPromote"] = "2";
            _bll.Model["IsRebate"]  = "1";
            break;

        case "3":          //导购店
            _bll.Model["IsPromote"] = "1";
            _bll.Model["IsRebate"]  = "2";
            break;

        case "4":          //导购返利店
            _bll.Model["IsPromote"] = "1";
            _bll.Model["IsRebate"]  = "1";
            break;

        case "1":          //流通店
        default:
            _bll.Model["IsPromote"] = "2";
            _bll.Model["IsRebate"]  = "2";
            break;
        }
        #endregion

        Addr_OfficialCity city = new Addr_OfficialCityBLL(_bll.Model.OfficalCity).Model;
        if (city != null)
        {
            if (_bll.Model.PostCode == "")
            {
                _bll.Model.PostCode = city.PostCode;
            }
            if (_bll.Model["Township"] == "" && city.Level == 4)
            {
                _bll.Model["Township"] = city.Name;
            }
        }

        if (ViewState["ClientID"] == null)
        {
            _bll.Model.ClientType  = 3;
            _bll.Model.ApproveFlag = 2;
            _bll.Model.InsertStaff = (int)Session["UserID"];
            ViewState["ClientID"]  = _bll.Add();
        }
        else
        {
            _bll.Model.UpdateStaff = (int)Session["UserID"];
            _bll.Update();
        }
        if (sender != null)
        {
            MessageBox.ShowAndRedirect(this, "保存终端门店资料成功!", "RetailerDetail.aspx?ClientID=" + ViewState["ClientID"].ToString());
        }
    }
Esempio n. 27
0
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] == 1)
        {
            return;
        }

        Addr_OfficialCityBLL _bll;


        if ((int)ViewState["ID"] == 0)
        {
            _bll = new Addr_OfficialCityBLL();
        }
        else
        {
            _bll = new Addr_OfficialCityBLL((int)ViewState["ID"]);
        }

        _bll.Model.Name         = tbx_Name.Text;
        _bll.Model.SuperID      = int.Parse(tree_SuperID.SelectValue);
        _bll.Model.Code         = tbx_Code.Text;
        _bll.Model.CallAreaCode = tbx_CallAreaCode.Text;
        _bll.Model.PostCode     = tbx_PostCode.Text;
        _bll.Model.Level        = new Addr_OfficialCityBLL(_bll.Model.SuperID).Model.Level + 1;
        _bll.Model.Births       = int.Parse(tbx_Births.Text.Trim() == "" ? "0" : tbx_Births.Text.Trim());
        _bll.Model.Attribute    = int.Parse(ddl_CityAttributeFlag.SelectedValue);
        if (DictionaryBLL.GetDicCollections("Addr_OfficialCityLevel")[_bll.Model.Level.ToString()] == null)
        {
            lbl_AlertInfo.Text = "添加城市失败,等级超出范围";
            return;
        }

        if ((int)ViewState["ID"] == 0)
        {
            int resultAdd = _bll.Add();
            if (resultAdd < 0)
            {
                lbl_AlertInfo.Text = "添加城市失败,城市名称已存在";
                return;
            }
        }
        else
        {
            int ret = _bll.Update();

            switch (ret)
            {
            case -1:
                lbl_AlertInfo.Text = "更新城市失败,城市名称已存在";
                return;

            case -2:
                lbl_AlertInfo.Text = "更新城市失败,不能将当前城市设置为上级城市";
                return;

            case -3:
                lbl_AlertInfo.Text = "更新城市失败,不能将当前城市的子城市设置为上级城市";
                return;
            }
        }

        Response.Redirect("OfficialCityManage.aspx?SuperID=" + _bll.Model.SuperID.ToString());
    }
    protected void bt_OK_Click(object sender, EventArgs e)
    {
        CM_ClientBLL _bll = null;
        if (ViewState["ClientID"] == null)
        {
            _bll = new CM_ClientBLL();

        }
        else
        {
            _bll = new CM_ClientBLL((int)ViewState["ClientID"]);
            if (CM_LinkManBLL.GetModelList("ClientID=" + ViewState["ClientID"].ToString()).Count == 0)
            {
                MessageBox.Show(this, "对不起,请至少提供一名客户联系人!");
                return;
            }
        }

        string IsRMSClient = _bll.Model["IsRMSClient"];
        pl_detail.GetData(_bll.Model);

        #region 判断必填项
        if (_bll.Model.OrganizeCity == 0)
        {
            MessageBox.Show(this, "所属的管理片区必填!");
            return;
        }
        if (_bll.Model.OfficalCity == 0)
        {
            MessageBox.Show(this, "所属的行政城市必填!");
            return;
        }
        if (_bll.Model.Supplier == 0)
        {
            MessageBox.Show(this, "供货商信息必填!");
            return;
        }
        if (_bll.Model["Supplier2"] == "")
        {
            MessageBox.Show(this, "赠品供货商信息必填!");
            return;
        }
        if (_bll.Model["OperateProperty"] == "0")
        {
            MessageBox.Show(this, "归属办事处类型必填!");
            return;
        }
        if (new Addr_OfficialCityBLL(_bll.Model.OfficalCity).Model.Level < 3)
        {
            MessageBox.Show(this, "门店所在行政城市必须到区或县城!");
            return;
        }
        if (_bll.Model["RTChannel"] == "0")
        {
            MessageBox.Show(this, "门店渠道必填!");
            return;
        }
        if ((_bll.Model["RTChannel"] == "1" || _bll.Model["RTChannel"] == "2") && _bll.Model["VestKA"] == "0")
        {
            MessageBox.Show(this, "当门店渠道为LKA,或NKA时,KA系统必填!");
            return;
        }
        if (_bll.Model["Classification"] == "" || _bll.Model["Classification"] == "0")
        {
            MessageBox.Show(this, "“门店归类”必填!");
            return;
        }
        if ((_bll.Model["MarketType"] == "" || _bll.Model["MarketType"] == "0"))
        {
            MessageBox.Show(this, "“市场类型”必填!");
            return;
        }
        #endregion

        if (_bll.Model["IsRMSClient"] == "2" && IsRMSClient != "2")
        {
            _bll.Model["RMSCloseDate"] = DateTime.Now.ToString("yyyy-MM-dd");
        }

        string[] RTChannelLimit1 = ConfigHelper.GetConfigString("RTChannelLimit1").Split(',');
        string[] RTChannelLimit2 = ConfigHelper.GetConfigString("RTChannelLimit2").Split(',');
        string[] RT_Classification1 = ConfigHelper.GetConfigString("Classification1").Split(',');
        string[] RT_Classification2 = ConfigHelper.GetConfigString("Classification2").Split(',');
        if (RTChannelLimit1.Contains(_bll.Model["RTChannel"]) && !RT_Classification1.Contains(_bll.Model["Classification"])
            || RTChannelLimit2.Contains(_bll.Model["RTChannel"]) && !RT_Classification2.Contains(_bll.Model["Classification"]))
        {
            MessageBox.Show(this, "“门店渠道”与“门店归类”匹配不规范,请重新选填!");
            return;
        }

        #region 判断活跃标志
        if (_bll.Model.ActiveFlag == 1 && _bll.Model.CloseTime != new DateTime(1900, 1, 1))
            _bll.Model.CloseTime = new DateTime(1900, 1, 1);

        if (_bll.Model.ActiveFlag == 2 && _bll.Model.CloseTime == new DateTime(1900, 1, 1))
            _bll.Model.CloseTime = DateTime.Now;
        #endregion

        #region 自动设定“是否促销店”字段
        switch (_bll.Model["RTClassify"])
        {
            case "2":      //返利店
                _bll.Model["IsPromote"] = "2";
                _bll.Model["IsRebate"] = "1";
                break;
            case "3":      //导购店
                _bll.Model["IsPromote"] = "1";
                _bll.Model["IsRebate"] = "2";
                break;
            case "4":      //导购返利店
                _bll.Model["IsPromote"] = "1";
                _bll.Model["IsRebate"] = "1";
                break;
            case "1":      //流通店
            default:
                _bll.Model["IsPromote"] = "2";
                _bll.Model["IsRebate"] = "2";
                break;
        }
        #endregion

        Addr_OfficialCity city = new Addr_OfficialCityBLL(_bll.Model.OfficalCity).Model;
        if (city != null)
        {
            if (_bll.Model.PostCode == "") _bll.Model.PostCode = city.PostCode;
            if (_bll.Model["Township"] == "" && city.Level == 4) _bll.Model["Township"] = city.Name;
        }

        if (ViewState["ClientID"] == null)
        {
            _bll.Model.ClientType = 3;
            _bll.Model.ApproveFlag = 2;
            _bll.Model.InsertStaff = (int)Session["UserID"];
            ViewState["ClientID"] = _bll.Add();
        }
        else
        {
            _bll.Model.UpdateStaff = (int)Session["UserID"];
            _bll.Update();
        }
        if (sender != null)
        {
            MessageBox.ShowAndRedirect(this, "保存终端门店资料成功!", "RetailerDetail.aspx?ClientID=" + ViewState["ClientID"].ToString());
        }
    }
    protected void bt_OK_Click(object sender, EventArgs e)
    {
        Org_StaffBLL _staffbll = null;

        if ((int)ViewState["ID"] == 0)
        {
            _staffbll = new Org_StaffBLL();
        }
        else
        {
            _staffbll = new Org_StaffBLL((int)ViewState["ID"]);
        }

        int oldPosition     = _staffbll.Model.Position;
        int oldOrganizeCity = _staffbll.Model.OrganizeCity;

        panel1.GetData(_staffbll.Model);

        if ((int)ViewState["ID"] != 0 && (oldPosition != _staffbll.Model.Position || oldOrganizeCity != _staffbll.Model.OrganizeCity) &&
            EWF_Task_JobDecisionBLL.GetModelList("DecisionResult=1 AND RecipientStaff=" + ViewState["ID"].ToString()).Count > 0)
        {
            MessageBox.Show(this, "对不起,该人员还有未审批流程不能调整【职务】或【管理片区】信息!");
            return;
        }
        Addr_OfficialCityBLL citybll = new Addr_OfficialCityBLL(_staffbll.Model.OfficialCity);

        if (citybll != null && citybll.Model.Level < 2)
        {
            MessageBox.Show(this, "驻点所在城市必须选到市级!");
            return;
        }

        Org_Staff _staffM = new Org_StaffBLL((int)Session["UserID"]).Model;

        if (_staffM.Position == _staffbll.Model.Position && new Org_PositionBLL(_staffM.Position).Model.IsHeadOffice != "Y")
        {
            MessageBox.Show(this, "对不起,您没有权限新增职位与您相同的员工");
            return;
        }

        if (_staffbll.Model["OperateProperty"] == "0")
        {
            MessageBox.Show(this, "归属办事处类型必填!");
            return;
        }

        if ((int)ViewState["ID"] == 0)
        {
            #region 根据身份证号判断是否重复
            if (_staffbll.Model["IDCode"] != string.Empty &&
                Org_StaffBLL.GetStaffList("MCS_SYS.dbo.UF_Spilt(Org_Staff.ExtPropertys,'|',1)='" + _staffbll.Model["IDCode"] + "' AND Dimission=1").Count > 0)
            {
                MessageBox.Show(this, "对不起,该身份证号的员工已在系统中入职,请核实后再新增员工!");
                return;
            }
            #endregion

            if (Org_StaffNumberLimitBLL.CheckAllowAdd(_staffbll.Model.OrganizeCity, _staffbll.Model.Position) <= 0)
            {
                MessageBox.Show(this, "对不起当前城市该职位员工人数满额,要想继续新增请与人事经理联系");
                return;
            }
            _staffbll.Model.InsertStaff = (int)Session["UserID"];
            _staffbll.Model.InsertTime  = DateTime.Now;
            _staffbll.Model.ApproveFlag = 1;            //未审批
            _staffbll.Model.Dimission   = 1;            //在职
            ViewState["ID"]             = _staffbll.Add();
        }
        else
        {
            if (!Org_StaffNumberLimitBLL.IsSameLimit(oldOrganizeCity, _staffbll.Model.OrganizeCity, oldPosition, _staffbll.Model.Position) &&
                Org_StaffNumberLimitBLL.CheckAllowAdd(_staffbll.Model.OrganizeCity, _staffbll.Model.Position) <= 0)
            {
                MessageBox.Show(this, "对不起当前城市该职位员工人数满额,要想继续新增请与人事经理联系");
                return;
            }
            _staffbll.Model.UpdateStaff = (int)Session["UserID"];
            _staffbll.Update();
        }
        MessageBox.ShowAndRedirect(this, "保存成功", "StaffDetail.aspx?ID=" + ViewState["ID"].ToString());
    }
    private void BindData(int ID)
    {
        ViewState["ID"] = ID;

        Addr_OfficialCityBLL _bll = new Addr_OfficialCityBLL(ID);
        lbl_ID.Text = _bll.Model.ID.ToString();
        tbx_Name.Text = _bll.Model.Name;
        tree_SuperID.SelectValue = _bll.Model.SuperID.ToString();
        tbx_Code.Text = _bll.Model.Code;
        tbx_CallAreaCode.Text = _bll.Model.CallAreaCode;
        tbx_PostCode.Text = _bll.Model.PostCode;
        tbx_Births.Text = _bll.Model.Births.ToString();
        ddl_CityAttributeFlag.SelectedValue = _bll.Model.Attribute.ToString();
        if (_bll.Model.Level != 0)
            lbl_LevelName.Text = DictionaryBLL.GetDicCollections("Addr_OfficialCityLevel")[_bll.Model.Level.ToString()].Name;

        btn_Save.Text = "修改";
        btn_Save.ForeColor = System.Drawing.Color.Red;
        btn_Delete.Visible = true;
        MessageBox.ShowConfirm(btn_Delete, "数据删除将不可恢复,确定删除么?");
        btn_Cancel.Visible = true;
        bt_AddSub.Visible = true;

        lbl_AlertInfo.Text = "";

        if ((int)ViewState["ID"] == 1)
        {
            btn_Save.Enabled = false;
        }
        else
        {
            btn_Save.Enabled = true;
        }

        btn_Delete.Visible = Addr_OfficialCityBLL.GetModelList("SuperID=" + ViewState["ID"].ToString()).Count == 0;

        BindOfficialPopulation();
    }
    protected void bt_Create_Click(object sender, EventArgs e)
    {
        DateTime begindate = DateTime.Parse(tbx_begindate.Text);
        DateTime enddate   = DateTime.Parse(tbx_enddate.Text);

        #region 规则校验
        if (select_PlanStaff.SelectValue == "")
        {
            MessageBox.Show(this, "请正确选择要填报计划的员工!");
            return;
        }
        if (begindate < DateTime.Today)
        {
            MessageBox.Show(this, "开始日期不能小于今天!");
            return;
        }

        if (enddate < begindate)
        {
            MessageBox.Show(this, "截止日期必须大于开始日期!");
            return;
        }

        if ((enddate - begindate).Days > 31)
        {
            MessageBox.Show(this, "日期范围不能超过一个月!");
            return;
        }

        if (JN_WorkingPlanBLL.GetModelList("Staff = " + select_PlanStaff.SelectValue +
                                           " AND ( (BeginDate BETWEEN '" + begindate.ToString("yyyy-MM-dd") + "' AND '" + enddate.ToString("yyyy-MM-dd") +
                                           "') OR ('" + begindate.ToString("yyyy-MM-dd") + "' BETWEEN BeginDate AND EndDate) )").Count > 0)
        {
            MessageBox.Show(this, "日期范围与系统中已填报的计划有日期重叠!");
            return;
        }
        #endregion

        InitGridView(begindate, enddate);
        DataTable dt = GenareateDataTable(begindate, enddate);

        #region 页面控件使能控制
        tr_adddetail.Visible     = true;
        tbx_begindate.Enabled    = false;
        tbx_enddate.Enabled      = false;
        select_PlanStaff.Enabled = false;
        tr_OrganizeCity.Enabled  = false;

        cbx_GenarateSynergetic.Visible = false;
        bt_Create.Visible = false;
        bt_Save.Visible   = true;
        #endregion

        #region 载入该操作员所有负责客户,加入客户拜访记录计划中
        IList <CM_Client> clients = CM_ClientBLL.GetModelList("ClientManager=" + select_PlanStaff.SelectValue + " AND ActiveFlag=1 AND ApproveFlag=1");

        foreach (CM_Client client in clients)
        {
            DataRow dr = dt.NewRow();

            dr["WorkingClassify"]     = "1";
            dr["WorkingClassifyName"] = DictionaryBLL.GetDicCollections("OA_WorkingClassify")["1"].Name;

            dr["RelateClient"]     = client.ID;
            dr["RelateClientName"] = client.FullName;

            dr["RelateStaff"]     = 0;
            dr["RelateStaffName"] = "";

            dr["OfficialCity"] = client.OfficalCity;
            if (client.OfficalCity > 0)
            {
                dr["OfficialCityName"] = TreeTableBLL.GetFullPathName("MCS_SYS.dbo.Addr_OfficialCity", client.OfficalCity).Replace("->", " ");
            }

            dt.Rows.Add(dr);
        }
        #endregion

        #region 加入协同拜访工作项,管理片区非总部员工,将所有下级员工加入
        if (cbx_GenarateSynergetic.Checked && int.Parse(tr_OrganizeCity.SelectValue) > 1)
        {
            #region 所有下级职位(不含本级职位)
            string    positions          = "";
            int       position           = new Org_StaffBLL(int.Parse(select_PlanStaff.SelectValue)).Model.Position;
            DataTable dtAllChilePosition = TreeTableBLL.GetAllChildByNodes("MCS_SYS.dbo.Org_Position", "ID", "SuperID", position.ToString());
            for (int i = 0; i < dtAllChilePosition.Rows.Count; i++)
            {
                positions += dtAllChilePosition.Rows[i]["ID"].ToString();
                if (i != dtAllChilePosition.Rows.Count - 1)
                {
                    positions += ",";
                }
            }
            #endregion

            #region 所有本级及下级管理片区
            string orgcitys = "";
            Addr_OrganizeCityBLL orgcity = new Addr_OrganizeCityBLL(int.Parse(tr_OrganizeCity.SelectValue), true);
            orgcitys = orgcity.GetAllChildNodeIDs();
            if (orgcitys != "")
            {
                orgcitys += ",";
            }
            orgcitys += tr_OrganizeCity.SelectValue;
            #endregion

            if (positions != "" && orgcitys != "")
            {
                IList <Org_Staff> staffs = Org_StaffBLL.GetStaffList("OrganizeCity IN (" + orgcitys + ") AND Position IN (" + positions + ") AND Dimission=1 AND ApproveFlag=1");

                foreach (Org_Staff staff in staffs)
                {
                    DataRow dr = dt.NewRow();

                    dr["WorkingClassify"]     = "2";
                    dr["WorkingClassifyName"] = DictionaryBLL.GetDicCollections("OA_WorkingClassify")["2"].Name;

                    dr["RelateClient"]     = 0;
                    dr["RelateClientName"] = "";

                    dr["RelateStaff"]     = staff.ID;
                    dr["RelateStaffName"] = staff.RealName;

                    dr["OfficialCity"] = staff.OfficialCity;
                    if (staff.OfficialCity > 0)
                    {
                        dr["OfficialCityName"] = TreeTableBLL.GetFullPathName("MCS_SYS.dbo.Addr_OfficialCity", staff.OfficialCity).Replace("->", " ");
                    }

                    dt.Rows.Add(dr);
                }
            }
        }
        #endregion

        #region 加入除客户拜访以外的工作项
        foreach (ListItem item in ddl_WorkingClassify.Items)
        {
            if (int.Parse(item.Value) >= 3)
            {
                DataRow dr = dt.NewRow();
                dr["WorkingClassify"]     = int.Parse(item.Value);
                dr["WorkingClassifyName"] = item.Text;
                dr["Description"]         = "";
                dr["RelateClient"]        = 0;
                dr["RelateClientName"]    = "";

                dr["RelateStaff"]     = 0;
                dr["RelateStaffName"] = "";

                dr["OfficialCity"] = (int)ViewState["StaffOfficialCity"];
                if (ViewState["StaffOfficialCity"] != null && (int)ViewState["StaffOfficialCity"] != 0)
                {
                    dr["OfficialCityName"] = new Addr_OfficialCityBLL((int)ViewState["StaffOfficialCity"]).Model.Name;
                }
                else
                {
                    dr["OfficialCity"] = 0;
                }

                dr["Cost1"] = 0;
                dr["Cost2"] = 0;
                dt.Rows.Add(dr);
            }
        }
        #endregion

        ViewState["WorkingPlanData"] = dt;
        ViewState["BeginDate"]       = begindate;
        ViewState["EndDate"]         = enddate;

        BindGrid();
    }
    private void BindOfficialPopulation()
    {
        if ((int)ViewState["ID"] > 0)
        {
            Addr_OfficialCityPopulationBLL populationBindBll = new Addr_OfficialCityPopulationBLL((int)ViewState["ID"]);
            Addr_OfficialCityBLL bll = new Addr_OfficialCityBLL((int)ViewState["ID"]);
            DataTable officialDatatable = bll.GetAllChildNode();
            if (officialDatatable.Rows.Count <= 0)
            {
                pl_Details.Visible = true;
                btn_SavePopulation.Visible = true;
                if (populationBindBll.Model == null)
                {
                    populationBindBll = new Addr_OfficialCityPopulationBLL();
                    populationBindBll.Model.ID = bll.Model.ID;

                }

                pl_Details.BindData(populationBindBll.Model);

            }

            else
            {
                pl_Details.Visible = false;
                btn_SavePopulation.Visible = false;
            }

        }
        else
        {
            pl_Details.Visible = false;
            btn_SavePopulation.Visible = false;

        }
    }
    protected void tr_OfficialCity_Selected(object sender, MCSControls.MCSWebControls.SelectedEventArgs e)
    {
        cbl_OfficialList.Items.Clear();
        DataTable dt = TreeTableBLL.GetAllChildByNodes("MCS_SYS.dbo.Addr_OfficialCity", "ID", "SuperID", tr_OfficialCity.SelectValue);

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            Addr_OfficialCityBLL city = new Addr_OfficialCityBLL((int)dt.Rows[i]["ID"]);
            if (city.Model.Level == 3)
            {
                string fullname = TreeTableBLL.GetFullPathName("MCS_SYS.dbo.Addr_OfficialCity", city.Model.ID);
                ListItem item = new ListItem(fullname, city.Model.ID.ToString());

                IList<Addr_OfficialCityInOrganizeCity> organizecitys = Addr_OfficialCityInOrganizeCityBLL.GetModelList("OfficialCity=" + city.Model.ID.ToString());
                if (organizecitys.Count > 0)
                {
                    Addr_OrganizeCity organizecity = new Addr_OrganizeCityBLL(organizecitys[0].OrganizeCity).Model;
                    if (organizecity != null)
                    {
                        item.Text += "; 已归属于片区:【" + organizecity.Name + "】";
                    }
                    item.Enabled = false;
                }

                cbl_OfficialList.Items.Add(item);
            }
        }
    }
    private void BindData(int ID)
    {
        ViewState["ID"] = ID;

        Addr_OrganizeCityBLL _bll = new Addr_OrganizeCityBLL(ID);
        lbl_ID.Text = _bll.Model.ID.ToString();
        tbx_Name.Text = _bll.Model.Name;
        if (_bll.Model.SuperID != 0)
            tree_SuperID.SelectValue = _bll.Model.SuperID.ToString();
        tbx_Code.Text = _bll.Model.Code;

        if (_bll.Model.Manager != 0)
        {
            select_Manager.SelectValue = _bll.Model.Manager.ToString();
            select_Manager.SelectText = new Org_StaffBLL(_bll.Model.Manager).Model.RealName;
        }
        else
        {
            select_Manager.SelectValue = "";
            select_Manager.SelectText = "";
        }

        if (_bll.Model.Level != 0)
            lbl_LevelName.Text = DictionaryBLL.GetDicCollections("Addr_OrganizeCityLevel")[_bll.Model.Level.ToString()].Name;

        tbx_ManageRegion.Text = _bll.Model["ManageRegion"];

        if (ID == 1)
        {
            btn_Save.Visible = false;
            btn_Delete.Visible = false;
        }
        else
        {
            btn_Save.Visible = true;
            btn_Delete.Visible = true;
        }
        bt_AddSub.Visible = true;
        MessageBox.ShowConfirm(btn_Delete, "数据删除将不可恢复,确定删除么?");

        btn_Delete.Visible = Addr_OrganizeCityBLL.GetModelList("SuperID=" + ViewState["ID"].ToString()).Count == 0;
        lbl_AlertInfo.Text = "";

        #region 绑定已关联的行政区县列表
        if (_bll.Model.Level.ToString() == ConfigHelper.GetConfigString("OrganizeCity-CityLevel"))
        {
            tb_OfficialCityInOrganizeCity.Visible = true;
            cb_CheckAll.Checked = false;
            cbl_OfficialList.Items.Clear();
            IList<Addr_OfficialCityInOrganizeCity> lists = Addr_OfficialCityInOrganizeCityBLL.GetModelList("OrganizeCity = " + ID.ToString());
            foreach (Addr_OfficialCityInOrganizeCity e in lists)
            {
                Addr_OfficialCityBLL city = new Addr_OfficialCityBLL(e.OfficialCity);
                string fullname = TreeTableBLL.GetFullPathName("MCS_SYS.dbo.Addr_OfficialCity", city.Model.ID);
                ListItem item = new ListItem(fullname, e.ID.ToString());

                cbl_OfficialList.Items.Add(item);
            }
            bt_AddOfficialCity.OnClientClick = "PopAddOfficialCity(" + ID.ToString() + ")";
        }
        else
        {
            tb_OfficialCityInOrganizeCity.Visible = false;
        }
        #endregion
    }