|
Reverse the changes you made.
Then change your function implementation from
private void ReserveOrCancelSeat(SeatManager.DisplayOptions choice) into
private void ReserveOrCancelSeat()
If you want to improve your knowledge of functions read the tutorial[^].
0100000101101110011001000111001011101001
|
|
|
|
|
you have to provide us with the members of the SeatManager.DisplayOptions enum to help you choose one of them as a parameter to you function
as example if your SeatManager.DisplayOptionsenum is
<pre lang="C#">
enum SeatManager.DisplayOptionsenum
{
choice1
choice2
choice3
choice4
}
</pre>
you can call your function like this
<pre lang="C#">
private void btnOK_Click(object sender, EventArgs e)
{
ReserveOrCancelSeat( SeatManager.DisplayOptionsenum.choice1); // here comes the error message
}
</pre>
|
|
|
|
|
Thank you that helpt alot!
|
|
|
|
|
Well. I have done a small project.
But the problem is some of my required data is not available across whole project.
I mean, every time I go form to form I need to open the database and fill the same data from the same SqlDataAdapter.
Instead is it possible to keep the data somewhere globally for all the project forms?
With my project I have a class for the queries and tables and wherever I need data in the forms, there I use to call the Subs for filling the table like the below...
Class1.cs
=========
public void MyTableFill()
{
Con.ConnectionString = Con_1;
Con.Open();
SQLDAp = new SqlDataAdapter(MyQry, Con);
SQLDAp.Fill(MyTable);
Con.Close();
}
Form1.cs
========
Class1 MyDatas = new Class1();
Form1_Load()
{
MyDatas.MyTableFill();
}
Form2.cs
========
Class1 AccDatas=new Class1();
Form2_Load()
{
AccDatas.MyTableFill();
}
Thanks
|
|
|
|
|
|
I keep a static class that hold all the lists that support dimension data (typically stuff for comboboxes), every form uses this for static data. When the get accessor is called it checks for content and if there is none it gets the data from the database.
If the app changes the static data then the list is set to null. Next time it is requested the data is refreshed from the database. This does not work well for asynch processing (Silverlight);
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
The data access should not be in the UI layer at all. Have a separate class that encapsulates the data access and pass a reference to an instance of it to each form.
|
|
|
|
|
the best way is to create a global class and retrieve information from the database and store it in that class, and when any form needs that data it reads it from the global class
|
|
|
|
|
Use layered approach (tier). In your case three tier approach is suitable: DAL–Data Access Layer, BLL–Business Logic Layer and GUI –Graphical User Interface.
|
|
|
|
|
Dear Fellows,
I have only this question that can some one show me the sample of Inventory Database software in a form of images because I don't seen this software before so I got task its not a project its just a assignment for me so I don't know where to start how this inventory database software looks like how many labels, text boxes, what features are in main menu etc etc so can some one guide me???
Any help or assistance will be appreciated.
thanks
================================================
be happy always and also keep other happy as well...
================================================
|
|
|
|
|
How this software would look depends on what it would need to do.
So you first would need to write down its functional requirements.
If you want some samples of similar software use Google[^] and browse the links given.
0100000101101110011001000111001011101001
|
|
|
|
|
We have already explained to you here[^] that this question is too broad to be answered in these forums. There is no standard Supermarket Software that can be given to you; you need to design it based on the requirements of your Supermarket. If you really do not understand how to design a database then either you are on the wrong study course or in the wrong job.
|
|
|
|
|
Enable or disable controls inside the groupbox based on the checkbox state. If checkbox is unchecked and the groupbox and all controls inside are hidden. For a tri-state checkbox in immediate state, all controls inside are just disabled.
|
|
|
|
|
This is a follow-up question to: [^] posted in the C# Q/A Forum.
Why not post this question in C# Q/A forum, as well ?
"Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye." Miss Piggy"
|
|
|
|
|
I have this sample data. Right now it is defined in a seperate C# file like this:
public class SampleData
{
public static ObservableCollection<Product> GetSampleData()
{
ObservableCollection<Product> teams = new ObservableCollection<Product>();
}
}
and I load the obsevableCollection inside GetSampleData().
It works and I am able to get the sample data anywhere in my program.
But how can I redesign this code so that I can create the sample data on the fly from outside the class?
|
|
|
|
|
0. 'as is' the code shown here will not work: your definition of 'GetSampleData' is supposed to return an ObservableCollection<product>, and it does not.
1. Why not make the Class 'static' as well ? As the code is now, the Class will have to be instantiated with 'new'
2. please explain more clearly exactly what you mean by "get the sample data on the fly from outside the class." You mean from a database ?
Would something like this work for you:
public static class SampleData
{
public static ObservableCollection<Product> teams = new ObservableCollection<Product>();
public static void GetSampleData()
{
// code here to access a database or whatever to fill the teams<Product> collection
}
}
In this type of access-model, once you have called 'GetSampleData,' and filled the 'teams' global static variable, you can access it from anywhere in your project by: SampleData.teams
Note: since you are using ObservableCollection, my guess is your intent is to make use of PropertyChanged and/or CollectionChanged facilties: I have not thought through the implications of making a static ObservableCollection.
There's a great new article here on CP about ObservableCollection I recommend you see: Enhanced ObservableCollection with ability to delay or disable notifications[^]
best, Bill
"Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye." Miss Piggy"
|
|
|
|
|
Dear friends I have simple experience programming with C#,but new to deal with graph data structure. when I got some examples from MSDN which is the following
I face this error message Error
'WindowsApplication4.Graph<t> does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()
'WindowsApplication4.Graph<l>GetEnumerator()' is either static, not public, or has the wrong return type.
and I had changed the return data type to all possible type and the error still the same please help me to overcome this problem.
#region Using directives
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
#endregion
namespace WindowsApplication4
{
public class Graph<T> : IEnumerable<T>
{
#region Private Member Variables
private NodeList<T> nodeSet;
#endregion
#region Constructors
public Graph() : this(null) { }
public Graph(NodeList<T> nodeSet)
{
if (nodeSet == null)
this.nodeSet = new NodeList<T>();
else
this.nodeSet = nodeSet;
}
#endregion
#region Methods
#region Add
#region AddNode
#region IEnumerable<T> Members
public IEnumerator<T> GetEnumerator()
{
foreach (GraphNode<T> gnode in nodeSet)
yield return gnode.Value;
}
#endregion
public void AddNode(GraphNode<T> node)
{
nodeSet.Add(node);
}
public void AddNode(T value)
{
nodeSet.Add(new GraphNode<T>(value));
}
#endregion
#region Add*Edge Methods
public void AddDirectedEdge(T from, T to)
{
AddDirectedEdge(from, to, 0);
}
public void AddDirectedEdge(GraphNode<T> from, GraphNode<T> to)
{
AddDirectedEdge(from, to, 0);
}
public void AddDirectedEdge(GraphNode<T> from, GraphNode<T> to, int cost)
{
from.Neighbors.Add(to);
from.Costs.Add(cost);
}
public void AddDirectedEdge(T from, T to, int cost)
{
((GraphNode<T>)nodeSet.FindByValue(from)).Neighbors.Add(nodeSet.FindByValue(to));
((GraphNode<T>)nodeSet.FindByValue(from)).Costs.Add(cost);
}
public void AddUndirectedEdge(T from, T to)
{
AddUndirectedEdge(from, to, 0);
}
public void AddUndirectedEdge(GraphNode<T> from, GraphNode<T> to)
{
AddUndirectedEdge(from, to, 0);
}
public void AddUndirectedEdge(GraphNode<T> from, GraphNode<T> to, int cost)
{
from.Neighbors.Add(to);
from.Costs.Add(cost);
to.Neighbors.Add(from);
to.Costs.Add(cost);
}
public void AddUndirectedEdge(T from, T to, int cost)
{
((GraphNode<T>)nodeSet.FindByValue(from)).Neighbors.Add(nodeSet.FindByValue(to));
((GraphNode<T>)nodeSet.FindByValue(from)).Costs.Add(cost);
((GraphNode<T>)nodeSet.FindByValue(to)).Neighbors.Add(nodeSet.FindByValue(from));
((GraphNode<T>)nodeSet.FindByValue(to)).Costs.Add(cost);
}
#endregion
#endregion
#region Clear
public void Clear()
{
nodeSet.Clear();
}
#endregion
#region Contains
public bool Contains(T value)
{
return nodeSet.FindByValue(value) != null;
}
#endregion
#region Remove
public bool Remove(T value)
{
GraphNode<T> nodeToRemove = (GraphNode<T>)nodeSet.FindByValue(value);
if (nodeToRemove == null)
return false;
nodeSet.Remove(nodeToRemove);
foreach (GraphNode<T> gnode in nodeSet)
{
int index = gnode.Neighbors.IndexOf(nodeToRemove);
if (index != -1)
{
gnode.Neighbors.RemoveAt(index);
gnode.Costs.RemoveAt(index);
}
}
return true;
}
#endregion
#endregion
#region Public Properties
public NodeList<T> Nodes
{
get
{
return nodeSet;
}
}
public int Count
{
get { return nodeSet.Count; }
}
#endregion
}
}
|
|
|
|
|
Didn't look at everything, but IEnumerable<T>.GetEnumerator() is supposed to return a class of something that implements IEnumerator<T>. Its not supposed to return your object. IEnumerator<T> implements methods to do that.
|
|
|
|
|
From a quick scan of your code, it looks like you know that both IEnumerable<t> and IEnumerable() interfaces must both be implemented, but you have your non-generic 'GetEnumerator() commented out: why ?
The other thing that 'jumps out' from the code is that while 'Graph implements IEnumerable, you don't seem to be taking advantage that an instance of 'Graph is inherently a List.
To really help with this, I think we'd need to know how and where you implement 'GraphNode and 'NodeList.
Have you googled on this error message, and looked on StackOverFlow, as well as CP, for similar questions ?
best, Bill
"Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye." Miss Piggy"
|
|
|
|
|
The short answer to this is that IEnumerable<T> also mandates that you implement IEnumerable, which requires a method of signature
IEnumerator GetEnumerator()
Fortunately IEnumerator<T> similarly mandates IEnumerator, so you can fulfil this contract with an explicit interface implementation:
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
(If you need to write an enumerator yourself, there's a similar issue with the Current property in IEnumerator<T> and IEnumerator, and a similar fix to return the same value but cast to object.)
However, as already pointed out, your graph is essentially wrapping a NodeList, and that already implements IEnumerable<T>. Instead of making an intermediate iterator, why not just forward the interface methods directly to the inner list?
IEnumerator<T> IEnumerable<T>.GetEnumerator() { return nodeList.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
(I've done both as explicit for symmetry and because you shouldn't be calling GetEnumerator directly; only one of them needs to be explicit.)
|
|
|
|
|
Dear Sir,
I had tried your kind suggestion ,but unfortunately faild as shown below.please could you help me by making the changes on the following code segment and returned it to me “I’m very sorry to bother you………”
Error 3 foreach statement cannot operate on variables of type 'WindowsApplication4.NodeList<t>' because 'WindowsApplication4.NodeList<t>' does not contain a public definition for 'GetEnumerator'
namespace WindowsApplication4
{
///
/// Represents a graph. A graph is an arbitrary collection of GraphNode
instances.
///
/// <typeparam name="T">The type of data stored in the graph's
nodes.
public class Graph<t> : IEnumerable<t>
{
#region Private Member Variables
private NodeList<t> nodeSet; // the set of nodes in the graph
#endregion
#region Constructors
public Graph() : this(null) { }
public Graph(NodeList<t> nodeSet)
{
if (nodeSet == null)
this.nodeSet = new NodeList<t>();
else
this.nodeSet = nodeSet;
}
#endregion
#region Methods
#region Add
#region AddNode
///
/// Adds a new GraphNode instance to the Graph
///
/// <param name="node" />The GraphNode instance to add.
///
#region IEnumerable<t> Members
///
/// Returns an enumerator that allows for iterating through the
contents of the graph.
public IEnumerator<t> GetEnumerator()
{
foreach (GraphNode<t> gnode in nodeSet)
yield return gnode.Value;
}
#endregion
////////////////////////////////////////////////////////////
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
public void AddNode(GraphNode<t> node)
{
// adds a node to the graph
nodeSet.Add(node);
}
///
/// Adds a new value to the graph.
///
/// <param name="value" />The value to add to the graph
public void AddNode(T value)
{
nodeSet.Add(new GraphNode<t>(value));
}
#endregion
#region Add*Edge Methods
///
/// Adds a directed edge from a GraphNode with one value (from) to a GraphNode with another value (to).
///
/// <param name="from" />The value of the GraphNode from which the directed edge eminates.
/// <param name="to" />The value of the GraphNode to which the edge leads.
public void AddDirectedEdge(T from, T to)
{
AddDirectedEdge(from, to, 0);
}
and if I Changed it to public like this
public IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
Error 1 The modifier 'public' is not valid for this item
|
|
|
|
|
I assumed that NodeList inherited from List<T>. If it is a custom class, firstly, it probably shouldn't be (it is a list, it should be a List<Node<T>> unless there's a good reason for it not to be), and secondly, it must itself implement IEnumerable<T> as you are trying to foreach over it in the GetEnumerator method.
|
|
|
|
|
Dear BobJanova,
Agian sorry to bother you,
I would like to inform your highness I'm using
Visual Studio 2005 C# and Vista home Basic edition OS ,if they have some effects.
|
|
|
|
|
Hello experts,
even though I tried to create a minimal code sample, this question needs rather large code samples attached. Don't worry, all the interesting text is here, above all the code.
An application has to serialize data to a file and to de-serialize from that file. This works like a charm. The working example is attached in the first two code samples.
Now for the interesting part: the original working version is delivered to millions of satisfied customers. All their positive feedback encouraged the creation of version 2. Version 2 should of course be able to load data files from version 1. It is possible to change the data model without breaking compatibility, to some extend at least using ObsoleteAttribute and OptionalFieldAttribute . But when changes get more fundamental, other approaches are to be researched.
The third code sample shows an altered <cdoe>DataContainer class. In this example, it has to serialize one field that is not present in the original version. Therefore the well-known loading process fails.
To recover from the exception, another assembly is loaded. In my test case, it's the original assembly. It's delivered within the version 2 project resources.
The original assembly should load the legacy file. But it throws a TargetInvocationException instead. Its inner exception tells us that DataContainer has three members while there are only two de-serialized.
Now where does this legacy assembly know of DataContainer having three members nowadays?
It should have called its integrated version of DataContainer , which then had two members and therefore should load the legacy file without moaning.
However, here is the "minimal" working sample:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Test_Serialization_Versioning_Heavy
{
public partial class Form1 : Form
{
#region Declarations
string _filename = string.Empty;
DataContainer _dataContainer = new DataContainer();
#endregion
#region Init
public Form1()
{
_filename = System.IO.Path.Combine(Application.StartupPath, "datafile.xml");
InitializeComponent();
ShowData();
}
#endregion
#region User Interaction
private void btLoad_Click(object sender, EventArgs e)
{
_dataContainer = DataContainer.LoadDataContainter(_filename);
ShowData();
}
private void btSave_Click(object sender, EventArgs e)
{
_dataContainer.Save(_filename);
}
#endregion
private void ShowData()
{
pgData.SelectedObject = _dataContainer;
}
#region Vom Windows Form-Designer generierter Code
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.tlpMain = new System.Windows.Forms.TableLayoutPanel();
this.btLoad = new System.Windows.Forms.Button();
this.btSave = new System.Windows.Forms.Button();
this.pgData = new System.Windows.Forms.PropertyGrid();
this.tlpMain.SuspendLayout();
this.SuspendLayout();
this.tlpMain.ColumnCount = 3;
this.tlpMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 96F));
this.tlpMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 96F));
this.tlpMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tlpMain.Controls.Add(this.btLoad, 0, 0);
this.tlpMain.Controls.Add(this.btSave, 1, 0);
this.tlpMain.Controls.Add(this.pgData, 0, 1);
this.tlpMain.Dock = System.Windows.Forms.DockStyle.Fill;
this.tlpMain.Location = new System.Drawing.Point(0, 0);
this.tlpMain.Name = "tlpMain";
this.tlpMain.RowCount = 2;
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 35F));
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tlpMain.Size = new System.Drawing.Size(386, 392);
this.tlpMain.TabIndex = 0;
this.btLoad.Anchor = System.Windows.Forms.AnchorStyles.None;
this.btLoad.Location = new System.Drawing.Point(10, 6);
this.btLoad.Name = "btLoad";
this.btLoad.Size = new System.Drawing.Size(75, 23);
this.btLoad.TabIndex = 0;
this.btLoad.Text = "Load";
this.btLoad.UseVisualStyleBackColor = true;
this.btLoad.Click += new System.EventHandler(this.btLoad_Click);
this.btSave.Anchor = System.Windows.Forms.AnchorStyles.None;
this.btSave.Location = new System.Drawing.Point(106, 6);
this.btSave.Name = "btSave";
this.btSave.Size = new System.Drawing.Size(75, 23);
this.btSave.TabIndex = 1;
this.btSave.Text = "Save";
this.btSave.UseVisualStyleBackColor = true;
this.btSave.Click += new System.EventHandler(this.btSave_Click);
this.tlpMain.SetColumnSpan(this.pgData, 3);
this.pgData.Dock = System.Windows.Forms.DockStyle.Fill;
this.pgData.Location = new System.Drawing.Point(3, 38);
this.pgData.Name = "pgData";
this.pgData.Size = new System.Drawing.Size(380, 351);
this.pgData.TabIndex = 2;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(386, 392);
this.Controls.Add(this.tlpMain);
this.Name = "Form1";
this.Text = "Form1";
this.tlpMain.ResumeLayout(false);
this.ResumeLayout(false);
}
private System.Windows.Forms.TableLayoutPanel tlpMain;
private System.Windows.Forms.Button btLoad;
private System.Windows.Forms.Button btSave;
private System.Windows.Forms.PropertyGrid pgData;
#endregion
}
} The original DataContainer class
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
namespace Test_Serialization_Versioning_Heavy
{
[Serializable]
public class DataContainer
{
#region Declarations
private string _name = "NoName";
private int _someNumber = 3;
#endregion
#region Information Disclosure
public string Name
{
get { return (_name); }
set { _name = value; }
}
public int SomeNumber
{
get { return (_someNumber); }
set { _someNumber = value; }
}
#endregion
#region Actions
public void Save(string path)
{
using (
System.IO.Stream writeStream = new System.IO.FileStream(
path,
System.IO.FileMode.OpenOrCreate
)
)
{
IFormatter formatter = new Formatters.Soap.SoapFormatter();
formatter.Serialize(writeStream, this);
}
}
public static DataContainer LoadDataContainter(string path)
{
using (System.IO.Stream readStream = new System.IO.FileStream(path, System.IO.FileMode.Open))
{
IFormatter formatter = new Formatters.Soap.SoapFormatter();
return ((DataContainer)(formatter.Deserialize(readStream)));
}
}
#endregion
}
} After updating
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
namespace Test_Serialization_Versioning_Heavy
{
[Serializable]
public class DataContainer
{
#region Declarations
private string _name = "NoName";
private int _someNumber = 3;
private double _newDouble = 5.2;
#endregion
#region Information Disclosure
public string Name
{
get { return (_name); }
set { _name = value; }
}
public int SomeNumber
{
get { return (_someNumber); }
set { _someNumber = value; }
}
public double NewDouble
{
get { return (_newDouble); }
set { _newDouble = value; }
}
#endregion
#region Actions
public void Save(string path)
{
using (
System.IO.Stream writeStream = new System.IO.FileStream(
path,
System.IO.FileMode.OpenOrCreate
)
)
{
IFormatter formatter = new Formatters.Soap.SoapFormatter();
formatter.Serialize(writeStream, this);
}
}
public static DataContainer LoadDataContainter(string path)
{
try
{
using (
System.IO.Stream readStream = new System.IO.FileStream(
path,
System.IO.FileMode.Open
)
)
{
IFormatter formatter = new Formatters.Soap.SoapFormatter();
return ((DataContainer)(formatter.Deserialize(readStream)));
}
}
catch (Exception ex)
{
System.Reflection.Assembly legacyAssembly = System.Reflection.Assembly.Load(Properties.Resources.LegacyAssemblyV1_0_0_0);
Type[] legacyTypes = legacyAssembly.GetTypes();
Type legacyProjectType = legacyAssembly.GetType("Test_Serialization_Versioning_Heavy.DataContainer");
object legacyProjectObject = legacyProjectType.InvokeMember(
"LoadDataContainter",
System.Reflection.BindingFlags.Public
| System.Reflection.BindingFlags.Static
| System.Reflection.BindingFlags.InvokeMethod,
null, null,
new object[] { path }
);
return (null);
}
}
#endregion
}
}
Ciao,
luker
|
|
|
|
|
|