|
Read a C# book.
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...
|
|
|
|
|
|
hi.
Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
|
|
|
|
|
I believe I'm going about this the wrong way and was wondering if there is an easier way to do this. It just appears to be a lot of functions to call for what I would assume would be a simple process.
Here is a break down of what I'm trying to accomplish:
see db diagram
I want to simply make an Insert_Update functionality when the save button is pressed on a linq to sql c# winform application. I have the insert working per say but I don't think it is the correct way to do it so I'm wondering if there is a better method than doing all the checks separately and calling db.submit() multiple times.
private void saveToolStripButton_Click(object sender, EventArgs e)
{
CheckAuthor(authorFirstTextBox.Text, authorLastTextBox.Text);
}
public void CheckAuthor(String FirstName, String LastName)
{
using (var db = new momdbDataContext())
{
try
{
StatusLabel.Text = "Adding Item to database";
List<Author> authorList = new List<Author>();
bool exist = db.Authors.Any(a => a.AuthorFirst == FirstName && a.AuthorLast == LastName);
if (exist)
CheckBookExist_ADD();
else
{
Author authorInsert = new Author { AuthorFirst = authorFirstTextBox.Text, AuthorLast = authorLastTextBox.Text };
authorList.Add(authorInsert);
db.Authors.InsertAllOnSubmit(authorList);
db.SubmitChanges();
Debug.WriteLine(db.Log);
CheckBookExist_ADD();
}
}
catch (Exception oops)
{
MessageBox.Show(oops.ToString());
}
}
}
public void CheckBookExist_ADD()
{
using (var db = new momdbDataContext())
{
var originalBook = db.Books.Where(t => t.Title == this.titleTextBox.ToString()).FirstOrDefault();
List<Book> bookList = new List<Book>();
bool exist = db.Books.Any(b => b.Title == this.titleTextBox.Text);
if (exist)
{
AddBookNumber(originalBook.ID);
var AuthorID = (from a in db.Authors
select a.ID).Max();
CheckBookAuthor(originalBook.ID, AuthorID);
}
else
{
Book bookInsert = new Book
{
Title = this.titleTextBox.Text,
Keywords = keywordsTextBox.Text,
Price = Convert.ToDecimal(priceTextBox.Text),
Retired = retiredCheckBox.Checked
};
bookList.Add(bookInsert);
db.Books.InsertAllOnSubmit(bookList);
db.SubmitChanges();
var bookID = (from b in db.Books
select b.ID).Max();
var AuthorID = (from a in db.Authors
select a.ID).Max();
CheckBookAuthor(bookID, AuthorID);
}
}
}
public void AddBookNumber(int ID)
{
using (var db = new momdbDataContext())
{
var max_Surrogate = (from sn in db.BookNumbers
select sn.SurrogateNumber).Max();
List<BookNumber> bookNumberList = new List<BookNumber>();
BookNumber booknumberInsert = new BookNumber { BookID = ID, SurrogateNumber = max_Surrogate + 1 };
bookNumberList.Add(booknumberInsert);
db.BookNumbers.InsertAllOnSubmit(bookNumberList);
db.SubmitChanges();
}
}
public void CheckBookAuthor(int bid, int aid)
{
using (var db = new momdbDataContext())
{
List<BookAuthor> bookAuthorList = new List<BookAuthor>();
bool exist = db.BookAuthors.Any(a => a.BookID == bid && a.AuthorID == aid);
if (exist)
return;
else
{
BookAuthor bookauthorInsert = new BookAuthor { AuthorID = aid, BookID = bid };
bookAuthorList.Add(bookauthorInsert);
db.BookAuthors.InsertAllOnSubmit(bookAuthorList);
db.SubmitChanges();
}
StatusLabel.Text = "Add Complete";
LoadData();
}
}
Please keep in mind that I'm learning this stuff so please don't bash me too hard. Thanks...
modified on Wednesday, February 3, 2010 4:18 PM
|
|
|
|
|
Post the relevant bit of code you have questions about, and be sure to use the pre tags, no one is going to link outside to look at it.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi All,
I have created a form and placed an image on its back ground. Now the form controls take much time to load.
Is there any way by which we can do this thing quickly.
thanks
Syed Shahid Hussain
|
|
|
|
|
Pick one:
1) Don't put an image on it's background.
2) If you must, then make it a small one.
3) Don't load the image until all the controls are loaded.
4) Get a faster machine.
All those who believe in psycho kinesis, raise my hand.
My 's gonna unleash hell on your ass. tastic!
|
|
|
|
|
I want to give a background image that is very necessary but in vb application it is working very fast but in c# it takes too much time.
I'm using core 2Dou 2.0 GHz.
Syed Shahid Hussain
|
|
|
|
|
Then that has to be (pretty much) down to differences in your code, doesn't it? Since VB and C# both use the same .NET framework and runtime, there has to be a significant difference between the two programs.
What are you doing in the C# that you aren't in the VB?
All those who believe in psycho kinesis, raise my hand.
My 's gonna unleash hell on your ass. tastic!
|
|
|
|
|
sorry I was talking about VB6. It its loading speed is too fast.
And I want to develop an on screen key board. Do u also have any idea about that? Thanks
Syed Shahid Hussain
|
|
|
|
|
CodeProject holds a couple of articles on virtual keyboards. I suggest you search and read them.
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. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
VB6 I can't help with - I bailed out of VB around Version 2 - but I assume VB6 is native code rather than .NET? If so, then I would expect it to load a lot faster, as there is no large framework to worry about. C# need the framework, so will load slower.
Having said that, just how many controls do you have? And what size/format is the image?
It may be worth just loading the app without the image and seeing if that speeds up the load enough. If it doesn't then I suspect you may have to go the "put-up-a-splash-screen-so-no-one-notices-it-is-so-slow" route that Adobe tried...
See Lucs' answer re the virtual keyboard.
All those who believe in psycho kinesis, raise my hand.
My 's gonna unleash hell on your ass. tastic!
|
|
|
|
|
Thanks a lot Friend
Syed Shahid Hussain
|
|
|
|
|
Pleased I have small problem about controls and class.
I have my new Winform class with a single label in my project and I want to write information in this label in another non GUI class I don't know how I can proceed
Exemple:
public partial class Form1:Form
{
privata Server serv = new Server(); //Form1 has-a Server
....
}
This is my non UI class
public class Server
{
public Server(){}
}
|
|
|
|
|
This is considered rude here.
"No matter how many fish in the sea; it will be so empty without me." - From song "Without me" by Eminem
|
|
|
|
|
Ok imagine you create a new Winform whit a single label.
And you add a new class named Server for example.
You want to write a simple hello word in the label but this time via your new class which reside in a single file.
|
|
|
|
|
which part of "Don't repost the same question" don't you understand? you will be blacklisted!
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. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Pleased I have small problem about controls and class.
I have my new Winform class with a single label in my project and I want to write information in this label in another non GUI class I don't know how I can proceed
Exemple:
public partial class Form1:Form
{
privata Server serv = new Server(); //Form1 has-a Server
....
}
This is my non UI class
public class Server
{
public Server(){}
}
|
|
|
|
|
Hi,
best is to use a delegate for this, and provide an event.
this[^] explains it.
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. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
This is basic object oriented programming!
Expose a property or method in the Server class that allows you set the value from the label.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Don't repost the same question Remove the second one before someone answers and you can't remove it.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi all
I have a big issue with threading in Windows Forms.
For example:
I have a .NET 2.0 (VS 2008) Windows Forms Solution
with one form in it (as default Form1).
I make this Form1 as MdiContainer.
In the Load Event I create a new thread and after this I
load a new Windows Form as Mdi Child.
In the thread I just read about 1mio rows in a DataTable
using standard DataReader.
Now because I have created a new thread, I would expect
the load time of this large amount of data would not affect
the loaded form, but it does ...
After starting the application, I grab the child form and I
just move it arround the Container form and it allways
hangs for some time ...
When I reduce the amount of data to just some rows,
the form feels free.
Here I send you my code and I would be very very happy
for a solution of this problem !
Thanks and best regards
Frank Uray
private static bool StopThread = false;
private void Form1_Load(object sender, EventArgs e)
{
System.Threading.Thread local_Thread = new System.Threading.Thread(RunThread);
local_Thread.Start();
System.Windows.Forms.Form local_Form = new System.Windows.Forms.Form();
local_Form.MdiParent = this;
local_Form.Show();
}
private void RunThread()
{
System.Data.SqlClient.SqlConnection local_SqlConnection = new System.Data.SqlClient.SqlConnection();
System.Data.SqlClient.SqlCommand local_SqlCommand = new System.Data.SqlClient.SqlCommand();
System.Data.SqlClient.SqlDataReader local_SqlDataReader;
local_SqlConnection.ConnectionString = @"Data Source=MyServer\MyInstance;Initial Catalog=master;Integrated Security=true;";
local_SqlConnection.Open();
while (!StopThread)
{
local_SqlCommand.CommandText = "SELECT * FROM SomeTable";
local_SqlCommand.CommandTimeout = 0;
local_SqlCommand.Connection = local_SqlConnection;
local_SqlDataReader = local_SqlCommand.ExecuteReader();
System.Data.DataTable local_DataTable = new System.Data.DataTable();
local_DataTable.BeginLoadData();
local_DataTable.Load(local_SqlDataReader);
local_DataTable.EndLoadData();
System.Threading.Thread.Sleep(2000);
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{ StopThread = true; }
modified on Wednesday, February 3, 2010 9:14 AM
|
|
|
|
|
Please show formatted code, use PRE tags! You can still edit your message.
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. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Hi Luc
What are PRE Tags ??
When you paste the code into Visual Studio
it is formatted automaticly.
Regards
Frank Uray
|
|
|
|
|
PRE tags are HTML instructions that provide background color, non-proportional font, syntax coloring (on CodeProject at least), and indentation, like so:
public class CPTest_OwnIPAdr : CPTest {
public override void Test(int arg) {
String strHostName;
strHostName = Dns.GetHostName();
log("Local Machine's Host Name: " + strHostName);
IPHostEntry ipEntry = Dns.GetHostByName(strHostName);
IPAddress[] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++) {
log("IP Address "+addr[i].ToString());
}
}
}
I don't copy/paste all messages to Visual, I do read a lot of messages provided their formatting is acceptable, so please add <PRE> and </PRE> around code snippets. The "code block" widget may help you.
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. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Hi Luc
Ok, I have changed it
Regards
Frank Uray
|
|
|
|