PDA

View Full Version : C# Console Application


FrodoLives
02-06-2007, 11:12 AM
Dal program huwa stock control speci ta, ssa malli mmur bix namel lincriment, jahdem imma malli jlesti jibqa jillopja flistess post... any help??


static void Increase()
{
string opt = "";
string qamount = "";
bool state = false;
// check if stock is empty
if (stock.Count != 0)
{
// loop until state = true
do
{
qamount = "";
int id = 0;
Console.Clear();
Console.WriteLine(" .:STOCK CONTROL:. ");
Console.WriteLine(" -----------------");
Console.WriteLine(" .:INCREASE STOCK:. ");
Console.WriteLine(" ");
Console.Write("Product ID: ");
// check if it is an integer trough method CheckInt
qamount = Console.ReadLine();
CheckInt(qamount);
//do on true/false
switch (CheckInt(qamount))
{
case true:
// check if input is emtpy
if (qamount.Length == 0)
{
// if empty print error msg
Console.Clear();
Console.WriteLine(" .:STOCK CONTROL:. ");
Console.WriteLine(" -----------------");
Console.WriteLine(" .:INCREASE STOCK:. ");
Console.WriteLine(" ");
Console.WriteLine("Product ID: CANT BE EMPTY! - PRESS ANY KEY");
Console.ReadLine();

}
else
{ //else begin by checking if product exists in stock
id = Convert.ToInt32(qamount);
if (id > stock.Count)
{
//if not found display error msg
Console.Clear();
Console.WriteLine(" .:STOCK CONTROL:. ");
Console.WriteLine(" -----------------");
Console.WriteLine(" .:INCREASE STOCK:. ");
Console.WriteLine(" ");
Console.WriteLine("Product ID: PRODUCT NOT FOUND");
Console.ReadLine();
}
else
{
// else begin loop until option (opt) is y or n
do
{ int i = 0;
int count = 0;
// do for loop to fill temporary array (temp)
for (count = 0; count < id; count++)
{
string[] temp = new string[3];
temp = (string[])stock[id - 1];
i = Convert.ToInt32(temp[0]);
// display array for user verification
Console.Clear();
Console.WriteLine(" .:STOCK CONTROL:. ");
Console.WriteLine(" -----------------");
Console.WriteLine(" .:INCREASE STOCK:. ");
Console.WriteLine(" ");
Console.WriteLine("Product ID: " + temp[0]);
Console.WriteLine("Product Name: " + temp[1]);
Console.WriteLine("Quantity: " + temp[2]);
Console.WriteLine(" ");
Console.Write("[y]es | [n]o -> ");
opt = Console.ReadLine();
opt = opt.ToLower();
// switch between yes and no
switch (opt)
{
case "y":
// if yes do until state = true
do
{
state = false;
qamount = "";
Console.Clear();
Console.WriteLine(" .:STOCK CONTROL:. ");
Console.WriteLine(" -----------------");
Console.WriteLine(" .:INCREASE STOCK:. ");
Console.WriteLine(" ");
Console.WriteLine("Product ID: " + id);
Console.WriteLine("Product Name: " + temp[1]);
Console.WriteLine("Quantity: " + temp[2]);
Console.WriteLine(" ");
Console.WriteLine("[y]es | [n]o -> " + opt);
Console.WriteLine(" ");
Console.Write("Enter Amount to Add: ");
// ask for the amount
qamount = Console.ReadLine();
CheckInt(qamount);
// check if amount is integer
switch (CheckInt(qamount))
{
case true:
// begin if input is null then
if (qamount.Length == 0)
{
//display error msg
Console.Clear();
Console.WriteLine(" .:STOCK CONTROL:. ");
Console.WriteLine(" -----------------");
Console.WriteLine(" .:INCREASE STOCK:. ");
Console.WriteLine(" ");
Console.WriteLine("Product ID: " + id);
Console.WriteLine("Product Name: " + temp[1]);
Console.WriteLine("Quantity: " + temp[2]);
Console.WriteLine(" ");
Console.WriteLine("[y]es | [n]o -> " + opt);
Console.WriteLine(" ");
Console.Write("Enter Amount to Add: CANT BE EMPTY! - PRESS ANY KEY");
Console.ReadLine();

}
else
{ //else make state true
state = true;
//prepare amount( convert to int for method IncreaseProceess
int amount = Convert.ToInt32(qamount);
//Method Process will wotk the new sum
IncreaseProcess(id, amount);
}
//break switch(stop)
break;

case false:
// if amount was not integer, display error msg
Console.Clear();
Console.WriteLine(" .:STOCK CONTROL:. ");
Console.WriteLine(" -----------------");
Console.WriteLine(" .:INCREASE STOCK:. ");
Console.WriteLine(" ");
Console.WriteLine("Product ID: INVALID INPUT - PRESS ANY KEY");
Console.ReadLine();
//leave state false
state = false;

break;
}
// if state = true then the lopp will stop
} while (state != true);



break;
case "n":
// case the user choses no, go back to menu
Add();
break;
default:
// this is what will print if invalid input ( not y or n)
Console.Clear();
Console.WriteLine(" .:STOCK CONTROL:. ");
Console.WriteLine(" -----------------");
Console.WriteLine(" .:INCREASE STOCK:. ");
Console.WriteLine(" ");
Console.WriteLine("Product ID: " + temp[0]);
Console.WriteLine("Product Name: " + temp[1]);
Console.WriteLine("Quantity: " + temp[2]);
Console.WriteLine(" ");
Console.WriteLine("[y]es | [n]o -> INVALID INPUT - PRESS ANY KEY");
Console.ReadKey();
break;
}
}
//if option of user was good (y/n) - stop loop
}while (opt != "y" && opt != "n");

}// close else if product wasn't found
}// close else if amount was null
break;
// case the input was not integer do :
case false:
Console.Clear();
Console.WriteLine(" .:STOCK CONTROL:. ");
Console.WriteLine(" -----------------");
Console.WriteLine(" .:INCREASE STOCK:. ");
Console.WriteLine(" ");
Console.WriteLine("Product ID: INVALID INPUT - PRESS ANY KEY");
Console.ReadLine();
break;
}// close switch check input
}// close do until state = true

while (state != true);

}
else// else if stock was 0(empty) do:
{
Console.Clear();
Console.WriteLine(" .:STOCK CONTROL:. ");
Console.WriteLine(" -----------------");
Console.WriteLine(" .:INCREASE STOCK:. ");
Console.WriteLine(" ");
Console.WriteLine("STOCK IS EMPTY");
Console.ReadLine();
}// close else if stock was empty
MainMenu();// go back to menu
} //ready

FrodoLives
02-06-2007, 12:03 PM
ok rrangajt - I think