|
martin_hughes wrote: but I really like 3.0's auto implementing properties
3.5 was released last week. But I'm further behind - I'm still using 2.0
|
|
|
|
|
.Net 3.5 did... but the language is C# 3.0! Yay for confusion!
"On one of my cards it said I had to find temperatures lower than -8. The numbers I uncovered were -6 and -7 so I thought I had won, and so did the woman in the shop. But when she scanned the card the machine said I hadn't.
"I phoned Camelot and they fobbed me off with some story that -6 is higher - not lower - than -8 but I'm not having it."
-Tina Farrell, a 23 year old thicky from Levenshulme, Manchester.
|
|
|
|
|
Anything interesting other than LINQ?
|
|
|
|
|
Semi-tied in to LINQ, but extension methods are pretty sweet too!
"On one of my cards it said I had to find temperatures lower than -8. The numbers I uncovered were -6 and -7 so I thought I had won, and so did the woman in the shop. But when she scanned the card the machine said I hadn't.
"I phoned Camelot and they fobbed me off with some story that -6 is higher - not lower - than -8 but I'm not having it."
-Tina Farrell, a 23 year old thicky from Levenshulme, Manchester.
|
|
|
|
|
I have met this exercise in a book I am reading :
Develop a C# application that will determine whether any of several department-store customers has exceeded the credit limit on a charge account. For each customer, the following facts are available:
account number
balance at the beginning of the month
total of all items charged by the customer this month
total of all credits applied to the customer's account this month
allowed credit limit.
The application should input all these facts as integers, calculate the new balance (= beginning balance + charges credits), display the new balance and determine whether the new balance exceeds the customer's credit limit. For those customers whose credit limit is exceeded, the application should display the message "Credit limit exceeded". Use sentinel-controlled repetition to obtain the data for each account.
I have tried to code this solution and I came to this source code :
CustomerTest.cs :
using System;<br />
<br />
public class CustomerTest<br />
{<br />
public static void Main(string[] args)<br />
{<br />
int account_Number;<br />
int initial_Balance;<br />
int total_Month_Items;<br />
int total_Month_Credits;<br />
int credit_Limit;<br />
<br />
<br />
Customer myCustomer = new Customer(0, 0, 0, 0, 0);<br />
<br />
<br />
Console.Write("Enter account number or -1 to quit : ");<br />
account_Number = Convert.ToInt32(Console.ReadLine());<br />
<br />
while (account_Number != -1)<br />
{<br />
Console.Write("Enter balance at the beggining of the month : ");<br />
initial_Balance = Convert.ToInt32(Console.ReadLine());<br />
<br />
Console.Write("Enter total of all items charged by the customer this month : ");<br />
total_Month_Items = Convert.ToInt32(Console.ReadLine());<br />
<br />
Console.Write("Enter total of all credits applied to the customer's account this month : ");<br />
total_Month_Credits = Convert.ToInt32(Console.ReadLine());<br />
<br />
Console.Write("Enter customer's credit limit : ");<br />
credit_Limit = Convert.ToInt32(Console.ReadLine());<br />
<br />
myCustomer.AccountNumber = account_Number;<br />
myCustomer.InitialBalance = initial_Balance;<br />
myCustomer.TotalMonthItems = total_Month_Items;<br />
myCustomer.TotalMonthCredit = total_Month_Credits;<br />
myCustomer.CreditLimit = credit_Limit;<br />
<br />
myCustomer.DetermineNewBalance();<br />
<br />
}<br />
}<br />
}
Customer.cs :
using System;<br />
<br />
public class CustomerTest<br />
{<br />
public static void Main(string[] args)<br />
{<br />
int account_Number;<br />
int initial_Balance;<br />
int total_Month_Items;<br />
int total_Month_Credits;<br />
int credit_Limit;<br />
<br />
<br />
Customer myCustomer = new Customer(0, 0, 0, 0, 0);<br />
<br />
<br />
Console.Write("Enter account number or -1 to quit : ");<br />
account_Number = Convert.ToInt32(Console.ReadLine());<br />
<br />
while (account_Number != -1)<br />
{<br />
Console.Write("Enter balance at the beggining of the month : ");<br />
initial_Balance = Convert.ToInt32(Console.ReadLine());<br />
<br />
Console.Write("Enter total of all items charged by the customer this month : ");<br />
total_Month_Items = Convert.ToInt32(Console.ReadLine());<br />
<br />
Console.Write("Enter total of all credits applied to the customer's account this month : ");<br />
total_Month_Credits = Convert.ToInt32(Console.ReadLine());<br />
<br />
Console.Write("Enter customer's credit limit : ");<br />
credit_Limit = Convert.ToInt32(Console.ReadLine());<br />
<br />
myCustomer.AccountNumber = account_Number;<br />
myCustomer.InitialBalance = initial_Balance;<br />
myCustomer.TotalMonthItems = total_Month_Items;<br />
myCustomer.TotalMonthCredit = total_Month_Credits;<br />
myCustomer.CreditLimit = credit_Limit;<br />
<br />
myCustomer.DetermineNewBalance();<br />
<br />
}<br />
}<br />
}
The problem is in the first file when I use the sentinel-controlled repetition because I get no account number question at the second loop.Any ideas how to fix this one?Thnx!
|
|
|
|
|
A loop (for, while, ...) repeats whatever is inside, not what is in front of it.
|
|
|
|
|
Hello everybody
I ask everyone who can disign a simple paint software lookalike winXP
of course I need the source&code in C#
As soon as possible,Please
alirahimei@yahoo.com
Thank you
|
|
|
|
|
The CodeProject site holds articles about almost anything, and has search facilities.
You must use them ASAP. Now. Urgently.
|
|
|
|
|
Luc Pattyn wrote: Urgently.
Oh my, the u-word
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hello everybody
I ask everyone who can disign a simple paint software lookalike winXP
of course I need the source&code in C#
As soon as possible,Please
|
|
|
|
|
Did you search google? There is an open source program much better then paint
|
|
|
|
|
hi freind i want to change the Border the color of the Text box . friend of mine give me advice to use User Controland change the back color of the user Control.
Now the question is how i can User control in myForm
wasim khan
|
|
|
|
|
Dear Wasim,
instead of making user control write this code in Paint Event of Form
foreach (Control acontrol in this.Controls)
{
if (acontrol is TextBox)
{
Pen myPen = new Pen(Color.White, 4.0F);
e.Graphics.DrawRectangle(myPen, new Rectangle(acontrol.Bounds.X, acontrol.Bounds.Y, acontrol.Bounds.Width, acontrol.Bounds.Height));
e.Graphics.Dispose();
}
}
hope this will help
Becoming Programmer...
|
|
|
|
|
HI xmen_xwk
there is a little bit problem that Text box controls are not found the loop execute each time but it
never move inside the body of the loop the Text Boxes are inside the Group
wasim khan
|
|
|
|
|
as far as i understood that you were saying that textboxes are in groupbox
if yes, then just change this.Controls in this line :
foreach (Control acontrol in this.Controls)
with GroupName
foreach (Control acontrol in <<write group name>>)
Becoming Programmer...
|
|
|
|
|
Hi, i'd like to have a menuitem
that ptints the screen directly to printer,
any idea where do i start
i did not found any thing Simple here
anyone?
THANKS
Have Fun
Never forget it
|
|
|
|
|
There are many articles here on codeproject that describe how to take screenshot programmatically, why don't you look through them?
|
|
|
|
|
Hello, guys!!
I am working with an application that uses a try-catch block inside a DragOver Event handler. The problem is that there is an Argument Exception that occurs when a control is dragged. Technically, it is a circular reference. When this Argument Exception occurs, both controls disappear, and the ArgumentException handler catches the error. The question is, how do I get the Exception handlers to prevent the code from running, thereby preventing the controls from disappearing? Is there a way of trapping the condition that causes the ArgumentException so that the controls would not disappear because of the error?
Here is the code:
private static void _ctrlParent_DragOver(object sender, DragEventArgs e)
{
try
{
if (DragDropHandler.CanDropHere((Control)sender, e.Data))
{
Control cthis = (Control)sender;
CardControl ctrl = (CardControl)DragDropHandler.GetControl(e.Data, true, true);
e.Effect = DragDropEffects.Move;
if (!(ctrl is IDragDropEnabled))
{
return;
}
if (cthis.Name != ctrl.Name)
{
if ((ctrl.HasChildren == false) && (ctrl.blnCardFaceStatus==true)
|| ((ctrl.HasChildren == true) && (ctrl.blnCardFaceStatus=true)))
{
ctrl.Parent.Controls.Remove(ctrl);
ctrl.Parent = cthis;
cthis.Controls.Add(ctrl);
ctrl.BringToFront();
}
else if ((ctrl.HasChildren == true) && (ctrl.blnCardFaceStatus==false)
|| ((ctrl.HasChildren == false) && (ctrl.blnCardFaceStatus=false)))
{
return;
}
}
else
{
return;
}
Point NewLocation = cthis.PointToClient(new Point(e.X, e.Y));
ctrl.Left = NewLocation.X - dragPoint.X;
ctrl.Top = NewLocation.Y - dragPoint.Y;
}
else
{
e.Effect = DragDropEffects.None;
}
}
catch (System.ArgumentException)
{
MessageBox.Show("Argument Exception Error");
}
}
modified on Monday, December 24, 2007 8:12:20 PM
|
|
|
|
|
Hi everyone...A newbie is confuse here, so please help...and before we start, please aplogize for my bad english
OK, lets start.
I have a task to make an XML file from unusual Excel file...i'm giving the screenshot...please follow the link
http://img227.imageshack.us/img227/1637/capthd0.jpg
So, as u can see that the spreadsheet is not a good looking one...and i've been trying to convert it into an XML file....with reading many tutors...
The file (.xls) is different in the field name (such as "TMPT LHR" can be "TMPT_LHR" or "TMPTLHR" in other xls file) between another...and it is make me crazy doing for one single file...not yet another file :P
Here are methods that i tried:
1. with XML Schema in the Excel view source...not really good at it (my kowledge), cause my test went bad, the XML file output doesn't go as i wish, it messy..
2. Save As the spreadsheet as CSV, and i found it like this...please follow the link...it more make me confuse..
http://img84.imageshack.us/img84/8210/csvfj3.jpg
3. Save As the spreadsheet as Text, and dont get any idea how to convert it...
4. Save As the spreadsheet as XML Spreadsheet, and i try to read the <data> tag/node in it and finally succeded reading the element string (inside the <data>) using VC#... and try to make a well formed XML file...this part not done yet...
This is the code..
start***** this is the code for reading the node****
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
namespace test1
{
public partial class Form1 : Form
{
public String fileName;
public String dbconnect;
public String strNodeValues;
//public String[] strNodeValues3a = new String[3] { "", "", "" }; <- the 3 top field from excel
//public String[] strNodeValues3b = new String[3] { "", "", "" }; <- the 1 record under the 3 top filed
//public String[] strNodeValues15a = new String[15] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" }; <- the 15 field under the 1 record
//public String[] strNodeValues15b = new String[15] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" }; <- wish this line to held the 15 data of 1 record, that can be not just one record...see pict above please...
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
Stream myStream;
// String fileName;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "xml files (*.xml)|*.xml";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
myStream.Close();
fileName = openFileDialog1.FileName;
textBox1.Text = fileName;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
XmlTextReader reader = new XmlTextReader(fileName);
while (reader.Read())
{
switch (reader.Name)
{
case "Data ":
reader.Read();
strNodeValues = reader.Value;
MessageBox.Show(reader.Value, "Ini " + strNodeValues); <- i see it with message box.
break;
}
}
}
private void button7_Click(object sender, EventArgs e)
{
listBox1.Items.Add(textBox2.Text);
}
private void button8_Click(object sender, EventArgs e)
{
listBox1.Items.Remove(listBox1.SelectedItem);
}
}
}
End***** this is the code for reading the node****
start***** this is the code (class file) for making the XML file**** I edited it from a log generator...
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace test1
{
class bknxml
{
private const string FILE_NAME = "Logimp.log";
StreamWriter sw = null;
public bknxml()
{
if (File.Exists(FILE_NAME))
sw = File.AppendText(FILE_NAME);
else
{
sw = File.CreateText(FILE_NAME);
sw.WriteLine("");
//sw.WriteLine("Generated log by Aplikasi XML Import for PL/SQL error reporting on " + DateTime.Now.DayOfWeek + " at " + DateTime.Now);
}
}
public void writexml(params string[] file)
{
sw.WriteLine("<data_sync>");
foreach (string f in file)
{
sw.WriteLine(" <kk_wni>");
sw.WriteLine(f);
sw.WriteLine(" </kk_wni>");
}
sw.WriteLine("</data_sync>");
sw.WriteLine("");
}
public void closefile()
{
sw.Close();
}
}
}
End***** this is the code for making the XML file****
start***** this is how i want the XML well formed look like****
<data_sync>
<kk_wni>
<no_transaksi>73710110006102006000004</no_transaksi>
<no_kk>7371010610060003</no_kk>
<alamat>JL. BANTAENG 10</alamat>
<rt>001</rt>
<rw>001</rw>
<kd_pos>90221</kd_pos>
<telp> </telp>
<dusun> </dusun>
<kd_wilayah>7371011001</kd_wilayah>
<nama_rt> </nama_rt>
<nama_rw> </nama_rw>
<nama_ptgs_reg> </nama_ptgs_reg>
<nip_ptgs_reg> </nip_ptgs_reg>
<nama_pjbt> </nama_pjbt>
<nip_pjbt> </nip_pjbt>
<created_date>2006-10-06T15:21:22.0000000+08:00</created_date>
<created_by>Febby Ekadiarta</created_by>
<updated_by> </updated_by>
<tgl_transaksi>2006-10-19T09:07:54.0000000+08:00</tgl_transaksi>
</kk_wni>
<kk_wni>
<no_transaksi>73710110006102006000001</no_transaksi>
<no_kk>7371010610060001</no_kk>
<alamat>JL. BANTAENG 10</alamat>
<rt>001</rt>
<rw>001</rw>
<kd_pos>90221</kd_pos>
<telp> </telp>
<dusun> </dusun>
<kd_wilayah>7371011001</kd_wilayah>
<nama_rt> </nama_rt>
<nama_rw> </nama_rw>
<nama_ptgs_reg> </nama_ptgs_reg>
<nip_ptgs_reg> </nip_ptgs_reg>
<nama_pjbt> </nama_pjbt>
<nip_pjbt> </nip_pjbt>
<created_date>2006-10-06T15:12:48.0000000+08:00</created_date>
<created_by>Febby Ekadiarta</created_by>
<updated_by> </updated_by>
<tgl_transaksi>2006-10-19T09:07:54.0000000+08:00</tgl_transaksi>
</kk_wni>
</data_sync>
End***** this is how i want the XML well formed look like****
I want the XML to be look like the above...cause i already made a single application that can inserting the xml data into an oracle table with XML style....and would kindly share to other...
SO...Mr and Mrs Expert please help me...
1. Which is the best method that i have to use? Would you kindly suggest me some better method?
2. If it is not to hard for you to kindly help me, please help me coding the code...the XML Spreadsheet reader and the XML creator...
Please send me mail...if anyone would kindly collaborate coding with this stupid newbie
send it to: me.iyepb0@gmail.com, or YM: me.iyepb0@yahoo.com
To be honest...its been 1 month i'm starting learning VC#...and i was not really a programmer mindset...just drop from colledge...
Thank you for you guys who will be and helping this stupid newbie...tx</data></data>
<div class="ForumMod">modified on Monday, December 24, 2007 4:18:44 PM</div>
|
|
|
|
|
Method 3 is probably the best, i.e. saving the spreadsheet as an XML Spreadsheet and then transforming it into the required form. Note that there is a special language design to do exactly this: XSLT.
Some tips for Xml with .NET, take a look into them:
1) There is a whole namespace dedicated to reading, writing and manipulating Xml, the System.Xml namespace.
2) There is (in .NET 3.0 / 3.5) a "query" language (other than XPath) for selecting Xml: LINQ (System.Xml.Linq)
|
|
|
|
|
There's a simpler way than those you listed and you won't have to save the Excel file in another format. You can use ADO.NET to read from the Excel file (use OleDb), next you fill the data in a dataset then save the data in the dataset as an .xml file using WriteXml() (you have the option to save the schema too or you could save the schema in a separate file using WriteXmlSchema())
Tell me if you want the details.
|
|
|
|
|
Just to put in my two cents – there is a free editor out there that can edit those ado.net xml file. Just drag the file in and it leats you view and edit all the data in a really effective way: (then save it as Excel file.. optionally selecting which rows you'd like to be in that fie)
http://www.nobhillsoft.com/MarieAlix.aspx
(its currently on beta so its given out freely)
|
|
|
|
|
Hi all, I'm looking for a way to hide a property from the property grid while still allowing it to be serialized into XML. The problem is that if I set the [Browseable(false)] attribute on the property, this hides it from the property grid but also makes the property not serialize out to XML. Is there a decent way around this issue?
|
|
|
|
|
Did you put a XmlElement on the property?
|
|
|
|
|
Yes, but if Browseable is set to false, it doesn't serialize out to XML. So what I need is a way to hide a property from the property grid without using the browseable attribute, or a way to change the browseable attribute dynamically before the item is saved..
|
|
|
|
|