|
The format is available, but sometimes it can be a bit fuzzy what they mean. I glanced at an open source implementation (can't remember the name, it was a command line thingy normally available on for example Linux). This was for an internal use only project, so GPL code was not a problem but you should be careful if you need to release the program.
It is relatively easy task, but I would still estimate a week to do it (and I have done it before).
|
|
|
|
|
Hello..
I simply want to develop a stock program but somewhere I make smth. wrong and I cannot say where.. My program seems write into file in binary mode but connot recover the data correct.. The problem is , I enter 3 samples fırst.. then I want to edıt 3.rd one , when ın debug mode , I can get first 2 item's data but when 3rd , It throws an exception "Unable to read beyond the end of the stream." Can anyone help me what is wrong with my code? Thanks..
using System;
using System.Data;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
namespace fileodevi
{
public struct type//yenı urun ıcın kullanılacak struct type
{
public string name;
public double price;
public int stok;
public const int SIZE = 36;
}
class Class1
{
private const string fileName = "file1.dat";
private BinaryWriter writer = null;
private BinaryReader reader = null;
public FileStream file = null;//global deklerasyon , daha sonra her yerde kullanalım dıye..
public Class1()
{
do
{
try
{
file = new FileStream(fileName,FileMode.OpenOrCreate);
Console.WriteLine("File created(if NOT exists / Opened(if exists)");
break;
}
catch(Exception exp)
{
Console.WriteLine(exp);
file.Close();
}
}while(true);
file.Close();
}
public void enterNewProduct()
{
type newProduct = new type();
do
{
try
{
file = new FileStream(fileName , FileMode.Append , FileAccess.Write);
Console.WriteLine("File opened for writing new entry");
break;
}
catch(Exception ex)
{
Console.WriteLine(ex);
}
}while(true);
//urun adı
Console.WriteLine("Enter name of the new product :");
Console.WriteLine("WARNING name MUST be at most 20 characters!!\n");
do
{
newProduct.name = Console.ReadLine();
if(newProduct.name.Length < 20)
{
newProduct.name += new string(' ',20-newProduct.name.Length);
}
}while(newProduct.name.Length > 20);
//urun fıyatı
Console.WriteLine("Enter Price of the new product :");
do
{
try
{
newProduct.price = double.Parse(Console.ReadLine());
break;
}
catch(FormatException e)
{
Console.WriteLine(e);
}
}while(true);
//urun adedı
Console.WriteLine("Enter amount of the product :");
do
{
try
{
newProduct.stok = Int32.Parse(Console.ReadLine());
break;
}
catch(FormatException ex)
{
Console.WriteLine(ex);
}
}while(true);
//urunu fıle a kaydetme
do
{
try
{
writer = new BinaryWriter(file);
writer.Write(newProduct.name);
writer.Write(newProduct.price);
writer.Write(newProduct.stok);
Console.WriteLine("Product successfully entered to file");
writer.Close();
file.Close();
Console.WriteLine("File closed");
break;
}
catch(Exception b)
{
Console.WriteLine(b);
}
}while(true);
}
public void editProduct(string name)
{
type pro = new type();
if(name.Length < 20)
{
name += new string(' ' ,(20-name.Length));
}
do
{
try
{
file = new FileStream(fileName,FileMode.Open,FileAccess.ReadWrite);
Console.WriteLine("File opened for Editing");
break;
}
catch(Exception ex)
{
Console.WriteLine(ex);
}
}while(true);
reader = new BinaryReader(file);
for(int b = 0;;b++)
{
pro.name = reader.ReadString();
pro.price = reader.ReadDouble();
pro.stok = reader.ReadInt32();
int sel = 0;
try
{
if(string.Equals(name , pro.name))
{
reader.Close();
Console.WriteLine("What attirbute dou you wish to change ? :");
Console.WriteLine(" 1) Name\n 2) Price\n 3)Amaount in stock");
sel = Int32.Parse(Console.ReadLine());
switch(sel)
{
case 1:
Console.WriteLine("Enter new Name of the product :");
Console.WriteLine("The name must be at most 20 characters\n");
do
{
pro.name = Console.ReadLine();
if(pro.name.Length < 20)
{
pro.name += new string(' ',(20-pro.name.Length));
Console.WriteLine(pro.name.Length.ToString());
}
}while(pro.name.Length > 20);
break;
case 2:
Console.WriteLine("Enter new Price of the product :");
do
{
try
{
pro.price = double.Parse(Console.ReadLine());
break;
}
catch(Exception ex)
{
Console.WriteLine("Invalid amount try again..");
}
}while(true);
break;
case 3:
Console.WriteLine("Enter new stock number :");
do
{
try
{
pro.stok = Int32.Parse(Console.ReadLine());
break;
}
catch(Exception ex)
{
Console.WriteLine("Invalid amount try again..");
}
}while(true);
break;
}
writer = new BinaryWriter(file);
writer.Seek(b*(type.SIZE),SeekOrigin.Current);
try
{
writer.Write(pro.name);
writer.Write(pro.price);
writer.Write(pro.stok);
writer.Close();
file.Close();
Console.WriteLine("File Closed , writer closed");
}
catch(Exception ex)
{
Console.WriteLine("Error writting");
}
break;
}
else
{
file.Seek(b*(type.SIZE),SeekOrigin.Current);
}
}
catch(Exception ex)//File ıcınde obje bulamadıgı zaman veya okurken bı hata ıle karsılasırsa...
{
Console.WriteLine("No such Item Found...");
file.Close();
break;
}
}
}
[STAThread]
static void Main(string[] args)
{
char sel ;
Class1 c = new Class1();
while(true)
{
Console.WriteLine("A) To enter a new product");
Console.WriteLine("B) Edit a product");
Console.WriteLine("C) Order a product");
Console.WriteLine("D) Exit program");
do
{
try
{
sel = char.Parse(Console.ReadLine().ToLower());
break;
}
catch(Exception)
{
Console.WriteLine("The Input command is invalid.Try Again..");
}
}while(true);
if( sel == 'a')
{
c.enterNewProduct();
}
if(sel == 'd')
{
break;
}
if(sel == 'b')
{
Console.WriteLine("Enter the name of the product you wish yo edit :");
c.editProduct(Console.ReadLine());
}
}
}
}
}
Revelation 22:13
-- modified at 15:58 Sunday 6th November, 2005
|
|
|
|
|
Use the pre tag to keep the indentation of the code when you post it.
---
b { font-weight: normal; }
|
|
|
|
|
Hi
I have trouble in setting the displaymember in a dataset-binded combobox.
My Code:
this.cselectName.DataSource = this.selectExpensePropertiesDataSet1.cPerson;
this.cselectName.DisplayMember = "LastName";
this.cselectName.Location = new System.Drawing.Point(368, 16);
this.cselectName.Name = "cselectName";
this.cselectName.Size = new System.Drawing.Size(144, 21);
this.cselectName.TabIndex = 6;
this.cselectName.Tag = "";
this.cselectName.ValueMember = "pID";
I tried to set a DisplayMember as default value selected using the following code:
cselectType.SelectedIndex = cselectType.FindStringExact("Miete");
Hasn't worked.
Any ideas?
Thanks in advance.
Jens
-- modified at 15:38 Sunday 6th November, 2005
|
|
|
|
|
hi i am c# programmer and thank you for your site . it is best programming site .
how to get serial number of cd in c# ?
please help me ...
thanks
hdv212@yahoo.com
hdv212@yahoo.com
|
|
|
|
|
Hi i am new to C# and would like to ask for some helps here on array
The scenario is like this,
I need to create a form with a combobox for a restaurant which store a series of food and their respective prices. When any food items on the combobox is checked, the name and price of the name is supposed to be appeared on a listbox.
http://photobucket.com/albums/c358/pearhk2/?action=view¤t=asg1.jpg[^]
I managed to get the name of the food appear on the listbox but cant get the price corresponding to them listed
//Food Prices
decimal[] FoodPrice = new decimal[] {5, 5.5M, 6, 6.5M, 7, 7.5M};
//Selected Food Name listing on MealList Box
MealList.Items.Add(FoodBox.Text);
The above line is how i add the food name on the list, may i know how to add the price of the chosen item too? i tried going through my textbook still cant get it done
Any helps will be much appreciated, Thanks in advance!
|
|
|
|
|
FoodPrice[MealList.SelectedIndex] is probably what you're looking for, although I'd have done it with a hashtable to be safe.
Or perhaps FoodBox.SelectedValue ? A combobox can store name/value pairs, but you'd know if you'd done that, I guess.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi.
I put some Label controls on a form and then put Text into them. I also wanted to put a random number into some labels on the same form. So I do this:
Random r = new Random();
label6.Text = r.Next(88).ToString();
label6.Location = new Point(90,60);
this.Controls.Add(label6);
This is what I did to the other Labels that I want on my form except I did not put a random number into them. The problem is that the label (label6) doesn´t show up on the form. Why is that? What am I missing? What do I need to do so that the label shows up on the form containing a random number?
Thanks,
FJ
|
|
|
|
|
You don't need to do anything different, so that is not where the problem is. Can you set the location before adding it to the form ? I'd have done those two in the other order.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Is there a way to speed up starting of an c# application?
i'm using microsoft internet control and it takes a few seconds to load, can I precache or something?
Thanx in advance.
Lju2
|
|
|
|
|
Hello All,
I made a Com+ component connect over network to insert , update and delete from the Sql serve in the same network. but i got error means that no connectivity between the server and client.
I need to know what is the default ports and portocols that the Com+ user it over the network?
Thanks
Hay
|
|
|
|
|
A search in the Microsoft Knowledge Base for COM+ ports to open for firewalls[^] yields what you want. The first result - How to configure RTP dynamic port allocation to work with firewalls[^] is probably what you want. The linked article How to configure a firewall for domains and trusts[^] might also be helpful to solve potential authentication issues.
You could also define either a specific unused port for the COM+ component or a static range for all components and open those on the firewall, but the former would be more secure. Don't forget to open ports on the client
Also keep in mind authentication. Once you've solves connection problems make sure that you've set up the appropriate authentication and authorization for your component using the Component Services MMC snap-in. Much of that can be configured using the appropriate attributes on your COM+ service, too.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
|
|
I am using a TreeView Control to view the complete set of folders in Outlook and now I have the complete set I want to prune the ones that don't have the capability of storing mail messages.
What I want to to do is only add those folders to the Treeviw that are of the correct type which means I need to query the type.
I expected to be able to do something like:-
if (currentFolder.GetTypeOfFolder = olMailFolder) {
AddChild(...)
}
but I can't find any reference to a folder type that I might be able to use in this way. Anyone with any bright ideas?
Cheers,
Goose
|
|
|
|
|
Hold that thought, just answered it myself!
For those interested, the answer is:-
if (mF.DefaultItemType == Outlook.OlItemType.olMailItem) {
AddChild(...)
}
|
|
|
|
|
How do you paint a user control with transparent background?
I have set this line in the constructor: this.SetStyle( ControlStyles.SupportsTransparentBackColor , true ); , but now my control has a black background.
Regards,
Johnny
|
|
|
|
|
Do you also have these two lines?
this.SetStyle(ControlStyles.UserPaint, true);
this.BackColor = System.Drawing.Color.FromArgb(0, 0, 0, 0);
|
|
|
|
|
Yeah, I was deriving from CheckBox and i think that was the problem. Now I'm deriving from usercontrol and it works like it supposed to.
Thanks anyways
|
|
|
|
|
I'm trying to write a sliding panel custom control. As regards the component sliding etc it is all ok. However, during design mode the V.S. doesn't let me place controls inside the panel. It places them on top of the panel, not into it. Can any one help out on this.
Best Regards
|
|
|
|
|
Try deriving your custom control class from System.Windows.Forms.Panel instead of System.Windows.Forms.UserControl
Hope this is what you are looking for...
Greatings,
Johnny
|
|
|
|
|
Did you set ControlStyles.ContainerControl style on your control?
(using Control.SetStyle() )
Regards,
mav
|
|
|
|
|
Hi,
I'm building a small application where I like to capure a part of the application screen and save it as a image.
Does anyone know of any tutorials o similiar about this??
The part I like capture is filled with a flash application if that will make it any difference.
Best regards
Magnus
|
|
|
|
|
If you search for screen capture[^] in the article search box at the top of every page right under the Code Project logo you can find many helpful articles and sample code.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Question please
I'd like to access data from database using dataset dependent on the
selectedValue in combobox.
My combobox's displays displayMember FieldName,
based on its valueMember fieldId,
i'd like be able to access the FieldAddress
which are all in Fields Table.
thank you!
I wanna have something like this, except it doesn't return the whole row but just the Address:
<br />
DataRow drSelectedCustomer;<br />
drSelectedCustomer = <br />
dsNorthwind1.Customers.FindByCustomerID(SelectedCustomerID);
thank you again
Gerri
|
|
|
|