init
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,10 @@
|
||||
namespace DatabaseExport
|
||||
{
|
||||
public class DbOperationsEnum
|
||||
{
|
||||
public enum StoredProcedure
|
||||
{
|
||||
sp_DbVersionGet,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
public class DbVersion
|
||||
{
|
||||
public DbVersion(System.Data.DataRow dr)
|
||||
{
|
||||
_version = Convert.ToInt32(dr["Version"]);
|
||||
_step = Convert.ToInt32(dr["Step"]);
|
||||
_date = Convert.ToDateTime(dr["Date"]);
|
||||
_remarks = (string)dr["Remarks"];
|
||||
_userField = (string)dr["UserField"];
|
||||
}
|
||||
private int _version;
|
||||
|
||||
public int Version
|
||||
{
|
||||
get => _version;
|
||||
set => _version = value;
|
||||
}
|
||||
|
||||
private int _step;
|
||||
public int Step
|
||||
{
|
||||
get => _step;
|
||||
set => _step = value;
|
||||
}
|
||||
|
||||
private DateTime _date;
|
||||
public DateTime Date
|
||||
{
|
||||
get => _date;
|
||||
set => _date = value;
|
||||
}
|
||||
|
||||
private string _remarks;
|
||||
public string Remarks
|
||||
{
|
||||
get => _remarks;
|
||||
set => _remarks = value;
|
||||
}
|
||||
|
||||
private string _userField;
|
||||
public string UserField
|
||||
{
|
||||
get => _userField;
|
||||
set => _userField = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
public abstract class DbTimeStampBase : IDbTimeStampAware, INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected bool SetProperty<T>(ref T storage, T value, String propertyName = null)
|
||||
{
|
||||
if (Equals(storage, value)) return false;
|
||||
|
||||
storage = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
protected void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
var eventHandler = PropertyChanged;
|
||||
if (eventHandler != null)
|
||||
{
|
||||
eventHandler(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
|
||||
protected long DbTimeStamp;
|
||||
public long GetTimeStampMemory()
|
||||
{
|
||||
return DbTimeStamp;
|
||||
}
|
||||
public void SetTimeStampMemory(long value) { DbTimeStamp = value; }
|
||||
public void SetTimeStampMemory(System.Data.DataRow row)
|
||||
{
|
||||
DbTimeStamp = 0;
|
||||
}
|
||||
|
||||
public void SetTimeStampMemory(IDataReader reader)
|
||||
{
|
||||
DbTimeStamp = 0;
|
||||
}
|
||||
public long GetTimeStampDb(Dictionary<string, long> lookup)
|
||||
{
|
||||
//var constraints = GetConstraints();
|
||||
return 0; //lookup.ContainsKey(constraints[0].DbValue.ToString()) ? lookup[constraints[0].DbValue.ToString()] : GetTimeStampDb();
|
||||
}
|
||||
|
||||
public Dictionary<string, long> GetAllTimeStampDb()
|
||||
{
|
||||
var lookup = new Dictionary<string, long>();
|
||||
return lookup;
|
||||
//try
|
||||
//{
|
||||
// var constraints = GetConstraints();
|
||||
// if (1 == constraints.Length)
|
||||
// {
|
||||
// using (var cmd = DbOperations.GetSQLCommand())
|
||||
// {
|
||||
// cmd.CommandText = string.Format("SELECT [{0}], DbTimeStamp from {1}", constraints[0].ColumnName, LookupTable);
|
||||
// using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
// {
|
||||
// foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
|
||||
// {
|
||||
// var s = Convert.ToString(dr[constraints[0].ColumnName]);
|
||||
// if (DBNull.Value.Equals(dr["DbTimeStamp"])) { continue; }
|
||||
// var res = BitConverter.ToInt64((dr["DbTimeStamp"] as byte[]), 0);
|
||||
// lookup[s] = res;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//catch (Exception ex) { APILogger.Log(ex); }
|
||||
//return lookup;
|
||||
}
|
||||
public long GetTimeStampDb()
|
||||
{
|
||||
return 0;
|
||||
//using (var sql = DbOperations.GetSQLCommand())
|
||||
//{
|
||||
// var sb = new StringBuilder(50);
|
||||
// sb.AppendFormat("SELECT DbTimeStamp as A FROM {0} ", LookupTable);
|
||||
|
||||
// var constraints = GetConstraints();
|
||||
// for (var i = 0; i < constraints.Length; i++)
|
||||
// {
|
||||
// sb.Append(0 == i ? "WHERE " : " AND ");
|
||||
// sb.AppendFormat("{0}=@{1}", constraints[i].ColumnName, i);
|
||||
// DbOperations.CreateParam(sql, string.Format("@{0}", i), constraints[i].DbType, constraints[i].DbValue);
|
||||
// }
|
||||
// sql.CommandText = sb.ToString();
|
||||
// using (var ds = DbOperations.Connection.QueryDataSet(sql))
|
||||
// {
|
||||
// if (ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0) return 0;
|
||||
// if (DBNull.Value.Equals(ds.Tables[0].Rows[0]["A"])) return 0;
|
||||
// try
|
||||
// {
|
||||
// var res = BitConverter.ToInt64(ds.Tables[0].Rows[0]["A"] as byte[], 0);
|
||||
// System.Diagnostics.Trace.WriteLine(string.Format("Db: {0}", res));
|
||||
// return res;
|
||||
// }
|
||||
// catch (Exception ex) { APILogger.Log(ex); return 0; }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
public abstract string LookupTable
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public class ConstraintHelper
|
||||
{
|
||||
public string ColumnName { get; set; }
|
||||
public System.Data.SqlDbType DbType { get; set; }
|
||||
public object DbValue { get; set; }
|
||||
}
|
||||
|
||||
public abstract ConstraintHelper[] GetConstraints();
|
||||
|
||||
public bool IsNotInDb()
|
||||
{
|
||||
return GetTimeStampDb() == 0;
|
||||
}
|
||||
|
||||
public bool IsOutOfDate()
|
||||
{
|
||||
var db = GetTimeStampDb();
|
||||
var mem = GetTimeStampMemory();
|
||||
//if there's no record in the db, don't mark as out of date
|
||||
if (db == 0) { return false; }
|
||||
//if is in db, but in memory is new, allow overwrite...
|
||||
if (mem == 0 && db != 0) { mem = db; SetTimeStampMemory(db); }
|
||||
return db != mem;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IDbTimeStampAware
|
||||
{
|
||||
long GetTimeStampMemory();
|
||||
void SetTimeStampMemory(long value);
|
||||
long GetTimeStampDb();
|
||||
bool IsOutOfDate();
|
||||
}
|
||||
public class DbItemOutOfDateException : Exception
|
||||
{
|
||||
public DbItemOutOfDateException(string msg)
|
||||
: base(msg)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user