c# BindingList read-only error - c#

I keep trying to look for the possible cause of the problem but I cant seem to find it:
Error:
System.NotSupportedException: Collection is read-only. at
System.ThrowHelper.ThrowNotSupportedException(ExceptionResource
resource) at System.Collections.ObjectModel.Collection`1.Add(T
item) at
WindowsFormsApplication1.Form1.Btn_CSVSEATINGPLAN_Click(Object sender,
EventArgs e) in C:\Users\aRJiJon\Documents\Visual Studio
2010\Projects\WindowsFormsApplication_1\WindowsFormsApplication1\Form1.cs:line
72
this.dataGridView1.DefaultCellStyle.Font = new Font("Tahoma", 11);
bindingCSVSP.DataSource = CSV_Seating_Plan;
bindingCSVSP.AllowNew = true;
CSV_Seating_Plan.AllowNew = true;
CSV_Seating_Plan.AllowRemove = true;
CSV_Seating_Plan.RaiseListChangedEvents = true;
CSV_Seating_Plan.AllowEdit = true;
this.dataGridView1.DataSource = bindingCSVSP;
this.btn_Process_SP.Enabled = true;
CSV_Seating_Plan.Add(new csv_SeatingPlan());
public string examperiod;
[FieldConverter(ConverterKind.Date, "dd/mm/yyyy")]
public DateTime date_Exam;
public string time;
public string exam_Code;
public string id_Student;
public string name_Student;
public string candidatenum_Student;
public string seat_num;
public string _WSS_EXEC;
public string exam_loc;
#region getsetmethods.
public string EXAMPERIOD
{ get { return this.examperiod; } }
public DateTime DATE_TIME
{ get { return this.date_Exam; } }
public string TIME
{ get { return this.time; } }
public string EXAM_CODE
{ get { return this.exam_Code; } }
public string ID_STUDENT
{ get { return this.id_Student; } }
public string NAME_STUDENT
{ get { return this.name_Student; } }
public string CANDIDATE_NUMBER
{ get { return this.candidatenum_Student; } }
public string SEAT_NUM
{ get { return this.seat_num; } }
public string WSS_EXEC
{ get { return this._WSS_EXEC; } }
public string EXAM_LOC
{ get { return this.exam_loc; } }
#endregion
public csv_SeatingPlan()
{
}
Can anyone tell me what I'm missing?

This means that the underlying implementation of IList for you generic collection class is returning true for the IsReadOnly property.

Related

Invalid Column Name on Databases

Screenshot showing column & column entry
Hey all, I'm getting an error saying my column names are invalid. I know it's not the table that is wrong because it worked perfectly fine an hour ago. I tried different variations of the Id, issue, etc with no luck.
namespace Csis265.DAL
{
public class BugMapper : BaseMapper
{
public BugMapper(SqlDataReader rdr) : base(rdr)
{ }
public override object DoMapping()
{
logger.Debug("INSIDE BugMapper DoMapping() !!!");
int id = GetInteger("ID");
string issue = GetString("ISSUE");
string resolution = GetString("RESOLUTION");
int statusId = GetInteger("STATUS_ID");
int priorityId = GetInteger("PRIORITY_ID");
int softwareappId = GetInteger("SOFTWARE_APP_ID");
DateTime dateCreated = GetDateTime("DATE_CREATED");
DateTime dateResolved = GetDateTime("DATE_RESOLVED");
Bug rtnObj = new Bug(id, issue, resolution,
statusId, priorityId, softwareappId, dateCreated, dateResolved);
logger.Debug($"INSIDE BugMapper DoMapping() {rtnObj.ToString()}");
return rtnObj;
}
}
BUG CLASS - Nothing was touched besides the issue get/set. I originally had it as name instead of issue but have fixed that mistake
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using log4net;
namespace Csis265.Domain
{
public class Bug : BaseObject
{
protected string issue;
protected string resolution;
protected int statusId;
protected int priorityId;
protected int softwareappId;
protected Status status;
protected Priority priority;
protected SoftwareApp softwareapp;
public Status Status
{
get { return status; }
set { status = value; }
}
public Priority Priority
{
get { return priority; }
set { priority = value; }
}
public SoftwareApp SoftwareApp
{
get { return softwareapp; }
set { softwareapp = value; }
}
public int Id
{
get { return id; }
set { id = value; }
}
public string Issue
{
get { return issue; }
set { issue = value; }
}
public string Resolution
{
get { return resolution; }
set { resolution = value; }
}
public string StatusName
{
get { return Status.Name; }
}
public string PriorityName
{
get { return Priority.Name; }
}
public string SoftwareAppName
{
get { return SoftwareApp.Name; }
}
public Bug(int id, string issuse, string resolution,
int statusId, int priorityId, int softwareappId,
DateTime dateCreated, DateTime dateResolved) : base(id, dateCreated)
{
SetIssue(issue);
SetResolution(resolution);
SetStatusId(statusId);
SetPriorityId(priorityId);
SetSoftwareAppId(softwareappId);
}
public void SetIssue(string issue)
{
this.issue = issue;
}
private void SetSoftwareAppId(int softwareappId)
{
this.softwareappId = softwareappId;
}
private void SetPriorityId(int priorityId)
{
this.priorityId = priorityId;
}
private void SetStatusId(int statusId)
{
this.statusId = statusId;
}
private void SetResolution(string resolution)
{
this.resolution = resolution;
}
public string GetIssue()
{
return issue;
}
public override string ToString()
{
return $"BUG ID:{id} ISSUE: {issue} DTC: {dateCreated}";
}
public string GetResolution()
{
return resolution;
}
public int GetStatusId()
{
return statusId;
}
public int GetPriorityId()
{
return priorityId;
}
public int GetSoftwareAppId()
{
return softwareappId;
}
}
}
line 20..
Change
int id = GetInteger("ID'");
to
int id = GetInteger("ID"); // Without the quote

Neo4jClient Node/Relationship Class conventions

Is there a standard naming convention for the properties/methods of a node/relationship class when working with Neo4jClient?
I'm following this link Neo4jClient - Retrieving relationship from Cypher query to create my relationship class
However, there are certain properties of my relationship which i can't get any value despite the relationship having it. While debugging my code, i realized certain properties was not retrieved from the relationship when creating the relationship object.
this is my relationship class
public class Creates
{
private string _raw;
private int _sourcePort;
private string _image;
private int _DestinationPort;
private int _eventcode;
private string _name;
private string _src_ip;
private int _src_port;
private string _dvc;
private int _signature_ID;
private string _dest_ip;
private string _computer;
private string _sourceType;
private int _recordID;
private int _processID;
private DateTime _time;
private int _dest_port;
public string Raw { get { return _raw; } set { _raw = value; } }
public int SourcePort { get { return _sourcePort; } set { _sourcePort = value; } }
public string Image { get { return _image; } set { _image = value; } }
public int DestinationPort { get { return _DestinationPort; } set { _DestinationPort = value; } }
public int Eventcode { get { return _eventcode; } set { _eventcode = value; } }
public string Name { get { return _name; } set { _name = value; } }
public string Src_ip { get { return _src_ip; } set { _src_ip = value; } }
public int Src_port { get { return _src_port; } set { _src_port = value; } }
public string DVC { get { return _dvc; } set { _dvc = value; } }
public int Signature_ID { get { return _signature_ID; } set { _signature_ID = value; } }
public string Dest_ip { get { return _dest_ip; } set { _dest_ip = value; } }
public string Computer { get { return _computer; } set { _computer = value; } }
public string SourceType { get { return _sourceType; } set { _sourceType = value; } }
public int RecordID { get { return _recordID; } set { _recordID = value; } }
public int ProcessID { get { return _processID; } set { _processID = value; } }
public DateTime Indextime { get { return _time; } set { _time = value; } }
public int Dest_port { get { return _dest_port; } set { _dest_port = value; } }
}
This is another class
public class ProcessConnectedIP
{
public Neo4jClient.RelationshipInstance<Pivot> bindto { get; set; }
public Neo4jClient.Node<LogEvent> bindip { get; set; }
public Neo4jClient.RelationshipInstance<Pivot> connectto { get; set; }
public Neo4jClient.Node<LogEvent> connectip { get; set; }
}
This is my neo4jclient query to get the relationship object
public IEnumerable<ProcessConnectedIP> GetConnectedIPs(string nodeName)
{
try
{
var result =
this.client.Cypher.Match("(sourceNode:Process{name:{nameParam}})-[b:Bind_IP]->(bind:IP_Address)-[c:Connect_IP]->(connect:IP_Address)")
.WithParam("nameParam", nodeName)
.Where("b.dest_ip = c.dest_ip")
.AndWhere("c.Image=~{imageParam}")
.WithParam("imageParam", $".*" + nodeName + ".*")
.Return((b, bind, c, connect) => new ProcessConnectedIP
{
bindto = b.As<RelationshipInstance<Creates>>(),
bindip = bind.As<Node<LogEvent>>(),
connectto = c.As<RelationshipInstance<Creates>>(),
connectip = connect.As<Node<LogEvent>>()
})
.Results;
return result;
}catch(Exception ex)
{
Console.WriteLine("GetConnectedIPs: Error Msg: " + ex.Message);
return null;
}
}
This is the method to read the results
public void MyMethod(string name)
{
IEnumerable<ProcessConnectedIP> result = clientDAL.GetConnectedIPs(name);
if(result != null)
{
var results = result.ToList();
Console.WriteLine(results.Count());
foreach (ProcessConnectedIP item in results)
{
Console.WriteLine(item.Data.Src_ip);
Console.WriteLine(item.bindto.StartNodeReference.Id);
Console.WriteLine(item.bindto.EndNodeReference.Id);
Console.WriteLine(item.connectto.StartNodeReference.Id);
Console.WriteLine(item.connectto.EndNodeReference.Id);
Node<LogEvent> ans = item.bindip;
LogEvent log = ans.Data;
Console.WriteLine(log.Name);
Node<LogEvent> ans1 = item.connectip;
LogEvent log1 = ans1.Data;
Console.WriteLine(log1.Name);
}
}
}
Somehow, i'm only able to populate the relationship object with src_ip/src_port/dest_ip/dest_port values. the rest are empty.
Is there any possible reason why? I've played with upper/lower cases on the properties names but it does not seem to work.
This is the section of the graph im working with
This is the relationship properties sample:
_raw: Some XML dataSourcePort: 49767Image: C:\Windows\explorer.exeDestinationPort: 443EventCode: 3Name: Bind
IPsrc_ip: 172.10.10.104dvc: COMPUTER-NAMEsrc_port:
49767signature_id: 3dest_ip: 172.10.10.11Computer:
COMPUTRE-NAME_sourcetype:
XmlWinEventLog:Microsoft-Windows-Sysmon/OperationalRecordID:
13405621ProcessId: 7184_time: 2017-08-28T15:15:39+08:00dest_port: 443
I'm not entirely sure how your Creates class is ever populated, in particular those fields - as your Src_port property doesn't match the src_port in the sample you provided (case wise).
I think it's probably best to go back to a super simple version. Neo4jClient will map your properties to the properties in the Relationship as long as they have the same name (and it is case-sensitive).
So start with a new Creates class (and use auto properties - it'll make your life a lot easier!)
public class Creates
{
public string Computer { get; set; }
}
Run your query with that and see if you get a result, then keep on adding properties that match the name and type you expect to get back (int, string etc)
It seems that i have to give neo4j node/relationship property names in lowercase and without special characters at the start of the property name, in order for the above codes to work.
The graph was not created by me at the start thus i had to work on it with what was given. I had to get the developer who created the graph to create the nodes with lowercases in order for the above to work.

Creating two C# class definitions with a driver to test classes, but not sure why so many errors?

I am new to C# and was asked to create two class definitions (customer and order) using partial code and with the suggested class names, methods, contructors and following an example. I am not sure why I am getting so many errors when I build/debug?
After this is finished, I need to create another program that builds onto this one. Our instructor also asked us not to use validation...
Some of my most common errors are:
expected: ; (in a place in my code where I believe there should not be a semi-colon and
Error "Expected class, delegate, enum, interface, or struct.
Here is my code:
public class clsOrder
{
//declare class variables
protected string cstrDescription;
protected int cintQuantity;
protected decimal cdecPrice;
protected decimal cdecExtendedPrice;
//shared variables
static decimal cdecTotalPrice;
static int cintTotalCount;
//declare constructors
public clsOrder();
}
public clsOrde r(string strDescription,
int intQuantity, decimal decPrice)
}
//declare property methods
{
this.Description = string strDescription;
this.Quantity = int intQuantity;
this.Price = decimal decPrice;
//declare read-only properties
public decimal ExtendedPrice
}
public string Description
{
get
{
return strDescription;
}
set
{
strDescription = value;
}
}
public int Quantity
{
get
{
return intQuantity;
}
set
{
intQuantity = value;
}
}
public decimal Price
{
get
{
return decPrice;
}
set
{
decPrice = value;
}
}
get
{
return cdecExtendedPrice;
}
}
//declare Shared (static) ReadOnly Properites
public static decimal TotalPrice
{
get
{
return cdecTotalPrice;
}
}
public static int TotalCount
{
get
{
return cintTotalCount;
}
}
//declare supporting methods
public void calcExtendedPrice()
{
cdecExtendedPrice = cintQuantity * cdecPrice;
}
public void accumulateTotals()
{
cdecTotalPrice += cdecExtendedPrice;
cintTotalCount += 1;
}
public static void resetTotals()
{
cdecTotalPrice = 0;
cintTotalCount = 0;
}
}//end of Class
}//end of namespace
And
public class clsCustomer
{
//declare class variables
private string cstrName;
private string cstrStreet;
private string cstrCity;
private string cstrState;
private string cstrZip;
//declare constructors
public class clsCustomer()
}
public clsCustomer(string strName,
string strStreet, string strCity,
string strState, string strZip)
}
//declare property methods
{
this.Name = cstrName;
this.Street = cstrStreet;
this.City = cstrCity;
this.State = cstrState;
this.Zip = cstrZip;
}
public string Name
{
get
{
return cstrName;
}
set
{
cstrName = value;
}
}
public string Street
{
get
{
return cstrStreet;
}
set
{
cstrStreet = value;
}
}
public string City
{
get
{
return cstrCity;
}
set
{
cstrCity = value;
}
}
public string State
{
get
{
return cstrState;
}
set
{
cstrState = value;
}
}
public string Zip
{
get
{
return cstrZip;
}
set
{
cstringZip = value;
}
}
Any help would be very much appreciated, thank you.

Convert two classes in VB.net to C# but get object reference error

I have converted the following two classes to c# from vb.net, but get a reference error. Can someone please help or explain why it does not work in c# but does in vb.net?
Member class:
public class Member
{
#region "Fields"
private string fPiecemark;
private string fMemberType;
private string fSize;
private string fTotalWeight;
private int fSheetKey;
private string fDescription;
private string fStructType;
#endregion
private string fMemberSheetIndex;
#region "Constructors"
//Default class Constructor
public Member()
{
fPiecemark = string.Empty;
fMemberType = string.Empty;
fSize = string.Empty;
fTotalWeight = string.Empty;
fSheetKey = 0;
fStructType = string.Empty;
}
public Member(string Piecemark, string MemberType, string Description, string Size, string TotalWeight, string StructType, string MemberSheetIndex, int SheetID)
{
this.Piecemark = Piecemark;
this.MemberType = MemberType;
this.Description = Description;
this.Size = Size;
this.TotalWeight = TotalWeight;
this.StructType = StructType;
this.MemberSheetIndex = MemberSheetIndex;
this.SheetKey = SheetID;
if (!MbrSheet.mSheet.ContainsKey(SheetID))
{
MbrSheet.mSheet.Add(SheetID, new MbrSheet(SheetID));
}
MbrSheet.mSheets[SheetID].Members.Add(this);
}
#endregion
#region "Properties"
public string Piecemark
{
get { return fPiecemark; }
set { fPiecemark = value; }
}
public string MemberType
{
get { return fMemberType; }
set { fMemberType = value; }
}
public string TotalWeight
{
get { return fTotalWeight; }
set { fTotalWeight = value; }
}
public string Size
{
get { return fSize; }
set { fSize = value; }
}
public int SheetKey
{
get { return fSheetKey; }
set { fSheetKey = value; }
}
public string Description
{
get { return fDescription; }
set { fDescription = value; }
}
public string StructType
{
get { return fStructType; }
set { fStructType = value; }
}
public string MemberSheetIndex
{
get { return fMemberSheetIndex; }
set { fMemberSheetIndex = value; }
}
#endregion
}
MbrSheet class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
public class MbrSheet
{
public static Dictionary<int, MbrSheet> mSheets = new Dictionary<int, MbrSheet>();
public int mSheet { get; set; }
public List<Member> Members { get; set; }
public MbrSheet(int MbrSheet)
{
Members = new List<Member>();
this.mSheet = MbrSheet;
}
public static decimal WeightByType(string MemberType)
{
var subset = mSheets.Where(kvp => kvp.Value.Members.Where(m => m.MemberType == MemberType).Count() > 0);
decimal wbt = 0;
wbt += mSheets
.Where(kvp => kvp.Value.Members.Where(m => m.MemberType == MemberType).Count() > 0)
.Sum(kvp => kvp.Value.Members.Sum(m => Convert.ToDecimal(m.TotalWeight, CultureInfo.InvariantCulture)));
return wbt;
}
}
I get error but don't know why
An object reference is required for the non-static field, method, or property for MbrSheet.mSheet, but both worked in VB.net
if (!MbrSheet.mSheet.ContainsKey(SheetID)) // Error on !MbrSheet.mSheet
{
MbrSheet.mSheet.Add(SheetID, new MbrSheet(SheetID)); // Error on MbrSheet.mSheet
}
I think you should use this:
if (!MbrSheet.mSheets.ContainsKey(SheetID))
{
MbrSheet.mSheets.Add(SheetID, new MbrSheet(SheetID));
}
Pay attention to mSheets you are using mSheet.
You can also use tools to convert codes:
http://www.developerfusion.com/tools/convert/csharp-to-vb/
http://codeconverter.sharpdevelop.net/SnippetConverter.aspx

Binding to DataGridView Datasource property with List(Of Entity) throw a null reference exception

I tried to make a solution for it for almost 4 hours but I couldn't find any
public class FinalClassScoreModel
{
private readonly FinalClassScore _finalClassScore;
public FinalClassScoreModel(FinalClassScore finalClassScore)
{
this._finalClassScore = finalClassScore;
}
public int EnrollId
{
get
{
return this._finalClassScore.EnrollId;
}
}
public string StudentNo
{
get
{
return this._finalClassScore.Enroll.Student.StudentNo;
}
}
public string ReversedName
{
get
{
return this._finalClassScore.Enroll.Student.ReversedName;
}
}
public decimal? Prelim
{
get
{
return this._finalClassScore.Prelim;
}
}
public string PrelimE
{
get
{
return this._finalClassScore.PrelimE;
}
}
public decimal? Midterm
{
get
{
return this._finalClassScore.Midterm;
}
}
public string MidtermE
{
get
{
return this._finalClassScore.MidtermE;
}
}
public decimal? Final
{
get
{
return this._finalClassScore.Final;
}
}
public string FinalE
{
get
{
return this._finalClassScore.FinalE;
}
}
public decimal? FinalGrade
{
get
{
return this._finalClassScore.FinalGrade;
}
}
public bool IsDropped
{
get
{
return this._finalClassScore.Enroll.IsDropped;
}
}
public bool IsIncomplete
{
get
{
return this._finalClassScore.Enroll.IsIncomplete;
}
}
public bool IsGradeSubmitted
{
get
{
return this._finalClassScore.Enroll.IsGradeSubmitted;
}
}
Public Property FinalClassScoreModels() As IEnumerable(Of FinalClassScoreModel) Implements IAlternativeView.FinalClassScoreModels
Get
Return Me._finalClassScoreModels
End Get
Set(ByVal value As IEnumerable(Of FinalClassScoreModel))
If DesignMode Then Exit Property
Me._finalClassScoreModels = value
Me.dgrAlternativeGrades.DataSource = Me._finalClassScoreModels
End Set
End Property
At first it was ok but when I delete 1 data on the FinalClassScoreModelList and re-run the Me.dgrAlternativeGrades.Datasource = Me._finalClassScoreModels it will throw nullreference exception on
public string StudentNo
{
get
{
return this._finalClassScore.Enroll.Student.StudentNo;
}
}
By the way it will work with no error if i didn't set the datapropertyname of each columns on datagridview but I need to set it because i dont want to autogenerate the columns.
my project is combination of vb.net and C#
For those beginner who will also encounter this problem what I did on my FinalClassScoreModel class
public class FinalClassScoreModel
{
private readonly FinalClassScore _finalClassScore;
private readonly Enroll _enroll;
public FinalClassScoreModel(FinalClassScore finalClassScore, Enroll enroll)
{
this._finalClassScore = finalClassScore;
this._enroll = enroll;
}
public int EnrollId
{
get
{
return this._finalClassScore.EnrollId;
}
}
public string StudentNo
{
get
{
return this._enroll.StudentNo;
}
}
on this way it will just get the value ot StudentNo even if it is null or not
thanks to all

Categories

Resources