|
I got that from your anteriour posts.
But what is your problem? Passing data from the BLogic to the UI
or just the UI part?
[EDIT]
OK suppose that your UI is in the MyUI namespace.
The BussinessLayer is in the MyLogic namespace.
in order to populate your UI with data do something like this inside a click event for example:
private void btn1_Click(object sender, EventArgs null){
dataGridView1.DataSource = MyLogic.MemberBL.GetDataSet().Tables[0];
}
Just like d@nish said if on a different project/dll just add a reference to it.
|
|
|
|
|
my business layer is:
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
<br />
namespace Library_Project<br />
{<br />
class memberBL<br />
{<br />
private String membercode;<br />
private String name;<br />
private String family;<br />
private String shsh;<br />
private String melicode;<br />
private String tavalod;<br />
private String shoghl;<br />
private String tel;<br />
private String mobile;<br />
private String adr;<br />
private String trkhozv;<br />
<br />
private memberDA memberData;<br />
<br />
public memberBL() <br />
{<br />
<br />
<br />
memberData = new memberDA();<br />
<br />
}<br />
public String DatasetData<br />
{<br />
get<br />
{<br />
return this.DatasetData;<br />
}<br />
set<br />
{<br />
this.DatasetData = value;<br />
<br />
<br />
}<br />
}<br />
public String Membercode<br />
{<br />
get<br />
{<br />
return this.membercode;<br />
}<br />
set<br />
{<br />
this.membercode = value;<br />
<br />
<br />
}<br />
}<br />
<br />
public String Name <br />
{<br />
<br />
get<br />
{<br />
return this.name;<br />
}<br />
set<br />
{<br />
try<br />
{<br />
this.name = value;<br />
<br />
if (this.name == "")<br />
{<br />
throw new Exception(<br />
"لطفا نام عضو را وارد نمایید");<br />
}<br />
}<br />
catch(Exception e)<br />
{<br />
throw new Exception(e.Message.ToString());<br />
}<br />
}<br />
}<br />
<br />
public String Familly<br />
{<br />
get<br />
{<br />
return this.family;<br />
}<br />
set<br />
{<br />
this.family = value;<br />
if (this.family == "")<br />
{<br />
throw new Exception("لطفا نام خانوادگی عضو رو وارد نمایید");<br />
}<br />
<br />
}<br />
}<br />
<br />
public String Shsh<br />
{<br />
get<br />
{<br />
return this.shsh;<br />
}<br />
set<br />
{<br />
this.shsh = value;<br />
<br />
if (this.shsh == "")<br />
{<br />
throw new Exception("لطفا شماره شناسنامه را وارد نمایید");<br />
}<br />
}<br />
}<br />
public String Melicode<br />
{<br />
get<br />
{<br />
return this.melicode;<br />
}<br />
set<br />
{<br />
this.melicode = value;<br />
if (this.melicode == "")<br />
{<br />
throw new Exception("لطفا کد ملی عضو رو وارد نمایید");<br />
}<br />
<br />
}<br />
}<br />
public String Tavalod<br />
{<br />
get<br />
{<br />
return this.tavalod;<br />
}<br />
set<br />
{<br />
this.tavalod = value;<br />
<br />
if (this.tavalod == "")<br />
{<br />
throw new Exception("لطفا تاریخ تولد رو وارد نمایید");<br />
}<br />
}<br />
}<br />
<br />
<br />
public String Shoghl<br />
{<br />
get<br />
{<br />
return this.shoghl;<br />
}<br />
set<br />
{<br />
this.shoghl = value;<br />
if (this.shoghl == "")<br />
{<br />
throw new Exception("لطفا شغل رو انتخاب کنید");<br />
}<br />
<br />
}<br />
}<br />
public String Tel<br />
{<br />
get<br />
{<br />
return this.tel;<br />
}<br />
set<br />
{<br />
this.tel = value;<br />
if (this.tel == "")<br />
{<br />
throw new Exception("لطفا شماره تلفن را وارد نمایید ");<br />
}<br />
<br />
}<br />
}<br />
public String Mobile<br />
{<br />
get<br />
{<br />
return this.mobile;<br />
}<br />
set<br />
{<br />
this.mobile = value;<br />
if (this.mobile == "")<br />
{<br />
throw new Exception("لطفا شماره موبایل را وارد نمایید ");<br />
}<br />
<br />
}<br />
}<br />
public String Adr<br />
{<br />
get<br />
{<br />
return this.adr;<br />
}<br />
set<br />
{<br />
this.adr = value;<br />
if (this.adr == "")<br />
{<br />
throw new Exception("لطفا آدرس را وارد نمایید");<br />
}<br />
<br />
}<br />
}<br />
public String Trkhozv<br />
{<br />
get<br />
{<br />
return this.trkhozv;<br />
}<br />
set<br />
{<br />
this.trkhozv = value;<br />
<br />
<br />
}<br />
}<br />
public void Add()<br />
{<br />
memberData.Add(this);<br />
}<br />
<br />
<br />
public void Update()<br />
{<br />
memberData.Update(this);<br />
}<br />
<br />
<br />
}<br />
}
My data Layer IS :
using System;
using System.Data.OleDb;
using System.Data;
using System.Text;
namespace Library_Project
{
class memberDA
{
private OleDbConnection cnn;
private const string CnnStr =
"Provider=Microsoft.Jet.OLEDB.4.0;Data " +
"Source= D:\\Data\\Library.mdb;";
private String strTable="";
private String strFields="";
private String strValues="";
private String insertStr="";
private const String thisTable = "tblmembers";
private const String member_code = "membercode";
private const String member_name = "name";
private const String member_family = "family";
private const String member_shsh = "shsh";
private const String member_melicode = "melicode";
private const String member_tavalod = "tavalod";
private const String member_shoghl = "shoghl";
private const String member_tel = "tel";
private const String member_mobile = "mobile";
private const String member_adr = "adr";
private const String member_trkhozv = "trkhozv";
private memberBL memberLogic;
public memberDA()
{
}
public memberDA(memberBL member)
{
memberLogic = new memberBL();
}
public void Add(memberBL member)
{
String str = BuildAddString(member);
OpenCnn();
OleDbCommand cmd = new OleDbCommand(str,cnn);
cmd.ExecuteNonQuery();
CloseCnn();
}
public void Update(memberBL member)
{
OpenCnn();
String selectStr = "UPDATE " + thisTable +
" set " + member_name + " = '" + member.Name + "'" +
", " + member_family + " = '" + member.Familly + "'" +
", " + member_shsh + " = '" + member.Shsh + "'" +
", " + member_melicode + " = '" + member.Melicode + "'" +
", " + member_tavalod + " = '" + member.Tavalod + "'" +
", " + member_shoghl + " = '" + member.Shoghl + "'" +
", " + member_tel + " = '" + member.Tel + "'" +
", " + member_mobile + " = '" + member.Mobile + "'" +
", " + member_adr + " = '" + member.Adr + "'" +
" where member_code = '" + member.Membercode + "'";
OleDbCommand cmd = new OleDbCommand(selectStr,cnn);
cmd.ExecuteNonQuery();
CloseCnn();
}
public DataSet Find(String argStr)
{
DataSet ds=null;
try
{
OpenCnn();
String selectStr = "select * from " + thisTable +
" where member_code = '" + argStr + "'";
OleDbDataAdapter da =
new OleDbDataAdapter(selectStr,cnn);
ds = new DataSet();
da.Fill(ds,thisTable);
CloseCnn();
}
catch(Exception e)
{
String Str = e.Message;
}
return ds;
}
public DataSet View()
{
DataSet ds = null;
try
{
OpenCnn();
String selectStr = "select * from " + thisTable + "'";
OleDbDataAdapter da =new OleDbDataAdapter(selectStr, cnn);
ds = new DataSet();
da.Fill(ds, thisTable);
CloseCnn();
}
catch (Exception e)
{
String Str = e.Message;
}
return ds;
}
private void OpenCnn()
{
String cnnStr = CnnStr;
cnn = new OleDbConnection(cnnStr);
cnn.Open();
}
private void CloseCnn()
{
cnn.Close();
}
private String BuildAddString(memberBL member)
{
strTable="Insert into " + thisTable;
strFields = " (" + member_code +
"," + member_name +
"," + member_family +
"," + member_shsh +
"," + member_melicode +
"," + member_tavalod +
"," + member_shoghl +
"," + member_tel +
"," + member_mobile +
"," + member_adr +
"," + member_trkhozv + ")";
strValues = " Values ( '" + member.Membercode +
"' , '" + member.Name +
"' , '" + member.Familly +
"' , '" + member.Shsh +
"' , '" + member.Melicode +
"' , '" + member.Tavalod +
"' , '" + member.Shoghl +
"' , '" + member.Tel +
"' , '" + member.Mobile +
"' , '" + member.Adr +
"' , '" + member.Trkhozv + "' )";
insertStr = strTable + strFields + strValues;
return insertStr;
}
}
}
HOW Return ds to Form?
|
|
|
|
|
Somthing like this:
public DataSet GetDatas(){
return memberData.View();
}
LibraryProject.MemberBL bl = new LibraryProject.MemberBL();
dataGridView1.DataSource = bl.GetDatas().Tables[0];
[Edit]Fixed pre tags[/EDIT]modified on Sunday, February 21, 2010 10:58 PM
|
|
|
|
|
If everything is in same project, create an instance of your BL class and then call the method which returns the dataset.
If BL is in separate project, add a reference to that project in your UI project and then do the same.
|
|
|
|
|
My Business Lyaer Is:
using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Text;
using System.Data;
namespace Library_Project
{
class memberBL
{
private String membercode;
private String name;
private String family;
private String shsh;
private String melicode;
private String tavalod;
private String shoghl;
private String tel;
private String mobile;
private String adr;
private String trkhozv;
private memberDA memberData;
public memberBL()
{
memberData = new memberDA();
}
public String Membercode
{
get
{
return this.membercode;
}
set
{
this.membercode = value;
}
}
public String Name
{
get
{
return this.name;
}
set
{
try
{
this.name = value;
if (this.name == "")
{
throw new Exception(
"لطفا نام عضو را وارد نمایید");
}
}
catch(Exception e)
{
throw new Exception(e.Message.ToString());
}
}
}
public String Familly
{
get
{
return this.family;
}
set
{
this.family = value;
if (this.family == "")
{
throw new Exception("لطفا نام خانوادگی عضو رو وارد نمایید");
}
}
}
public String Shsh
{
get
{
return this.shsh;
}
set
{
this.shsh = value;
if (this.shsh == "")
{
throw new Exception("لطفا شماره شناسنامه را وارد نمایید");
}
}
}
public String Melicode
{
get
{
return this.melicode;
}
set
{
this.melicode = value;
if (this.melicode == "")
{
throw new Exception("لطفا کد ملی عضو رو وارد نمایید");
}
}
}
public String Tavalod
{
get
{
return this.tavalod;
}
set
{
this.tavalod = value;
if (this.tavalod == "")
{
throw new Exception("لطفا تاریخ تولد رو وارد نمایید");
}
}
}
public String Shoghl
{
get
{
return this.shoghl;
}
set
{
this.shoghl = value;
if (this.shoghl == "")
{
throw new Exception("لطفا شغل رو انتخاب کنید");
}
}
}
public String Tel
{
get
{
return this.tel;
}
set
{
this.tel = value;
if (this.tel == "")
{
throw new Exception("لطفا شماره تلفن را وارد نمایید ");
}
}
}
public String Mobile
{
get
{
return this.mobile;
}
set
{
this.mobile = value;
if (this.mobile == "")
{
throw new Exception("لطفا شماره موبایل را وارد نمایید ");
}
}
}
public String Adr
{
get
{
return this.adr;
}
set
{
this.adr = value;
if (this.adr == "")
{
throw new Exception("لطفا آدرس را وارد نمایید");
}
}
}
public String Trkhozv
{
get
{
return this.trkhozv;
}
set
{
this.trkhozv = value;
}
}
public void Add()
{
memberData.Add(this);
}
public void Update()
{
memberData.Update(this);
}
}
}
& My Data Layer Is:
using System;
using System.Data.OleDb;
using System.Data;
using System.Text;
namespace Library_Project
{
class memberDA
{
private OleDbConnection cnn;
private const string CnnStr =
"Provider=Microsoft.Jet.OLEDB.4.0;Data " +
"Source= D:\\Data\\Library.mdb;";
private String strTable="";
private String strFields="";
private String strValues="";
private String insertStr="";
private const String thisTable = "tblmembers";
private const String member_code = "membercode";
private const String member_name = "name";
private const String member_family = "family";
private const String member_shsh = "shsh";
private const String member_melicode = "melicode";
private const String member_tavalod = "tavalod";
private const String member_shoghl = "shoghl";
private const String member_tel = "tel";
private const String member_mobile = "mobile";
private const String member_adr = "adr";
private const String member_trkhozv = "trkhozv";
private memberBL memberLogic;
public memberDA()
{
}
public memberDA(memberBL member)
{
memberLogic = new memberBL();
}
public void Add(memberBL member)
{
String str = BuildAddString(member);
OpenCnn();
OleDbCommand cmd = new OleDbCommand(str,cnn);
cmd.ExecuteNonQuery();
CloseCnn();
}
public void Update(memberBL member)
{
OpenCnn();
String selectStr = "UPDATE " + thisTable +
" set " + member_name + " = '" + member.Name + "'" +
", " + member_family + " = '" + member.Familly + "'" +
", " + member_shsh + " = '" + member.Shsh + "'" +
", " + member_melicode + " = '" + member.Melicode + "'" +
", " + member_tavalod + " = '" + member.Tavalod + "'" +
", " + member_shoghl + " = '" + member.Shoghl + "'" +
", " + member_tel + " = '" + member.Tel + "'" +
", " + member_mobile + " = '" + member.Mobile + "'" +
", " + member_adr + " = '" + member.Adr + "'" +
" where member_code = '" + member.Membercode + "'";
OleDbCommand cmd = new OleDbCommand(selectStr,cnn);
cmd.ExecuteNonQuery();
CloseCnn();
}
public DataSet Find(String argStr)
{
DataSet ds=null;
try
{
OpenCnn();
String selectStr = "select * from " + thisTable +
" where member_code = '" + argStr + "'";
OleDbDataAdapter da =
new OleDbDataAdapter(selectStr,cnn);
ds = new DataSet();
da.Fill(ds,thisTable);
CloseCnn();
}
catch(Exception e)
{
String Str = e.Message;
}
return ds;
}
public DataSet View()
{
DataSet ds = null;
try
{
OpenCnn();
String selectStr = "select * from " + thisTable + "'";
OleDbDataAdapter da =new OleDbDataAdapter(selectStr, cnn);
ds = new DataSet();
da.Fill(ds, thisTable);
CloseCnn();
}
catch (Exception e)
{
String Str = e.Message;
}
return ds;
}
private void OpenCnn()
{
String cnnStr = CnnStr;
cnn = new OleDbConnection(cnnStr);
cnn.Open();
}
private void CloseCnn()
{
cnn.Close();
}
private String BuildAddString(memberBL member)
{
strTable="Insert into " + thisTable;
strFields = " (" + member_code +
"," + member_name +
"," + member_family +
"," + member_shsh +
"," + member_melicode +
"," + member_tavalod +
"," + member_shoghl +
"," + member_tel +
"," + member_mobile +
"," + member_adr +
"," + member_trkhozv + ")";
strValues = " Values ( '" + member.Membercode +
"' , '" + member.Name +
"' , '" + member.Familly +
"' , '" + member.Shsh +
"' , '" + member.Melicode +
"' , '" + member.Tavalod +
"' , '" + member.Shoghl +
"' , '" + member.Tel +
"' , '" + member.Mobile +
"' , '" + member.Adr +
"' , '" + member.Trkhozv + "' )";
insertStr = strTable + strFields + strValues;
return insertStr;
}
}
}
How ds trasnsfer to Business Layer & Then View in formmodified on Sunday, February 21, 2010 9:44 AM
|
|
|
|
|
How ds trasnsfer to Business Layer & Then View in form?
BUSINESS LAYER & DATA LAYER CODE IS above
|
|
|
|
|
I am trying to convert some code to .net framework 2.0 from .net framework 3.0.
the code of .net framework 3.5 is:
if (mItems.Exists(b => string.Compare(b.FileName, item.FileName, StringComparison.OrdinalIgnoreCase) == 0))
return;
It can run in .net framework 3.5 and can not run in .net framework 2.0.
Could someone tell me where the defferent things between 3.5 from 2.0 in the code are.
|
|
|
|
|
Lambda expressions were introduced in .Net 3.0. This should be enough:
if (mItems.Exists(string.Compare(b.FileName, item.FileName, StringComparison.OrdinalIgnoreCase) == 0))
return;
|
|
|
|
|
Thanks!
There is another problem. The parameter "b" whose type as same as parameter "item" is not defined.
And the parameter "b" have not defined anywhere. I try to change the name of parameter "b" to "a",it also could run. I am puzzled about this.
|
|
|
|
|
"The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. "
So b (and a) are your input parameters.Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
Thanks!
I have googled the lambda operator specifies and research it.There are some differences in syntax.
In .net 2.0, it need use delegate to define a virtual method instead of the lambda expressions.
Thank you.
|
|
|
|
|
That expression means that A variable "b" would be sent and the expression on the right side of "=>" would be executed on it. Now, you can see through your code and modify it accordingly. You can have a separate method that takes a variable of same type as "b" and returns the result or can declare the variable in the current method/class and use it.
If you are using VS2008, you can set the target framework as 2.0 and the original code should work.
|
|
|
|
|
Thanks!
I just back from a business trip. I have googled the lambda operator specifies and research it.There are some differences in syntax.
In .net 2.0, it need use delegate to define a virtual method instead of the lambda expressions.
Thank you.
|
|
|
|
|
But you can use C# 3 with .NET 2.0
|
|
|
|
|
Yes, I can.
I just want to konw why I could not debug the code successed in .net 2.0.
|
|
|
|
|
In that line of code, there shouldn't be any differences.
Lambda expressions compile to the same IL as anonymous methods in C# 2.0; it shouldn't be the problem.
The "Exists" method already was present for List<T> in .NET 2.0, so I don't see why your code would not run on .NET 2.0.
Generally, if you use the C# 3.0 compiler without setting any references on .NET 3.x assemblies (e.g. System.Core), the resulting binary will run on .NET 2.0.
What does "it can not run" mean? Do you get an exception? What is the error message?
|
|
|
|
|
Thanks!
I just back from a business trip. I have googled the lambda operator specifies and research it.There are some differences in syntax.
In .net 2.0, it need use delegate to define a virtual method instead of the lambda expressions.
"it can not run", I said, means that, I could not debug the code in .net 2.0. And I just want to konw why it was happened.
Thank you.
|
|
|
|
|
Why can't we just right click, insert > picture??
Why doesn't it work?? I simply get nothing when I do that!!
If you're familiar with this problem, can you shed some light on how to set it at runtime from a path in the hard disk rather than from a database field.. Probably as a parameter or whatever way it works.
Thanks!
|
|
|
|
|
Hi ,
Is there any good tools to create a good framework(Busines Logic and Datalayer) from a database ?
With Warm Regards...
|
|
|
|
|
|
MyGeneration[^] can be used to generate sourcecode that's based on a database-structure I are Troll
|
|
|
|
|
I have a datagrid that is being populated correctly. yet only the first row shows in the grid. I have a second row that shows nothing. However, if i click on the second row then I see the data. Is there some kinda setting I'm missing in properties or is it something else?
|
|
|
|
|
Hi,
can I know your data source contains only two rows?
Also, check and set the different color for 'BackColor' and 'ForeColor' properties of DefaultCellStyle in DataGrid.
Thanks,Gopal.S
|
|
|
|
|
Hi, I'm having problems in casting object to List<Game>, Game is another class. I'm using Reflection to invoke the method, however my method return a List, but the invokeMethod in Reflection returns me an object.
object returnType;
List<Game> gameList = (List<Game>)returnType;
When i tried to do this casting, it gives InvalidCastException. I've used, getType to check they are of the same type of list, however it cannot works. When i tried to compare them, i.e returnType.GetType().Equals(gameList.getType()), they are different.
Thanks for any help/suggestion. I've tried to search but failed to find any help.
|
|
|
|
|
What happens when you do GetType().ToString()? It could be that the object is null... not sure if that would cause trouble, but maybe. Also, if the types are defined in different assemblies, that may cause problems too (e.g., if the type you are casting to is defined in a different assembly than the type stored in the object). Perhaps you can create a simplified example of code we can run that demonstrates the problem?
|
|
|
|
|