|
Hello all - I'm curious as to whether anyone on this forum knows of any generics "labs" that exist. Specificially, I'm looking for exercises where I need to come up with a solution and have access to an answer when I get stumped or can find out the "real" (or better) way to solve the question.
|
|
|
|
|
None that I can think of. I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi,
I have wriiten a little application that runs mainly in the background. There is a U.I. trhat can be accessed by double clicking its icon in the notification bar. The problem is when I try to restart or shut down my XP machine the application will not close. This appears to be not an issue on Windows 7 as it shutsdown fine, I suspect Vista could be ok also.
I checked the event viewer the event was to the effect The attempt to reboot PC failed. I have read a little and I added the following to my code
private int WM_QUERYENDSESSION = 0x11;<br />
<br />
protected override void WndProc(ref Message m)<br />
{<br />
if (m.Msg == WM_QUERYENDSESSION)<br />
{<br />
Application.ExitThread(); <br />
} <br />
base.WndProc(ref m); <br />
}
This works in as much as the application closes when I try to restart my machine, but the machine does not restart I have to tell to restart once more before it restarts. I feel it's almost there but I am not sure what is missing.
Help if you can, Dave.
|
|
|
|
|
I have also added : Application.Exit(); to the above code to no effect
|
|
|
|
|
I would guess that your problem is that your call to Application.ExitThread() means that the call to base.WndProc(ref m) never happens. What happens if you call the base function first?
|
|
|
|
|
Tried what you suggested. Still have the same problem, in that the app closes but seems to stop the machine from closing down until I try to restart for the 2nd time.
|
|
|
|
|
Hi,
AFAIK there is no need to override WndProc for this. Just add your handler to the SystemEvents.SessionEnding event and exit the application.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
|
Why would SessionEnding, that has exactly the purpose you're after, not work, when Microsoft has offered it since day 1 of .NET?
May i suggest, when you read some stuff, you read it carefully, all the way to the bottom.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Houdy,
I need a class that checks/validates file types.
Of course this is needed in cases where you can't trust the extension to supply that info.
I thought about Magic Numbers as an option - does anyone have an already built app - any language will do
Also if you have ideas on how to accomplish this task (like MIME etc) in a better way I am all
Surprising to see so few samples and sources for Magic Numbers on google...
Thanks a bunchTzumer
|
|
|
|
|
hi
how i can return dataset to datagriedview
My business layer is memberBL Class
My Data Access Layer Is memberDA Class
My view Dataset Code in memberDL Class is:
public DataSet View(memberBL member)
{
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;
}
How I Can return Dataset in GriedView in Form?
hoW i can use in ds IN windows FORM?
|
|
|
|
|
well that's easy. Something like:
dataGridView1.DataSource = ds.Tables[0];
|
|
|
|
|
program is layering & ds in not known in form
first ds come in business layer then view in datagried
it is not easy my dear friend
|
|
|
|
|
I'm sorry I don't understand.
what do you mean by "ds in not known in form"?
An by this "first ds come in business layer then view in datagried"?
Do you have problem returnig the dataset from your bussines layer to your UI?
|
|
|
|
|
yes
first ds to business layer then view in UI layer & form
|
|
|
|
|
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...
|
|
|
|
|
|