private void GetPositionHistory()
        {
            List <Performance.Error> errors = new List <Performance.Error>();
            List <PositionViewModel> positionViewModelUIs = new List <PositionViewModel>();

            try
            {
                List <PositionHistory> phs =
                    InstanceFactory.CreatePositionHistoryFacade().GetPositionHistoryByPositionID(
                        Convert.ToInt32(_Context.Request.Params["Pkid"]));

                positionViewModelUIs = PositionViewModel.Turn(phs);
            }
            catch (Exception e)
            {
                errors.Add(new Performance.Error("lblMessage", e.Message));
            }
            _ResponseString =
                string.Format("{{\"itemList\":{0},\"error\":{1}}}", JsonConvert.SerializeObject(positionViewModelUIs),
                              JsonConvert.SerializeObject(errors));
        }
        private void SearchPosition()
        {
            List <Performance.Error> errors = new List <Performance.Error>();
            List <PositionViewModel> positionViewModelUIs = new List <PositionViewModel>();

            try
            {
                string Name =
                    (_Context.Request.Params["Name"] ?? string.Empty).Replace(';', ';').Trim().Trim(';').Trim();
                //string Grade =
                //    (_Context.Request.Params["Grade"] ?? string.Empty).Replace(';', ';').Trim().Trim(';').Trim();
                string Nature =
                    (_Context.Request.Params["Nature"] ?? string.Empty).Replace(';', ';').Trim().Trim(';').Trim();
                string Department =
                    (_Context.Request.Params["Department"] ?? string.Empty).Replace(';', ';').Trim().Trim(';').Trim();
                string AccountName =
                    (_Context.Request.Params["AccountName"] ?? string.Empty).Replace(';', ';').Trim().Trim(';').Trim();

                string NameWhere = string.Empty;
                foreach (string str in Name.Split(';'))
                {
                    NameWhere += string.IsNullOrEmpty(NameWhere)
                                     ? "positionname like '%" + str.Trim() + "%' "
                                     : "or positionname like '%" + str.Trim() + "%' ";
                }
                //string GradeWhere = string.Empty;
                //foreach (string str in Grade.Split(';'))
                //{
                //    GradeWhere += string.IsNullOrEmpty(GradeWhere)
                //                      ? "PositionGradeName like '%" + str.Trim() + "%' "
                //                      : "or PositionGradeName like '%" + str.Trim() + "%' ";
                //}
                string NatureWhere = string.Empty;
                foreach (string str in Nature.Split(';'))
                {
                    NatureWhere += string.IsNullOrEmpty(NatureWhere)
                                       ? "tpositionnature.name like '%" + str.Trim() + "%' "
                                       : "or tpositionnature.name like '%" + str.Trim() + "%' ";
                }
                string DepartmentWhere = string.Empty;
                foreach (string str in Department.Split(';'))
                {
                    DepartmentWhere += string.IsNullOrEmpty(DepartmentWhere)
                                           ? "Departmentname like '%" + str.Trim() + "%' "
                                           : "or Departmentname like '%" + str.Trim() + "%' ";
                }
                string AccountNameWhere = string.Empty;
                foreach (string str in AccountName.Split(';'))
                {
                    AccountNameWhere += string.IsNullOrEmpty(AccountNameWhere)
                                            ? "employeename like '%" + str.Trim() + "%' "
                                            : "or employeename like '%" + str.Trim() + "%' ";
                }
                string sql = "select distinct tposition.pkid "
                             + "from tposition "
                             + "where (" + NameWhere + ") "
                             + "and  (     '' = '" + Nature + "' "
                             + "     or"
                             + "      ("
                             + "         tposition.pkid in "
                             + "		 (	 select tpositionnaturerelationship.positionid "
                             + "			 from tpositionnature,tpositionnaturerelationship "
                             + "			 where tpositionnature.pkid = tpositionnaturerelationship.positionnatureid "
                             + "			 and ("+ NatureWhere + ") "
                             + "		 ) "
                             + "     ) "
                             + " ) "
                             + "and  (     '' = '" + Department + "' "
                             + "     or"
                             + "      ("
                             + "         tposition.pkid in "
                             + "		 (	 select tpositiondeptrelationship.positionid "
                             + "			 from tDepartment,tpositiondeptrelationship "
                             + "			 where tDepartment.pkid = tpositiondeptrelationship.deptid "
                             + "			 and ("+ DepartmentWhere + ") "
                             + "		 ) "
                             + "     ) "
                             + " ) "
                             + "and  (     '' = '" + AccountName + "' "
                             + "     or "
                             + "      ( "
                             + "         tposition.pkid in "
                             + "		 (	 select taccount.positionid "
                             + "			 from taccount "
                             + "			 where ("+ AccountNameWhere + ") "
                             + "		 ) "
                             + "     ) "
                             + " ) ";
                //+ "and  (     '' = '" + Grade + "' "
                //+ "     or "
                //+ "      ( "
                //+ "         tposition.pkid in "
                //+ "		 (	 select tposition.pkid "
                //+ "			 from tpositiongrade,tposition "
                //+ "			 where tpositiongrade.pkid = tposition.levelid "
                //+ "				and  (" + GradeWhere + ") "
                //+ "		 ) "
                //+ "     ) "
                //+ " ) ";

                List <Position> Positions = BllInstance.PositionBllInstance.GetPositionByCondition(sql);
                for (int i = 0; i < Positions.Count; i++)
                {
                    Positions[i] = BllInstance.PositionBllInstance.GetPositionById(Positions[i].Id, _Operator);
                }
                positionViewModelUIs = PositionViewModel.Turn(Positions);
            }
            catch (Exception e)
            {
                errors.Add(new Performance.Error("lblMessage", e.Message));
            }
            _ResponseString =
                string.Format("{{\"itemList\":{0},\"error\":{1}}}", JsonConvert.SerializeObject(positionViewModelUIs),
                              JsonConvert.SerializeObject(errors));
        }