Error 1 'MatankProj.DB.GeneralDB' does not implement interface member 'MatankProj.Entities.IEntity.PopulateStock(System.Data.DataRow)'

StackOverflow https://stackoverflow.com/questions/23646108

  •  22-07-2023
  •  | 
  •  

Question

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);
}
}

I would like to know how to fix this error beacuse writing this isnt helping: it tells me to add this public void populatestock(datarow dr) in generaldb and i dont understand what should i write in there....
it gives me an error in this line: " throw new NotImplementedException(); "
and its telling me that: "The method or operation is not implemented."

anyway can anyone help me dealing with this error:

" Error1 'MatankProj.DB.GeneralDB' does not implement interface  
  member'MatankProj.Entities.IEntity.PopulateStock(System.Data.DataRow)' "
Was it helpful?

Solution

First, you should consult the documentantion of the Interface MatankProj.Entities.IEntity. There you should be able to gather information, what intention implementing PopulateStock(System.Data.Row) has. Second, you have talked about Visual Studio (I assume) giving you the error throw new NotImplementedException();. In fact, this is not an error. You seem to be trying to auto-implement the missing member by clicking something like Implement members from IEntity. Then Visual Studio always does something like this:

public void PopulateStock(System.Data.DataRow dataRow)
{
    throw new NotImplementedException();
}

...because VS wants you to replace throw new NotImplementedException(); by your own code.

Since you said that it "is telling you" The method or operation is not implemented., the method is executed at least once, hence you should take care of this. If you are able to find another implementation of MatankProj.Entities.IEntity, have a look at that implementation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top