private void Button_Click(object sender, RoutedEventArgs e) { DAL.T_FGJHtmlDataDal Dti = new DAL.T_FGJHtmlDataDal(); var Alltfg = Dti.LoadEntities(x => x.delflag != 1 || x.delflag == null).DefaultIfEmpty(); var c = Alltfg.Count(); var t = Alltfg.GroupBy(x => new { x.photo, x.FwMianji }).Where(g => g.Count() > 1); var tc = t.Count(); var ttc = t.Count(); int i = 0; foreach (var a in t) { var temp1 = Dti.LoadEntities(x => x.photo == a.Key.photo).FirstOrDefault(); if (temp1 != null) { var del1 = Dti.LoadEntities(x => x.photo == a.Key.photo).DefaultIfEmpty(); DateTime dt = del1.Max(x => x.FbTime); foreach (var d in del1) { if (d.FbTime != dt) { d.delflag = 1; Dti.EditEntity(d); } } } i++; } Dti.SaveChanges(); }
private void SaveDataHTML(oaEntities ctx, List <newWORD.Class1> L_Class_, int p) { DAL.T_FGJHtmlDataDal Dti = new DAL.T_FGJHtmlDataDal(); foreach (var da in L_Class_) { T_FGJHtmlData tf = new T_FGJHtmlData(); tf.HLName = da.TextName; tf.HLhref = da.href; tf.PersonName = da.PersonName; tf.Address = da.Address; tf.photo = da.photo; tf.FbTime = da.FbTime; tf.FbTime = tf.FbTime > DateTime.Now ? new DateTime(2017, tf.FbTime.Month, tf.FbTime.Day, tf.FbTime.Hour, tf.FbTime.Minute, tf.FbTime.Second):tf.FbTime; if (da.FwSumMoney == null) { continue; } else { if (da.FwSumMoney.Trim().Length <= 0) { continue; } } tf.FwSumMoney = da.FwSumMoney; tf.FwHuXing = da.FwHuXing; tf.FwMianji = da.FwMianji; tf.FwLoucheng = da.FwLoucheng; tf.FwZhuangxiu = da.FwZhuangxiu; tf.FwNianxian = da.FwNianxian; tf.FwChaoxiang = da.FwChaoxiang; tf.bak = da.bak; tf.Id_count = int.Parse(da.Id_count == null ? "0" : da.Id_count); tf.Laiyuan = da.Laiyuan; tf.Image_str = da.Image_str; tf.CityID = p; if (da.FwMianji != null) { tf.MianjiID = GeiMinji(da.FwMianji); tf.Pingmi_int = GetPingmi_int(da.FwMianji); } if (da.FwSumMoney != null) { tf.SumMoneyID = GetMoney(da.FwSumMoney); tf.Money_int = GetMoney_int(da.FwSumMoney); } if (da.FwHuXing != null) { tf.HuXingID = GetHuxing(da.FwHuXing); } //如果数据库中出现该名称并且 时间在当前时间那么 该信息不写入数据库 //如果有该数据那么修改数据库中的数据信息 var isnull = Dti.LoadEntities(x => x.FwMianji == tf.FwMianji && x.photo == tf.photo).DefaultIfEmpty(); if (isnull.ToList()[0] != null) { var tm = isnull.Max(x => x.FbTime); var vtm = isnull.Where(x => x.FbTime == tm).First(); vtm.FbTime = tf.FbTime; vtm.Money_int = tf.Money_int; vtm.FwSumMoney = tf.FwSumMoney; vtm.SumMoneyID = tf.SumMoneyID; Dti.EditEntity(vtm); } else { Dti.AddEntity(tf); } } Dti.SaveChanges(); }