|
|
Find out here[^]
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
It's one place you can go to learn about programming.
|
|
|
|
|
Maybe you need to start with a book on the basics of OOPS programming.
|
|
|
|
|
"Class," and "Object," as used in modern computer science, both can have a wide range of meanings.
Assuming your goal is to understand these concepts in .NET, and C#, I'd suggest you download the free e-book by Charles Petzold, ".NET Book Zero," here: [^], and read Chapter 13, "Classes, Structures, and Objects," and then read Chapters 14, 15.
Both "Class" and "Object" can be regarded as basic concepts in the knowledge domain of "Object Oriented Programming."
Both terms can be regarded as reflecting the idea of a discrete "entity," a unit of logic, a semantic abstraction which models a "thing," or, "process," in the "real world."
I think reading about the history of Object Oriented Programming will help you get a sense of what these terms mean, and how they are often used quite differently by different people: [^].
On a practical level in .NET, a Class is a block of code which can be seen as a template, or factory, for the manufacture of instances of the Class; some would say that the instances of a Class are Objects, but the Class is not quite the same thing. Some would say that a Class is an Object, and there have been (and are) computer languages in which everything you can think of is considered to be a Class.
In .NET a Class is a provider of a "bundle" of functionality: a constructor that supports parameters, an ability to inherit structure from other Classes and Interfaces, ability to inherit data in other Classes. But, there are "Static" Classes in .NET, which behave quite differently, and you should experiment with those to understand how they are different from "regular Classes."
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
i have a datatable with 3 columns Class, Student details, School Name
DataTable dt = new DataTable();
dt.Columns.Add("Class", typeof(System.String));
dt.Columns.Add("Student Details", typeof(System.String));
dt.Columns.Add("School Name", typeof(System.String));
dt.Rows.Add("12", "binod 16 Maths","X");
dt.Rows.Add("12", "Alex 17 History", "Y");
dt.Rows.Add("12", "Sam 18 Biology", "Z");
I want to convert this datatable into this below new datatable where i have splitted the "Student Deatils" column into 3 columns and added the values of this column separted by space in new columsn
dtNew.Columns.Add("Class", typeof(System.String));
dtNew.Columns.Add("Name", typeof(System.String));
dtNew.Columns.Add("Age", typeof(System.String));
dtNew.Columns.Add("Subject", typeof(System.String));
dtNew.Columns.Add("School Name", typeof(System.String));
Class Name Age Subject School Name
12 binod 16 maths X
12 Alex 17 History Y
12 Sam 18 Biology Z
|
|
|
|
|
You have got the general idea right.
Are you facing some issue?
The Copy [^] method might give you some ideas well.
This thread[^] might be useful to you as well.
|
|
|
|
|
Try
System.Data.DataTable dt = new DataTable();
dt.Columns.Add("Class", typeof(System.String));
dt.Columns.Add("Student Details", typeof(System.String));
dt.Columns.Add("School Name", typeof(System.String));
dt.Rows.Add("12", "binod 16 Maths", "X");
dt.Rows.Add("12", "Alex 17 History", "Y");
dt.Rows.Add("12", "Sam 18 Biology", "Z");
DataTable dtNew = new DataTable();
dtNew.Columns.Add("Class", typeof(System.String));
dtNew.Columns.Add("Name", typeof(System.String));
dtNew.Columns.Add("Age", typeof(System.String));
dtNew.Columns.Add("Subject", typeof(System.String));
dtNew.Columns.Add("School Name", typeof(System.String));
foreach (DataRow r in dt.Rows)
{
string details = (string)r[1];
string[] row = details.Split(' ');
dtNew.Rows.Add(r[0], row[0], row[1], row[2], r[2]);
}
foreach (DataRow r in dtNew.Rows)
{
Console.WriteLine(r[0] + " " + r[1] + " " + r[2] + " " + r[3] + " " + r[4]);
}
Console.ReadKey();
I don't speak Idiot - please talk slowly and clearly
"I have sexdaily. I mean dyslexia. Fcuk!"
Driven to the arms of Heineken by the wife
|
|
|
|
|
ihave problem when print datagridview
this coding me
public partial class Form1 : Form
{
PrintDocument dokprint = new PrintDocument();
String koneksidatabase = " Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\DatabaseMDB\\DBSALES.mdb";
public Form1()
{
InitializeComponent();
printDocument1.PrintPage += printDocument1_PrintPage;
----------------------------------------------------------------------------------
private void button2_Click(object sender, EventArgs e)
{
if (TXTBAYAR.Text == "")
{
MessageBox.Show("Please insert Buy");
return;
}
for (int i = 0; i < dataGridView2.Rows.Count; i++)
{
OleDbConnection con = new OleDbConnection(koneksidatabase);
OleDbCommand cmd = new OleDbCommand("insert into Sales ([Kode],[Nama Barang],[Harga],[Quantity],[Satuan],[Subtotal]) values (@Column1,@Column2,@Column3,@Column4,@Column5,@Column6)", con);
cmd.Parameters.AddWithValue("@Kode", dataGridView2.Rows[i].Cells[0].Value);
cmd.Parameters.AddWithValue("@Column2", dataGridView2.Rows[i].Cells[1].Value);
cmd.Parameters.AddWithValue("@Column3", dataGridView2.Rows[i].Cells[2].Value);
cmd.Parameters.AddWithValue("@Column4", dataGridView2.Rows[i].Cells[3].Value);
cmd.Parameters.AddWithValue("@Column5", dataGridView2.Rows[i].Cells[4].Value);
cmd.Parameters.AddWithValue("@Column6", dataGridView2.Rows[i].Cells[5].Value);
OleDbConnection con1 = new OleDbConnection(koneksidatabase);
OleDbCommand cmd1 = new OleDbCommand("insert into DetailSales ([Kode],[Nama Barang],[Harga],[Quantity],[Satuan],[Subtotal],[Total],[Bayar],[Kembalian],[DateTime]) values (@Column1,@Column2,@Column3,@Column4,@Column5,@Column6,@Total,@Bayar,@Kembalian,@DateTime)", con);
cmd1.Parameters.AddWithValue("@Kode", dataGridView2.Rows[i].Cells[0].Value);
cmd1.Parameters.AddWithValue("@Column2", dataGridView2.Rows[i].Cells[1].Value);
cmd1.Parameters.AddWithValue("@Column3", dataGridView2.Rows[i].Cells[2].Value);
cmd1.Parameters.AddWithValue("@Column4", dataGridView2.Rows[i].Cells[3].Value);
cmd1.Parameters.AddWithValue("@Column5", dataGridView2.Rows[i].Cells[4].Value);
cmd1.Parameters.AddWithValue("@Column6", dataGridView2.Rows[i].Cells[5].Value);
cmd1.Parameters.AddWithValue("@Total", txttotal1.Text);
cmd1.Parameters.AddWithValue("@Bayar", TXTBAYAR.Text);
cmd1.Parameters.AddWithValue("@Kembalian", TXTKEMBALIAN.Text);
cmd1.Parameters.AddWithValue("@DateTime", labelJam.Text);
con1.Open();
con.Open();
cmd.ExecuteNonQuery();
cmd1.ExecuteNonQuery();
con.Close();
con1.Close();
}
{
{
printDocument1.Print();(---this error)
dataGridView2.Rows.Clear();
MessageBox.Show("TRANSACTION COMPLITE!", "Complite");
TXTBAYAR.Clear();
TXTTOTAL.Clear();
TXTKEMBALIAN.Clear();
}
}
}
|
|
|
|
|
Looks like you have an issue connecting to the printer.
Look at the error and try to figure out the problem.
Post the error here.
As a side note, add a try catch block to your code to handle the error.
|
|
|
|
|
PrintDocument printdocument1 = new PrintDocument();
String koneksidatabase = " Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\DatabaseMDB\\DBSALES.mdb";
public Form1()
{
InitializeComponent();
printDocument1.PrintPage += printDocument1_PrintPage;
private void button2_Click(object sender, EventArgs e)
{
if (TXTBAYAR.Text == "")
{
MessageBox.Show("Please insert Buy");
return;
}
for (int i = 0; i < dataGridView2.Rows.Count; i++)
{
OleDbConnection con = new OleDbConnection(koneksidatabase);
OleDbCommand cmd = new OleDbCommand("insert into Sales ([Kode],[Nama Barang],[Harga],[Quantity],[Satuan],[Subtotal]) values (@Column1,@Column2,@Column3,@Column4,@Column5,@Column6)", con);
cmd.Parameters.AddWithValue("@Kode", dataGridView2.Rows[i].Cells[0].Value);
cmd.Parameters.AddWithValue("@Column2", dataGridView2.Rows[i].Cells[1].Value);
cmd.Parameters.AddWithValue("@Column3", dataGridView2.Rows[i].Cells[2].Value);
cmd.Parameters.AddWithValue("@Column4", dataGridView2.Rows[i].Cells[3].Value);
cmd.Parameters.AddWithValue("@Column5", dataGridView2.Rows[i].Cells[4].Value);
cmd.Parameters.AddWithValue("@Column6", dataGridView2.Rows[i].Cells[5].Value);
OleDbConnection con1 = new OleDbConnection(koneksidatabase);
OleDbCommand cmd1 = new OleDbCommand("insert into DetailSales ([Kode],[Nama Barang],[Harga],[Quantity],[Satuan],[Subtotal],[Total],[Bayar],[Kembalian],[DateTime]) values (@Column1,@Column2,@Column3,@Column4,@Column5,@Column6,@Total,@Bayar,@Kembalian,@DateTime)", con);
cmd1.Parameters.AddWithValue("@Kode", dataGridView2.Rows[i].Cells[0].Value);
cmd1.Parameters.AddWithValue("@Column2", dataGridView2.Rows[i].Cells[1].Value);
cmd1.Parameters.AddWithValue("@Column3", dataGridView2.Rows[i].Cells[2].Value);
cmd1.Parameters.AddWithValue("@Column4", dataGridView2.Rows[i].Cells[3].Value);
cmd1.Parameters.AddWithValue("@Column5", dataGridView2.Rows[i].Cells[4].Value);
cmd1.Parameters.AddWithValue("@Column6", dataGridView2.Rows[i].Cells[5].Value);
cmd1.Parameters.AddWithValue("@Total", txttotal1.Text);
cmd1.Parameters.AddWithValue("@Bayar", TXTBAYAR.Text);
cmd1.Parameters.AddWithValue("@Kembalian", TXTKEMBALIAN.Text);
cmd1.Parameters.AddWithValue("@DateTime", labelJam.Text);
con1.Open();
con.Open();
cmd.ExecuteNonQuery();
cmd1.ExecuteNonQuery();
con.Close();
con1.Close();
}
{
{
printDocument1.Print();this stetment erorr?
dataGridView2.Rows.Clear();
MessageBox.Show("TRANSACTION COMPLITE!", "Complite");
TXTBAYAR.Clear();
TXTTOTAL.Clear();
TXTKEMBALIAN.Clear();
}
}
}
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
Font print10B = new Font("Lucida Console", 10, FontStyle.Bold);
Font print8B = new Font("Arial", 9, FontStyle.Regular);
Font print6B = new Font("Arial", 8, FontStyle.Regular);
e.Graphics.DrawString("" + labelSTORE.Text + "'", print6B, Brushes.Black, 69, 20);
//e.Graphics.DrawString("" + labeladdress.Text + "'", print6B, Brushes.Black, 25, 30);
e.Graphics.DrawString("--------------------------------------------------- ", new Font(dataGridView2.Font.FontFamily, 10, FontStyle.Regular), Brushes.Black, 10, 35);
e.Graphics.DrawString(" Kasir :" + labelKASIR.Text + "'", print6B, Brushes.Black, 2, 50);
e.Graphics.DrawString("" + DateTime.Now.ToString("MM/dd/yyyy" + "-HH:mm:ss") + "'", print6B, Brushes.Black, 130, 50);
e.Graphics.DrawString("----------------------------------------------------", new Font(dataGridView2.Font.FontFamily, 10, FontStyle.Regular), Brushes.Black, 10, 60);
//e.Graphics.DrawString(" kode| Nama Barang | Harga | qty ", print6B, Brushes.Black, 6, 70);
int height = 0;
int x = 10;
for (int i = 0; i < dataGridView2.Rows.Count; i++)
{
e.Graphics.DrawString(dataGridView2.Rows[i].Cells[0].Value.ToString(), print6B, Brushes.Black, x, 70 + height);
e.Graphics.DrawString(dataGridView2.Rows[i].Cells[1].Value.ToString(), print6B, Brushes.Black, x + 50, 70 + height);
e.Graphics.DrawString(dataGridView2.Rows[i].Cells[2].Value.ToString(), print6B, Brushes.Black, x + 120, 70 + height);
// e.Graphics.DrawString("Rp,", print6B, Brushes.Black, x + 113, 70 + height);
e.Graphics.DrawString(dataGridView2.Rows[i].Cells[3].Value.ToString(), print6B, Brushes.Black, x + 170, 70 + height);
// e.Graphics.DrawString("=", print6B, Brushes.Black, x + 192, 70 + height);
e.Graphics.DrawString(dataGridView2.Rows[i].Cells[4].Value.ToString(), print6B, Brushes.Black, x + 180, 70 + height);
e.Graphics.DrawString(dataGridView2.Rows[i].Cells[5].Value.ToString(), print6B, Brushes.Black, x + 230, 70 + height);
height += 20;
}
{
{
e.Graphics.DrawString("--------------------------------------------------------------------------", print6B, Brushes.Black, x + 0, 60 + height);
e.Graphics.DrawString("Total :Rp, " + txttotal1.Text + "'", print6B, Brushes.Black, x + 0, 70 + height);
e.Graphics.DrawString("Bayar :Rp, " + TXTBAYAR.Text + "'", print6B, Brushes.Black, x + 0, 80 + height);
//e.Graphics.DrawString("Discount :" + 0 + "'", print6B, Brushes.Black, x + 0, 90 + height);
e.Graphics.DrawString("Kembali :Rp, " + TXTKEMBALIAN.Text + "'", print6B, Brushes.Black, x + 0, 90 + height);
e.Graphics.DrawString("--------------------------------------------------------------------------", print6B, Brushes.Black, x + 0, 110 + height);
e.Graphics.DrawString("Barang yang sudah di beli tidak dapat", print6B, Brushes.Black, x + 15, 120 + height);
e.Graphics.DrawString(" di kembalikan ", print6B, Brushes.Black, x + 70, 130 + height);
e.Graphics.DrawString("***Terima kasih***", print8B, Brushes.Black, x + 55, 140 + height);
}
}
}
}
}
|
|
|
|
|
It may be just me, but that doesn't look like an error message.
|
|
|
|
|
I have the same problem.
I describe the issue:
The process that not work sometimes is a MTA Process it have that code:
Protected Friend Function PrintCustomDriver(printerSetting As PrinterSettingsAvanzada) As Boolean
Dim sucess As Boolean = True
Dim impresoradefecto As String = HumanoSoftware.Helpers.WindowUtil.GetDefaultPrinter
Try
Using document = PdfiumViewer.PdfDocument.Load(path)
Using printDocument = document.CreatePrintDocument()
Dim printerDuplicado As PrinterSettingsAvanzada = printerSetting.Clone
printerDuplicado.Copies = 1
printDocument.PrinterSettings = printerDuplicado
printDocument.PrintController = New System.Drawing.Printing.StandardPrintController()
For indice As Integer = 0 To printerSetting.Copies - 1
printDocument.Print()
Next
End Using
End Using
Catch ex As Exception
Logger.EscribirException(ex)
sucess = False
Finally
HumanoSoftware.Helpers.WindowUtil.SetDefaultPrinter(impresoradefecto)
End Try
Return sucess
End Function
Normally it works fine, However, sometimes throw that exception:
Quote: [33][10/03/2022][10:23:23:170][ERROR][. Un componente externo produjo una excepción.. en PdfiumViewer.NativeMethods.Imports.FPDF_RenderPage(IntPtr dc, IntPtr page, Int32 start_x, Int32 start_y, Int32 size_x, Int32 size_y, Int32 rotate, FPDF flags)
en PdfiumViewer.NativeMethods.FPDF_RenderPage(IntPtr dc, IntPtr page, Int32 start_x, Int32 start_y, Int32 size_x, Int32 size_y, Int32 rotate, FPDF flags)
en PdfiumViewer.PdfFile.RenderPDFPageToDC(Int32 pageNumber, IntPtr dc, Int32 dpiX, Int32 dpiY, Int32 boundsOriginX, Int32 boundsOriginY, Int32 boundsWidth, Int32 boundsHeight, FPDF flags)
en PdfiumViewer.PdfDocument.Render(Int32 page, Graphics graphics, Single dpiX, Single dpiY, Rectangle bounds, PdfRenderFlags flags)
en PdfiumViewer.PdfPrintDocument.RenderPage(PrintPageEventArgs e, Int32 page, Double left, Double top, Double width, Double height)
en PdfiumViewer.PdfPrintDocument.PrintSinglePage(PrintPageEventArgs e)
en PdfiumViewer.PdfPrintDocument.OnPrintPage(PrintPageEventArgs e)
en System.Drawing.Printing.PrintDocument._OnPrintPage(PrintPageEventArgs e)
en System.Drawing.Printing.PrintController.PrintLoop(PrintDocument document)
en System.Drawing.Printing.PrintController.Print(PrintDocument document)
en System.Drawing.Printing.PrintDocument.Print()
en HumanoSoftware.GestorDocumental.Pdf.Documento.ImprimirCustomDriver(PrinterSettingsAvanzada printerSetting)Line number
Column
]
I don't understand witch are the reasons of the exception
Thanks in advance.
|
|
|
|
|
I couldn't tell you. The first thing I would look for is an InnerException in the exception that you get.
|
|
|
|
|
Hi all
im trying to do a assignment for programing and i cant get my program to do give me the output as described below
Program description:
Develop a program to implement a billing system for an electricity supply company. The billing program will gather information about each customer’s name, customer number, address, whether they are on Standard rates or Peak/Off Peak rates, and how much electricity they have consumed. Once all customer details have been entered it will allow electricity consumption data to be entered for all customers. It will then allow the bill for all customers to be calculated (including a 10% Goods and Service Tax) and display the results. It will also calculate and display the average energy usage per customer and the average bill per customer.
The program is required to hold data for up a maximum of 50 customers. Note, however, that this number may be revised in the future so your program should allow for this to be easily re-coded.
The program must operate via a menu system. The menu to control the program should be as follows:
Add a Customer Record (a)
Find a Customer Record (f)
Update a Customer Record (u)
Enter Electricity Consumption data (e)
Calculate Bills (b)
Clear Consumption data (c)
Exit (x)
The program must display the menu and wait for the user’s response and process the options entered until the user enters 'x' to quit. Menu option entries may be in upper or lower case. Use a switch statement to organise the code to suit the option selected.
Details of the menu options are as follows:
Add a customer record:
Prompt the user for the customer number, customer’s name, address and whether they are on standard rates or Peak/Off Peak rates and then store the entered data into the next array position.
All of these fields are compulsory and so must not be left blank.
Find a customer record:
Prompt for the name of the customer to search for.
· The user may enter all or part of the name.
· Search through all of the customer names until a match is found and return the customer number of the person found.
· Display the customer record found, including details of electricity consumption.
Update a Customer Record:
First perform a find (see above) to display the required record and then display the fields one at a time, each time asking the user if they wish to enter a new value or not. For example:
Customer name > Freddie Krueger
Update this information (Y or N)> Y
Enter new customer name > Frederick Krueger
Enter Electricity Consumption data:
This option will list ALL customers, one at a time, each time prompting the user to enter the electricity consumption data for that customer. If the customer is on Peak/Off Peak rates then the system will prompt separately for both Peak electricity consumption and Off Peak consumption, otherwise it will prompt only for total electricity consumption.
Calculate Bills:
This option will list ALL customers, one at a time, each time displaying the customer details and the bill as calculated based on consumption data that has been entered. The calculation of the bill is based on the following:
· Consumption at the Standard Rate is billed at $0.32 per Kilowatt Hour.
· Consumption at the Peak Rate is billed $0.50 per Kilowatt Hour.
· Consumption at the Off Peak Rate is billed at $0.18 per Kilowatt Hour.
· After calculating the amount of the bill a Goods and Services Tax of 10% is then added to the bill.
Once all customers’ bills have been processed the average bill per customer and the average electricity consumption per customer (in Kilowatt Hours) should be calculated and displayed.
Note: This option should only be accessible after electricity consumption data has been entered.
Clear Consumption data:
This option will go through all customer records and reset the electricity usage data to 0 in preparation for entering new data for the next billing period. Note that all other customer details must remain unaltered in this process.
Here's my code
// start of code
using System;
namespace ass1
{
class Bill
{
// Display menu and get response
static char get_menu()
{
char response;
Console.WriteLine("Add a Customer Record (a)");
Console.WriteLine("Find a Customer Record (f)");
Console.WriteLine("Update a Customer Record (u)");
Console.WriteLine("Enter Electricity Consumption data (e)");
Console.WriteLine("Calculate Bills (b)");
Console.WriteLine("Clear Consumption data (c)");
Console.WriteLine("Exit (x)");
response = char.Parse(Console.ReadLine());
return response;
}
// Find a Cusotmer Number based on giving the customer number
static int Customer_no(string[] records, int current_count, int CustomerNumbers_entered)
{
string find_data = "";
int item = 0;
bool found = false;
Console.Write("Customer Number: > ");
find_data = Console.ReadLine();
for (item = 0; item < CustomerNumbers_entered; item++)
{
if (records[item] == find_data)
{
current_count = item;
found = true;
break;
}
}
if (found == false)
Console.WriteLine("No Customer Information found");
else
Console.WriteLine("Customer Information found");
return current_count;
}
static float get_float(string prompt, float min)
{
string vtemp = "";
while (Attempt == false)
{
}
}
static void Main(string[] args)
{
// Declare and initialise variables and constants
// Constants
const int MAX_Cusomter = 50;
// Variables
const float PEEK_RATE = 0.50F;
const float OFF_PEAK_RATE = 0.18F;
const float STANDARD_RATE = 0.32F;
const float GST_RATE = 0.10F;
const string PEAK_SYM = "P";
const string STANDARD_SYM = "S";
// Customer variables
string[] Customer_no;
Customer_no = new string[MAX_Cusomter];
string[] CustomerNumber;
CustomerNumber = new string[MAX_Cusomter];
string[] CustomerName;
CustomerName = new string[MAX_Cusomter];
string[] Address;
Address = new string[MAX_Cusomter];
string[] RateType;
RateType = new string[MAX_Cusomter];
float PeakKWH = 0.0F;
float OffPeakKWH = 0.0F;
float TotalStandardPeakKWH = 0.0F;
// Ttrack the total and averages
float TotalBilled = 0.0F;
float TotalUsage = 0.0F;
float AverageBilled = 0.0F;
float AverageUsage = 0.0F;
// Count the number of valid customers
int CustomerCount = 0;
// Calculation variables
float PeakCharge = 0.0F;
float OffPeakCharge = 0.0F;
float TotalCharge = 0.0F;
float TotalPlusGST = 0.0F;
int current_count = 0;
int number_of_customers = 0;
//Temp variables
string inputStr = "";
bool parseAttempt = false;
char response = ' ';
while (response != 'x')
{
response = get_menu();
switch (response)
{
case 'a':
// Initialise
// INPUT
// Set the variable defaults
CustomerNumber[current_count] = "";
CustomerName[current_count] = "";
Address[current_count] = "";
RateType[current_count] = "";
PeakKWH = 0.0F;
OffPeakKWH = 0.0F;
TotalStandardPeakKWH = 0.0F;
// Get the Customer Number and exit is an error is detected
break;
case 'f':
// Find a cutomer Recored
current_count = find_data(records, current_count, CustomerNumbers_entered);
break;
case 'u':
// Update a customer recorded
if (CustomerNumber[Customer_no] == "")
{
Console.WriteLine("Update Info for new Customer >");
Customer_no [CustomerNumber] = Console.ReadLine();
if (Customer_no[CustomerNumber] == "")
{
Console.WriteLine("Error : Customer Number cannot be empty,");
}
// Get the Customer Name and exit is an error is detected
while (CustomerNumber[Customer_no] == "")
{
Console.Write("Customer Name > ");
CustomerName[Customer_no] = Console.ReadLine();
if (CustomerNumber[Customer_no] == "")
{
Console.WriteLine("Error : Customer Name cannot be empty,");
}
}
// Get the Customer Address and exit is an error is detected
while (Address[Customer_no] == "")
{
Console.Write("Address > ");
Address[Customer_no] = Console.ReadLine();
if (Address[Customer_no] == "")
{
Console.WriteLine("Error : Address cannot be empty,");
}
}
}
break;
case 'e':
// Get the Rate Type and exit is an error is detected
while (RateType[Customer_no] != PEAK_SYM && RateType[Customer_no] != STANDARD_SYM)
{
Console.Write("Standard Rate (S) or Peak/Off Peak (P) >");
RateType[Customer_no] = Console.ReadLine().ToUpper();
if (RateType[Customer_no] != PEAK_SYM && RateType[Customer_no] != STANDARD_SYM)
{
Console.WriteLine("Error : The Rate Type must be either S or P.");
}
}
// If Rate Type is P prompt for the usage
if (RateType[Customer_no] == PEAK_SYM)
{
parseAttempt = false;
while (parseAttempt == false)
{
// Peak Usage data
Console.Write("Peak Usage (kWh) > ");
inputStr = Console.ReadLine();
parseAttempt = float.TryParse(inputStr, out PeakKWH);
// Ensure the value entered is a valid numeric value
if (parseAttempt == false)
{
Console.WriteLine("Error : Peak Usage must be a valid numeric value.");
parseAttempt = false;
}
// Ensure the value entered is > 0
if (PeakKWH < 0)
{
Console.WriteLine("Error : Peak Usage must be a valid numeric value greater than or equal to 0.");
parseAttempt = false;
}
}
parseAttempt = false;
while (parseAttempt == false)
{
Console.Write("Off Peak Usage (kWh) > ");
inputStr = Console.ReadLine();
parseAttempt = float.TryParse(inputStr, out OffPeakKWH);
// Ensure the value entered is a valid numeric value
if (parseAttempt == false)
{
Console.WriteLine("Error : Off Peak Usage must be a valid numeric value.");
parseAttempt = false;
}
// Ensure the value entered is > 0
if (OffPeakKWH < 0)
{
Console.WriteLine("Error : Off Peak Usage must be a valid numeric value greater than or equal to 0.");
parseAttempt = false;
}
}
}
else // If Rate Type is S prompt for the usage
{
parseAttempt = false;
while (parseAttempt == false)
{
// Standard Usage data
Console.Write("Total Usage (kWh) > ");
inputStr = Console.ReadLine();
parseAttempt = float.TryParse(inputStr, out TotalStandardPeakKWH);
// Ensure the value entered is a valid numeric value
if (parseAttempt == false)
{
Console.WriteLine("Error : Total Usage must be a valid numeric value.");
parseAttempt = false;
}
// Ensure the value entered is > 0
if (TotalStandardPeakKWH < 0)
{
Console.WriteLine("Error : Total Usage must be a valid numeric value greater than or equal to 0.");
parseAttempt = false;
}
}
}
break;
case 'b':
// PROCESS the calculations
if (TotalCharge == 0)
{
Console.Write("Warrning need no Cutomer in the System");
inputStr = Console.ReadLine();
}
else
if (RateType[current_count] == PEAK_SYM)
{
PeakCharge = PeakKWH * PEEK_RATE;
OffPeakCharge = OffPeakKWH * OFF_PEAK_RATE;
TotalCharge = PeakCharge + OffPeakCharge;
// Keep track of the usage
TotalUsage = TotalUsage + (PeakKWH + OffPeakKWH);
}
else
{
TotalCharge = TotalStandardPeakKWH * STANDARD_RATE;
// Keep track of the usage
TotalUsage = TotalUsage + TotalStandardPeakKWH;
}
TotalPlusGST = TotalCharge + TotalCharge * GST_RATE;
// Keep track of the total billed
TotalBilled = TotalBilled + TotalPlusGST;
// Ad 1 to the customer count
Customer_no = CustomerNumber + 1;
// Calculate the averages only if the count is > 0
if (CustomerNumber > 0)
{
AverageBilled = TotalBilled / CustomerNumber[current_count];
AverageUsage = TotalUsage / CustomerNumber[current_count];
// Display the averages
Console.WriteLine("Average amount billed is {0:C}.", AverageBilled);
Console.WriteLine("Average consumption per customer is {0:C}.", AverageUsage);
}
else
Console.WriteLine("No Customer data entered.");
Console.ReadLine();
// OUTPUT the customer information and bill
Console.WriteLine("===================================");
Console.WriteLine("Electricity Bill for Customer {0}", CustomerNumber);
Console.WriteLine("===================================");
Console.WriteLine("Name : {0}", CustomerName);
Console.WriteLine("Address : {0}", Address);
if (RateType[current_count] == PEAK_SYM)
{
Console.WriteLine("Peak : {0,7:C}", PeakCharge);
Console.WriteLine("Off Peak : {0,7:C}", OffPeakCharge);
}
Console.WriteLine("Total : {0,7:C}", TotalCharge);
Console.WriteLine();
Console.WriteLine("Including GST : {0,7:C}", TotalPlusGST);
Console.WriteLine("===================================");
// End While
Console.WriteLine();
break;
case 'c':
// Initialise
PeakCharge = 0.0F;
OffPeakCharge = 0.0F;
TotalCharge = 0.0F;
TotalPlusGST = 0.0F;
TotalBilled = 0.0F;
TotalUsage = 0.0F;
AverageBilled = 0.0F;
AverageUsage = 0.0F;
break;
case 'x':
break;
default:
Console.WriteLine("Unknown menu selection");
break;
}
}
}
}
}
//end of code
I am very confused with the code and i'm not sure what i'm doing wrong,i'm not to be able to display what i need as a output.
Any help or suggestions are greatly appreciated.
Regards Brendan
|
|
|
|
|
Stepping through your code while debugging might give you an idea on what this code is doing.
|
|
|
|
|
I'm not going to look at that - it's a code dump, and pretty much unreadable without formatting.
So start like this: edit your question, cut it down to just the relevant bits, and enclose them in <pre> tags, by highlighting it, and using the "code" widget on the toolbar above the textbox.
That will keep the indentation and engage the syntax highlighter, which makes it a lot easier for us to read. It changes this:
// Get the Customer Name and exit is an error is detected
while (CustomerNumber[Customer_no] == "")
{
Console.Write("Customer Name > ");
CustomerName[Customer_no] = Console.ReadLine();
if (CustomerNumber[Customer_no] == "")
{
Console.WriteLine("Error : Customer Name cannot be empty,");
}
}
To this:
while (CustomerNumber[Customer_no] == "")
{
Console.Write("Customer Name > ");
CustomerName[Customer_no] = Console.ReadLine();
if (CustomerNumber[Customer_no] == "")
{
Console.WriteLine("Error : Customer Name cannot be empty,");
}
} which is much, much easier to follow - especially when it is part of a larger context.
Then, drop the homework question at the top, and tell use what you expect the code to do and what it is doing that you didn't expect, or not doing that you did - and how you get it to do that. Remember, we can't see your screen!
Then we might be able to help you more easily - help us to help you!
The only instant messaging I do involves my middle finger.
|
|
|
|
|
Okay, so here's what I understand about Destructors…
They are mainly used to help clear up any resources with unmanaged i.e. code, streams, certain type of events etc.
I also understand you put it inside your class at the very bottom preceded with a tilde, same name as the class… No modifiers of any kind.
Here is where I'm a little confused; in the example's I was given… It has just this and nothing else:
~MyClass
{
}
Will it work "good enough", without adding any "destruction statements"?
Or…
Should I be entering some statements to make sure it's taken care of?
|
|
|
|
|
You do know this is a C++ question, not a C# one, right?
But to answer the question, it's OK to have an empty destructor if you don't have any resources to clean up.
In fact, if your class definition lacks a destructor of any kind, the compiler generates one for you which does nothing.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
it is not a C++ question!
|
|
|
|
|
I apologize for my ignorance.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Not exactly true...
Read this[^]
|
|
|
|
|
Well I'll be a monkey's uncle!
Thank you for correcting me.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
If you are its uncle, I'm its cousin twice removed.
TIL the c++ destructor syntax is valid in c#
|
|
|
|
|
"Empty destructors should not be used. When a class contains a destructor, an entry is created in the Finalize queue. When the destructor is called, the garbage collector is invoked to process the queue. If the destructor is empty, this just causes a needless loss of performance." - http://msdn.microsoft.com/en-us/library/66x5fx1b.aspx
TY!
|
|
|
|
|