public bool AddData(yjfk Entity) { using (var db = Connection) { string id = Entity.id; if (string.IsNullOrEmpty(id)) { Entity.id = Guid.NewGuid().ToString(); db.Insert <yjfk>(Entity); } else { string executeSql = @"select * from yjfk a where a.id='" + id + "'"; //占位符 yjfk d = db.DbConnecttion.Query <yjfk>(executeSql, null).FirstOrDefault(); if (d != null) { DeepCopyHelper.CloneObject(Entity, ref d); db.Update <yjfk>(d); } else { db.Insert <yjfk>(Entity); } } return(true); } }
public bool AddFile(attach Entity, string Name, string fileName) { using (var db = Connection) { string Sql = string.Format("select * from attach a where a.yw_id='{0}'and tp_name='{1}'", Entity.yw_id, fileName); attach d = db.DbConnecttion.Query <attach>(Sql).FirstOrDefault(); if (d == null) { //string sql = string.Format("delete from MH_ATTACH where MH_BUSINESS_ID='{0}'", d.MH_BUSINESS_ID); //db.DbConnecttion.Execute(sql); string id = Entity.yw_id; Entity.id = Guid.NewGuid().ToString(); Entity.creater = Name; db.Insert <attach>(Entity); //找不到改数据就插入 } else { Entity.MODIFIER = Name; //否则就修改 Entity.MODIFY_TIME = DateTime.Now; DeepCopyHelper.CloneObject(Entity, ref d); db.Update <attach>(d); } return(true); } }