public void ttt() { ReadProduct rf = new ReadProduct(); HashSet <string> set = new HashSet <string>(); foreach (string s in ReadProduct.list) { //Debug.WriteLine(s); set.Add(s.Split(',')[1]); } BaseInfo bi = new BaseInfo(); bi.init(); SearchService ss = new SearchService(); SynonymDao synonymDao = new SynonymDao(); WordDao wordDao = new WordDao(); WordSynonymDao wsDao = new WordSynonymDao(); int i = 50000; foreach (string s in set) { //Debug.WriteLine(s); t_word word = ss.getWordBySynonym(s); if (null == word) { Debug.WriteLine(s + "没有对应Word"); t_synonym t_synonym = new t_synonym() { code = i + "", name = s, remark = "" }; t_word t_word = new t_word() { code = i + "", type = "单品", name = s, remark = "" }; t_word_synonym t_word_synonym = new t_word_synonym() { word_code = i + "", synonym_code = i + "" }; synonymDao.add(t_synonym); wordDao.add(t_word); wsDao.add(t_word_synonym); Debug.WriteLine("添加成功"); i++; } else { Debug.WriteLine(s + "对应" + word.name + word.code); } } }
//根据基础信息、楼层,查询活动列表 public List <t_activity> GetActivityListByBasciInfoAndFloor(String basicInfoText, String floorText, String builtinDatetimeDateResolution) { List <t_activity> activityList = new List <t_activity>(); //楼层 String basic_info_code = String.Empty; //楼层 String floor_code = String.Empty; //判断基础信息是否为空 if (!String.IsNullOrWhiteSpace(basicInfoText)) { t_word bi_word = getWordBySynonym(basicInfoText); //判断基础信息是否可以查询到 if (null != bi_word) { basic_info_code = bi_word.code; } //基础信息查询不到就返回空列表 else { return(activityList); } } //判断楼层是否为空 if (!String.IsNullOrWhiteSpace(floorText)) { t_word f_word = getWordBySynonym(floorText); //判断楼层是否可以查询到 if (null != f_word) { floor_code = f_word.code; } //楼层查询不到就返回空列表 else { return(activityList); } } activityList = activityDao.getDataByCondition(basic_info_code, floor_code, MSDateUtil.getBegin(builtinDatetimeDateResolution), MSDateUtil.getEnd(builtinDatetimeDateResolution)); if (activityList.Count >= 5) { activityList = activityList.Take(5).ToList(); } return(activityList); }
public void add(t_word po) { crm1Entities context = new crm1Entities(); //3.将改对象放入EF容器中,默认会为该对象加一个封装类对象(代理类对象) //用户对对象的操作,实际上是对代理类的操作 //DbEntityEntry保存着实体状态,当对象被加入时,EF默认为该对象设置State的属性为unchanged DbEntityEntry <t_word> entityEntry = context.Entry <t_word>(po); //4.设置对象的标志位Added entityEntry.State = EntityState.Added; //5.当调用SaveChanges()时,EF会遍历所有的代理类对象,并根据标志生成相应的sql语句 context.SaveChanges(); //Console.WriteLine("添加成功"); }
public void test1Test() { try { BaseInfo bi = new BaseInfo(); bi.init(); SearchService ss = new SearchService(); SynonymDao synonymDao = new SynonymDao(); WordDao wordDao = new WordDao(); WordSynonymDao wsDao = new WordSynonymDao(); ActivityDao activityDao = new ActivityDao(); ReadActivity rf = new ReadActivity(); if (null != ReadActivity.dic) { int i = 30000; foreach (Activity obj in ReadActivity.dic.Values) { Debug.WriteLine(obj.ToString()); t_synonym t_synonym = new t_synonym() { code = i + "", name = obj.Word, remark = "" }; t_word t_word = new t_word() { code = i + "", type = "活动", name = obj.Word, remark = "" }; t_word_synonym t_word_synonym = new t_word_synonym() { word_code = i + "", synonym_code = i + "" }; //t_brand t_brand = new t_brand { code = i + "", brand = i + "", floor = ss.getWordBySynonym(b.Floor).code, contract = b.BrandCode, house_number = b.UnitNumber, vip_flag = "特约商户".Equals(b.VipFee) ? 1 : 0 }; DateTimeFormatInfo dtFormat = new DateTimeFormatInfo(); dtFormat.ShortDatePattern = "MM/dd/yyyy"; t_activity t_activity = new t_activity { code = i + "", activity = i + "", floor = String.IsNullOrEmpty(obj.Floor)? "" : ss.getWordBySynonym(obj.Floor).code, basic_info = String.IsNullOrEmpty(obj.BasicInfo) ? "" : ss.getWordBySynonym(obj.BasicInfo).code, remark = obj.Remark, begin = Convert.ToDateTime(obj.Begin, dtFormat), end = Convert.ToDateTime(obj.End, dtFormat) }; synonymDao.add(t_synonym); wordDao.add(t_word); wsDao.add(t_word_synonym); activityDao.add(t_activity); Debug.WriteLine("添加成功"); i++; } } else { Debug.WriteLine("dic = null" + " ; path = " + ReadActivity.path); } } catch (DbEntityValidationException ex) { Debug.WriteLine(ex.ToString()); StringBuilder errors = new StringBuilder(); IEnumerable <DbEntityValidationResult> validationResult = ex.EntityValidationErrors; foreach (DbEntityValidationResult result in validationResult) { ICollection <DbValidationError> validationError = result.ValidationErrors; foreach (DbValidationError err in validationError) { errors.Append(err.PropertyName + ":" + err.ErrorMessage + "\r\n"); } } Debug.WriteLine(errors.ToString()); //简写 //var validerr = ex.EntityValidationErrors.First().ValidationErrors.First(); //Console.WriteLine(validerr.PropertyName + ":" + validerr.ErrorMessage); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
//根据单品,楼层,特约商户,查询品牌列表 public List <t_brand> GetBrandListByProductAndFloor(String productText, String floorText, bool VipFlag) { List <t_brand> brandList = new List <t_brand>(); //品牌列表 List <String> code_list = new List <String>(); //楼层 String floor_code = String.Empty; //判断单品是否为空 if (!String.IsNullOrWhiteSpace(productText)) { t_word p_word = getWordBySynonym(productText); //判断业态是否可以查询到 if (null != p_word) { //查询到则获得bp列表 List <t_brand_product> bp_list = bpDao.getproductByBrandAndProduct(null, p_word.code); //t_brand_product有把brand_code存起来 if (bp_list.Count > 0) { foreach (t_brand_product brand_product in bp_list) { code_list.Add(brand_product.brand_code); } } //t_brand_businessformat没有就返回空列表 else { return(brandList); } } //业态查询不到就返回空列表 else { return(brandList); } } //判断楼层是否为空 if (!String.IsNullOrWhiteSpace(floorText)) { t_word f_word = getWordBySynonym(floorText); //判断楼层是否可以查询到 if (null != f_word) { floor_code = f_word.code; } //楼层查询不到就返回空列表 else { return(brandList); } } brandList = brandDao.getBrandByCondition(code_list.ToArray(), floor_code, VipFlag); if (brandList.Count >= 5) { brandList = brandList.Take(5).ToList(); } return(brandList); }
//根据业态,楼层,特约商户,查询品牌列表 public List <t_brand> GetBrandListByBusinessFormatAndFloor(String businessFormatText, String floorText, bool VipFlag) { List <t_brand> brandList = new List <t_brand>(); //品牌列表 List <String> code_list = new List <String>(); //楼层 String floor_code = String.Empty; //判断业态是否为空 if (!String.IsNullOrWhiteSpace(businessFormatText)) { t_word bf_word = getWordBySynonym(businessFormatText); //判断业态是否可以查询到 if (null != bf_word) { //查询到则获得bb列表 List <t_brand_businessformat> bb_list = bbDao.getBusinessformatByBrandAndBf(null, bf_word.code); //t_brand_businessformat有把brand_code存起来 if (bb_list.Count > 0) { foreach (t_brand_businessformat brand_businessformat in bb_list) { code_list.Add(brand_businessformat.brand_code); } } //t_brand_businessformat没有就返回空列表 else { return(brandList); } } //业态查询不到就返回空列表 else { return(brandList); } } //判断楼层是否为空 if (!String.IsNullOrWhiteSpace(floorText)) { t_word f_word = getWordBySynonym(floorText); //判断楼层是否可以查询到 if (null != f_word) { floor_code = f_word.code; } //楼层查询不到就返回空列表 else { return(brandList); } } brandList = brandDao.getBrandByCondition(code_list.ToArray(), floor_code, VipFlag); //t_brand tmp = new t_brand(); //String a = ""; //foreach (String s in code_list) //{ // a += s + "、"; //} //tmp.code = " code_list = " + a + " floor = " + floor_code + " vipflag = " + VipFlag; //brandList.Add(tmp); //取前5条 if (brandList.Count >= 5) { brandList = brandList.Take(5).ToList(); } return(brandList); }
public void test1Test() { try { BaseInfo bi = new BaseInfo(); bi.init(); SearchService ss = new SearchService(); SynonymDao synonymDao = new SynonymDao(); WordDao wordDao = new WordDao(); WordSynonymDao wsDao = new WordSynonymDao(); BrandDao brandDao = new BrandDao(); ReadFile rf = new ReadFile(); if (null != ReadFile.brandDic) { int i = 20000; foreach (Brand b in ReadFile.brandDic.Values) { Debug.WriteLine(b.ToString()); t_synonym t_synonym = new t_synonym() { code = i + "", name = b.BrandName, remark = "" }; t_word t_word = new t_word() { code = i + "", type = "品牌", name = b.BrandName, remark = "" }; t_word_synonym t_word_synonym = new t_word_synonym() { word_code = i + "", synonym_code = i + "" }; t_brand t_brand = new t_brand { code = i + "", brand = i + "", floor = ss.getWordBySynonym(b.Floor).code, contract = b.BrandCode, house_number = b.UnitNumber, vip_flag = "特约商户".Equals(b.VipFee) ? 1 : 0 }; synonymDao.add(t_synonym); wordDao.add(t_word); wsDao.add(t_word_synonym); brandDao.add(t_brand); Debug.WriteLine("添加成功"); i++; } } else { Debug.WriteLine("brandDic = null" + " ; path = " + ReadFile.path); } } catch (DbEntityValidationException ex) { Debug.WriteLine(ex.ToString()); StringBuilder errors = new StringBuilder(); IEnumerable <DbEntityValidationResult> validationResult = ex.EntityValidationErrors; foreach (DbEntityValidationResult result in validationResult) { ICollection <DbValidationError> validationError = result.ValidationErrors; foreach (DbValidationError err in validationError) { errors.Append(err.PropertyName + ":" + err.ErrorMessage + "\r\n"); } } Debug.WriteLine(errors.ToString()); //简写 //var validerr = ex.EntityValidationErrors.First().ValidationErrors.First(); //Console.WriteLine(validerr.PropertyName + ":" + validerr.ErrorMessage); } }