Exemplo n.º 1
0
 protected override void Refresh(object o)
 {
     Services.ZhuanYeServicesClient service = new Services.ZhuanYeServicesClient();
     string result = service.ZhuanYeQuery();
     DataList = JsonConvert.DeserializeObject<DataTable>(result);
     service.Close();
 }
 /// <summary>
 /// 插入专业信息表
 /// </summary>
 /// <returns></returns>
 private bool InsertZhuanYe()
 {
     try
     {
         SetErrorMsg("正在导入基础专业信息");
         List<ZhuanYeModel> list = DbfHelper.GetList<ZhuanYeModel>(DbfSql.ZhuanYeSql);
         if (list != null)
         {
             //广东考生号只有10位
             string ksh = NewStudents.First().KSH.Trim();
             string year = ksh.Length > 10 ? ksh.Substring(0, 2) : DateTime.Now.Year.ToString().Substring(2, 2);
             Services.ZhuanYeServicesClient zhuanye = new Services.ZhuanYeServicesClient();
             string result = zhuanye.ZhuanYeQuery();
             List<ZhuanYeModel> zhuanyeList = JsonConvert.DeserializeObject<List<ZhuanYeModel>>(result);
             const string pattern = @"(.*?)\((.*?)\)";
             foreach (var item in list)
             {
                 //生成专业方向
                 item.Zymc = item.Zymc.Replace("(", "(").Replace(")", ")");
                 Match match = Regex.Match(item.Zymc, pattern, RegexOptions.IgnoreCase);
                 if (match.Success)
                 {
                     item.Zymc = match.Groups[1].Value;
                     item.Zyfx = match.Groups[2].Value;
                 }
                 item.Sfdm = year;
                 var query = zhuanyeList.Where(r => r.Sfdm == item.Sfdm && r.Pcdm == item.Pcdm && r.Kldm == item.Kldm
                          && r.Jhxz == item.Jhxz && r.Tddw == item.Tddw && r.Zydh == item.Zydh);
                 //如果专业存在就不在添加
                 if (query == null || query.Count() == 0)
                     zhuanye.ZhuanYeAdd(item);
             }
             zhuanye.Close();
             return true;
         }
         else
         {
             ErrorMsg = "没有争取获取录取专业信息";
             return false;
         }
     }
     catch (Exception ex)
     {
         ErrorMsg = ex.Message;
         return false;
     }
 }