public abstract class GeneralDB : IEntity
{
protected DataTable table;
protected int currentRow;
protected string primaryKey;
public GeneralDB(string tableName, string primaryKey)
{
DAL.GetInstance().AddTable(tableName);//bring data from database
table = DAL.GetInstance().GetTable(tableName);
this.primaryKey = primaryKey;
if (IsEmpty())
currentRow = -1;
else
currentRow = 0;
}
#region NAVIGATION
/// <summary>
/// going first line
/// </summary>
public void GoToFirst()
{
if (IsEmpty())
throw new Exception("navigate on empty table");
currentRow = 0;
}
/// <summary>
/// going to last line
/// </summary>
public void GoToLast()
{
if (IsEmpty())
throw new Exception("navigate on empty table");
currentRow = table.Rows.Count - 1;
}
/// <summary>
/// go next line if in the end go back to first
/// </summary>
public void MoveNext()
{
if (IsEmpty())
throw new Exception("navigate on empty table");
currentRow = (currentRow + 1) % table.Rows.Count;
}
/// <summary>
/// moves to the previous object. If reaches the beginning, goes back
/// to the end
/// </summary>
public void MovePrev()
{
if (IsEmpty())
throw new Exception("navigate on empty table");
if (this.currentRow == 0)
currentRow = table.Rows.Count - 1;
else
--currentRow;
}
/// <summary>
/// search obj by its key
/// </summary>
/// <param name="key">the key being looked for</param>
/// <returns>true if found and false if no such row exists</returns>
public bool Find(object key)
{
int r = 0;
foreach (DataRow dr in table.Rows)
{
if (dr[primaryKey].Equals(key))
{
currentRow = r;
return true;
}
else
r++;
}
return false;
}
/// <summary>
/// return current row
/// </summary>
/// <returns>Data Row of current row</returns>
protected DataRow GetThisRow()
{
return table.Rows[currentRow];
}
#endregion
#region GENERAL OPERATIONS
/// <summary>
/// return num of lines
/// </summary>
/// <returns>number of rows</returns>
public int Size()
{
return table.Rows.Count;
}
/// <summary>
/// check if table is empty
/// </summary>
/// <returns> true if empty, false if not empty</returns>
public bool IsEmpty()
{
return table.Rows.Count == 0;
}
public virtual void Save()
{
DAL.GetInstance().Update(table.TableName);
}
#endregion
public DataRow[] Filter(string filterString)
{
if (filterString.Trim().Length == 0)
return table.Select();
return table.Select(filterString);
}
#region CRUD
public void Add(IEntity obj)
{
DataRow dr = table.NewRow();
obj.Populate(dr);
table.Rows.Add(dr);
Find(dr[primaryKey]);
}
public void UpdateRow(IEntity obj)
{
DataRow dr = GetThisRow();
obj.Populate(dr);
}
public void UpdateRowWithStock(IEntity obj)
{
obj.PopulateStock(table.Rows[currentRow]);
}
public virtual void DeleteCurrentRow()
{
string sqlString = "Delete from " + table.TableName + " where " + primaryKey + " = " + table.Rows[currentRow][primaryKey].ToString();
DAL.GetInstance().ExecuteNonQuery(sqlString);
MoveNext();
object key = table.Rows[currentRow][primaryKey];
MovePrev();
table.Rows.Remove(GetThisRow());
if (!Find(key))
currentRow = -1;
}
#endregion
public abstract object GetCurrentRow();
public string GetNameType() { return table.TableName; }
public abstract void Populate(DataRow dr);
}
}
Я хотел бы знать, как исправить эту ошибку beacuse написания этого разве помогает: он говорит мне, чтобы добавить этот общественный недействительный populatestock (DataRow Dr) в generaldb и я не понимаю, что я должен написать там ....
это дает мне ошибку в этой строке: " throw new NotImplementedException(); "
и его рассказывающее меня то, что: "The method or operation is not implemented."
Ошибка t 1 «MatankProj.DB.GeneralDB» не реализует интерфейс члена «MatankProj.Entities.IEntity.PopulateStock (System.Data.DataRow)»
в любом случае может кто-нибудь помочь мне справиться с этой ошибкой:
" Error1 'MatankProj.DB.GeneralDB' does not implement interface
member'MatankProj.Entities.IEntity.PopulateStock(System.Data.DataRow)' "
спасибо, что согласился, но после того, как я сел за купель часов, чтобы решить проблему, я нашел проблему и исправил ее .... и я не использовал: public void PopulateStock (System.Data.DataRow dataRow) { throw new NotImplementedException(); } Я сделал что-то похожее на заполнение и в основном решил это так спасибо, я действительно ценю это tnx – user3629336