public void DeleteData(string ObjectName, SyncData Data) { using (SqlConnection Conn = new SqlConnection(_ConnString)) { string strSql = "delete from TAB_Sync_Store_Data where ObjectName=@ObjectName and [Key]=@Key"; SqlParameter[] sqlParams = new SqlParameter[] { new SqlParameter("ObjectName", ObjectName), new SqlParameter("Key", Data.Key) }; TF.DB.DBUtility.SqlHelper.ExecuteNonQuery(Conn, CommandType.Text, strSql, sqlParams); } }
public void AddUserIndex(SyncObject Obj, SyncData Data, int OP) { using (SqlConnection Conn = new SqlConnection(_ConnString)) { string strSql = "insert into TAB_Sync_User_Data (UserID,ObjectName,[Key],Op,UpdateTime) (select UserID,@ObjectName,@Key,@Op,getdate() from TAB_Sync_User where ObjectName=@ObjectName)"; SqlParameter[] sqlParams = new SqlParameter[] { new SqlParameter("ObjectName", Obj.ObjectName), new SqlParameter("Key", Data.Key), new SqlParameter("OP", OP) }; TF.DB.DBUtility.SqlHelper.ExecuteNonQuery(Conn, CommandType.Text, strSql, sqlParams); } }
public void AddData(string ObjectName, SyncData Data) { using (SqlConnection Conn = new SqlConnection(_ConnString)) { string strSql = "insert into TAB_Sync_Store_Data (ObjectName,[Key],Json,[Version],UpdateTime) values (@ObjectName,@Key,@Json,@Version,getdate())"; SqlParameter[] sqlParams = new SqlParameter[] { new SqlParameter("ObjectName", ObjectName), new SqlParameter("Key", Data.Key), new SqlParameter("Json", Data.Json), new SqlParameter("Version", Data.Version), }; TF.DB.DBUtility.SqlHelper.ExecuteNonQuery(Conn, CommandType.Text, strSql, sqlParams); } }
public void UpdateData(string ObjectName, SyncData Data) { using (SqlConnection Conn = new SqlConnection(_ConnString)) { string strSql = "update TAB_Sync_Store_Data set Json=@Json,[Version]=@Version,UpdateTime=getdate() where ObjectName=@ObjectName and [Key]=@Key"; SqlParameter[] sqlParams = new SqlParameter[] { new SqlParameter("ObjectName", ObjectName), new SqlParameter("Key", Data.Key), new SqlParameter("Json", Data.Json), new SqlParameter("Version", Data.Version) }; TF.DB.DBUtility.SqlHelper.ExecuteNonQuery(Conn, CommandType.Text, strSql, sqlParams); } }
public void GetDataList(string ObjectName, List <SyncData> DataList) { using (SqlConnection Conn = new SqlConnection(_ConnString)) { string strSql = "select * from TAB_Org_User order by UserNumber"; SqlParameter[] sqlParams = new SqlParameter[] { }; DataTable dt = TF.DB.DBUtility.SqlHelper.ExecuteDataset(Conn, CommandType.Text, strSql, sqlParams).Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { SyncData d = new SyncData(); d.Key = dt.Rows[i]["UserNumber"].ToString(); d.Json = GetUserDataJson(Conn, d.Key); d.Version = SyncTool.MD5Encrypt16(d.Json); DataList.Add(d); } } }
public bool GetObjectData(string ObjectName, string Key, SyncData Data) { using (SqlConnection Conn = new SqlConnection(_ConnString)) { string strSql = "select * from TAB_Sync_Store_Data where ObjectName = @ObjectName"; SqlParameter[] sqlParams = new SqlParameter[] { new SqlParameter("ObjectName", ObjectName) }; DataTable dt = TF.DB.DBUtility.SqlHelper.ExecuteDataset(Conn, CommandType.Text, strSql, sqlParams).Tables[0]; if (dt.Rows.Count > 0) { Data.Json = dt.Rows[0]["Json"].ToString(); Data.Key = dt.Rows[0]["Key"].ToString(); Data.Version = dt.Rows[0]["Version"].ToString(); return(true); } } return(false); }
public static void Update(string ObjectName, ISyncSource SourceUtils, ISyncStore StoreUtils) { SyncObject sourceObject = new SyncObject(); if (!SourceUtils.GetObject(ObjectName, sourceObject)) { throw new NullReferenceException("目标数据源无此对象:" + ObjectName); } SyncObject storeObject = new SyncObject(); if (!StoreUtils.GetObject(ObjectName, storeObject)) { storeObject.ObjectName = ObjectName; storeObject.ObjectVersion = ""; } if (sourceObject.ObjectVersion == storeObject.ObjectVersion) { //比对版本,一致则退出 return; } //加载本地数据信息 List <SyncDataOP> storeDataList = new List <SyncDataOP>(); StoreUtils.GetObjectDatas(ObjectName, storeDataList); List <SyncData> sourceDataList = new List <SyncData>(); SourceUtils.GetDataList(ObjectName, sourceDataList); //遍历数据源索引 foreach (var item in sourceDataList) { //本地仓储无数据则条件索引 if (!storeDataList.Exists((SyncDataOP s) => s.Key == item.Key)) { SyncDataOP dop = new SyncDataOP(); dop.Key = item.Key; dop.Json = item.Json; dop.Version = item.Version; dop.OP = 1; storeDataList.Add(dop); } else { //已有不同则更新 if (storeDataList.Find((SyncDataOP s) => s.Key == item.Key).Version != item.Version) { storeDataList.Find((SyncDataOP s) => s.Key == item.Key).Version = item.Version; storeDataList.Find((SyncDataOP s) => s.Key == item.Key).Json = item.Json; storeDataList.Find((SyncDataOP s) => s.Key == item.Key).OP = 2; } } } //判断本地仓储是否有删除的 foreach (var item in storeDataList) { if (!sourceDataList.Exists((SyncData s) => s.Key == item.Key)) { item.OP = 3; } } //保存本地存储索引信息 foreach (var item in storeDataList) { SyncData d = new SyncData(); d.Key = item.Key; d.Json = item.Json; d.Version = item.Version; if (item.OP == 0) { continue; } if (item.OP == 1) { StoreUtils.AddData(storeObject.ObjectName, d); } if (item.OP == 2) { StoreUtils.UpdateData(storeObject.ObjectName, d); } if (item.OP == 3) { StoreUtils.DeleteData(storeObject.ObjectName, d); } StoreUtils.AddUserIndex(storeObject, d, item.OP); } //保存本地对象版本信息 if (storeObject.ObjectVersion == "") { storeObject.ObjectVersion = sourceObject.ObjectVersion; StoreUtils.AddObject(storeObject); } else { storeObject.ObjectVersion = sourceObject.ObjectVersion; StoreUtils.UpdateObject(storeObject); } }