|
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?
|
|
|
|
|
Different assemblies! oh i compiled my code to a .DLL library. I'll load that assembly and run during runtime. However, inside the project I have forgotten to add that .DLL. Is that what is causing the problem? how do i add in the assembly to my project?
|
|
|
|
|
[A]System.Collections.Generic.List`1[AutomatedTestDriver.Game] cannot be cast to [B]System.Collections.Generic.List`1[AutomatedTestDriver.Game]. Type A originates from 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll'. Type B originates from 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll'.
This is the exception it throws me
|
|
|
|
|
Create a simple example and perhaps I can assist you further. I've never tried it, but I'm pretty sure you are supposed to load the DLL using Reflection, and then you are supposed to get the type from that loaded assembly. But I'd need to see some simplified example of what you are doing to know for sure what's going on.
|
|
|
|
|
Hi guys,
I have question about a code-behind in C# for an ASPX file.
the thing is that I made a class and I want this class to inherit from System.Web.UI.Page.
but it seems that this refrence does not exist.the only thing that exists is System.Web!!!!
so if anybody could help me I'll appreciate it.
thanks
|
|
|
|