• No se han encontrado resultados

INSTITUCIONES DESCENTRALIZADAS

PUBLICACIÓN DE PRIMERA VEZ

102

Coding

public partial class Edit_Reservation : Form

{

int temp = 0;

restdatabaseDataSet ds = new restdatabaseDataSet();

restdatabaseDataSetTableAdapters.ReservationTableAdapter ta = new

restdatabaseDataSetTableAdapters.ReservationTableAdapter(); int pos; public Edit_Reservation() { InitializeComponent(); }

private void Edit_Reservation_Load(object sender, EventArgs e) {

// TODO: This line of code loads data into the 'restdatabaseDataSet.Reservation' table. You can move, or remove it, as needed.

this.reservationTableAdapter.Fill(this.restdatabaseDataSet.Reservation);

// TODO: This line of code loads data into the 'restdatabaseDataSet.Customer' table. You can move, or remove it, as needed.

this.customerTableAdapter.Fill(this.restdatabaseDataSet.Customer); }

public void receive(string rid) {

ta.Fill(ds.Reservation);

for (int i = 0; i <= ds.Reservation.Rows.Count - 1; i++) {

if (rid == ds.Reservation.Rows[i]["reservationID"].ToString()) {

textBoxreservationid.Text = ds.Reservation.Rows[i]["reservationid"].ToString();

comboBoxoccasion.SelectedItem = ds.Reservation.Rows[i]["type"].ToString(); textBoxgathering.Text = ds.Reservation.Rows[i]["noofpeople"].ToString(); comboBoxcustid.SelectedItem =

ds.Reservation.Rows[i]["customer_id"].ToString(); dateTimePickerdob.Value =

Convert.ToDateTime(ds.Reservation.Rows[i]["dateofbooking"]);

textBoxadvance.Text = ds.Reservation.Rows[i]["advance"].ToString();

textBoxsplinst.Text = ds.Reservation.Rows[i]["splinstruction"].ToString(); comboBoxstatus.SelectedItem = ds.Reservation.Rows[i]["status"].ToString(); comboBoxspot.SelectedItem = ds.Reservation.Rows[i]["location"].ToString(); pos = i;

break; }

} }

private void buttonedit_Click(object sender, EventArgs e) { textBoxreservationid.ReadOnly = true; comboBoxoccasion.Enabled = true; textBoxgathering.ReadOnly = false; comboBoxcustid.Enabled = false; dateTimePickerdob.Enabled = true; textBoxadvance.ReadOnly = false; textBoxsplinst.ReadOnly = false;

103

comboBoxstatus.Enabled = true; comboBoxspot.Enabled = true; }

private void buttonsave_Click(object sender, EventArgs e) { try { if ((comboBoxoccasion.SelectedIndex == -1) || (textBoxgathering.Text == "") || (comboBoxcustid.SelectedIndex == -1) || (comboBoxspot.SelectedIndex == -1)) {

MessageBox.Show(" Fields Marked * Are Mandatory"); }

else if (!int.TryParse(textBoxadvance.Text, out temp) == true) {

MessageBox.Show("Invalid Advance Amount"); } else { DataRow dr; dr = this.restdatabaseDataSet.Reservation.Rows[pos]; dr.BeginEdit(); //dr["reservationid"]=textBoxreservationid.Text; dr["type"] = comboBoxoccasion.SelectedItem; dr["noofpeople"] = textBoxgathering.Text; //dr["customer_id"] = comboBoxcustid.SelectedItem; dr["dateofbooking"] = dateTimePickerdob.Value.ToShortDateString(); dr["advance"] = textBoxadvance.Text; dr["splinstruction"] = textBoxsplinst.Text; dr["status"] = comboBoxstatus.SelectedItem; dr["location"] = comboBoxspot.SelectedItem; dr.EndEdit();

this.reservationTableAdapter.Update(this.restdatabaseDataSet.Reservation); MessageBox.Show("Reservation Updated");

this.reservationTableAdapter.Fill(this.restdatabaseDataSet.Reservation); textBoxreservationid.ReadOnly = true; comboBoxoccasion.Enabled = false; textBoxgathering.ReadOnly = true; comboBoxcustid.Enabled = false; dateTimePickerdob.Enabled = false; textBoxadvance.ReadOnly = true; textBoxsplinst.ReadOnly = true; comboBoxstatus.Enabled = false; comboBoxspot.Enabled = false; } }

catch (Exception ex) {

MessageBox.Show(ex.Message); }

} }

104

105

Coding

public partial class Billing : Form

{

double totalprice, totalvat, amountpayable,discount; int srno = 1;

restdatabaseDataSet ds = new restdatabaseDataSet();

restdatabaseDataSetTableAdapters.listofitemsTableAdapter ta = new

restdatabaseDataSetTableAdapters.listofitemsTableAdapter(); int pos = -1;

int temp1 = 0, temp2 = 0;

restdatabaseDataSetTableAdapters.bill_tableTableAdapter ta1 = new

restdatabaseDataSetTableAdapters.bill_tableTableAdapter();

restdatabaseDataSetTableAdapters.bill_detailTableAdapter ta2 = new

restdatabaseDataSetTableAdapters.bill_detailTableAdapter();

restdatabaseDataSetTableAdapters.CustomerTableAdapter ta3 = new

restdatabaseDataSetTableAdapters.CustomerTableAdapter(); restdatabaseDataSet dsc = new restdatabaseDataSet();

restdatabaseDataSetTableAdapters.homedeliveryTableAdapter ta4 = new

restdatabaseDataSetTableAdapters.homedeliveryTableAdapter(); public Billing()

{

InitializeComponent(); }

private void buttonadd_Click(object sender, EventArgs e) {

try

{

ta.Fill(ds.listofitems); int flag = 0;

for (int i = 0; i <= ds.listofitems.Rows.Count - 1; i++) {

if (textBoxitemcode.Text == ds.listofitems.Rows[i]["item_code"].ToString()) { flag = 1; pos = i; break; } } if ((textBoxitemcode.Text == "") || (textBoxquantity.Text == "")) {

MessageBox.Show("Invalid Item Code or Quantity"); }

else if ((!int.TryParse(textBoxitemcode.Text, out temp1) == true) || (!int.TryParse(textBoxquantity.Text, out temp2) == true))

{

MessageBox.Show("Item Code and Quantity should be Numeric"); }

else if (flag == 0) {

MessageBox.Show("Invalid Item Code"); }

else

{

ListViewItem lt = new ListViewItem(srno.ToString());

106

lt.SubItems.Add(ds.listofitems.Rows[pos]["item_name"].ToString()); lt.SubItems.Add(ds.listofitems.Rows[pos]["price"].ToString()); lt.SubItems.Add(textBoxquantity.Text);

double vat, p;

vat = Convert.ToDouble(ds.listofitems.Rows[pos]["price"]) *

Convert.ToDouble(ds.listofitems.Rows[pos]["tax"]) / 100; lt.SubItems.Add(vat.ToString());

p = (Convert.ToDouble(ds.listofitems.Rows[pos]["price"]) +

Convert.ToDouble(vat)) * Convert.ToDouble(textBoxquantity.Text); lt.SubItems.Add(p.ToString()); listViewbilling.Items.Add(lt); updatebill(); srno = srno + 1; } }

catch (Exception ex) {

MessageBox.Show(ex.Message); }

}

private void buttonremove_Click(object sender, EventArgs e) { try { if (listViewbilling.Items.Count > 0) { if (listViewbilling.SelectedItems.Count > 0) { listViewbilling.Items.RemoveAt(listViewbilling.SelectedIndices[0]); serialgen(); updatebill(); } } }

catch (Exception ex) {

MessageBox.Show(ex.Message); }

}

public void serialgen() {

for (int i = 0; i <= listViewbilling.Items.Count - 1; i++) {

listViewbilling.Items[i].Text = Convert.ToString(i + 1); }

srno = listViewbilling.Items.Count + 1; }

public void updatebill() {

totalprice = 0; totalvat = 0; amountpayable = 0;

for (int i = 0; i <= listViewbilling.Items.Count - 1; i++) {

107

totalprice = totalprice + (Convert.ToDouble(listViewbilling.Items[i].SubItems[3].Text) * Convert.ToDouble(listViewbilling.Items[i].SubItems[4].Text)); totalvat = totalvat + (Convert.ToDouble(listViewbilling.Items[i].SubItems[5].Text) * Convert.ToDouble(listViewbilling.Items[i].SubItems[4].Text)); amountpayable = amountpayable + Convert.ToDouble(listViewbilling.Items[i].SubItems[6].Text); } textBoxtotalprice.Text = totalprice.ToString(); textBoxtotalvat.Text = totalvat.ToString(); textBoxpayableamount.Text = amountpayable.ToString(); }

private void Billing_Load(object sender, EventArgs e) {

// TODO: This line of code loads data into the 'restdatabaseDataSet.Customer' table. You can move, or remove it, as needed.

// this.customerTableAdapter.Fill(this.restdatabaseDataSet.Customer);

textBoxdateofbilling.Text = DateTime.Now.ToShortDateString(); ta1.Fill(ds.bill_table);

ta2.Fill(ds.bill_detail);

if (ds.bill_table.Rows.Count == 0) {

textBoxbillno.Text = Convert.ToString(1000); }

else

{

int x;

x = Convert.ToInt32(ta1.ScalarQuery()); textBoxbillno.Text = Convert.ToString(x + 1); }

}

private void buttoncheckout_Click(object sender, EventArgs e) { try { if (radioButtonwalkin.Checked == true ) { buttoncheckout.Enabled = true; DataRow drbill_table; DataRow drbill_detail; if (listViewbilling.Items.Count == 0) {

MessageBox.Show("Empty Bill"); }

else

{

drbill_table = ds.bill_table.NewRow(); drbill_table["billno"] = textBoxbillno.Text;

drbill_table["dateofbilling"] = textBoxdateofbilling.Text; drbill_table["totalprice"] = textBoxtotalprice.Text; drbill_table["totalvat"] = textBoxtotalvat.Text; drbill_table["discount"] = textBoxdiscount.Text;

108

drbill_table["amt_payable"] = textBoxpayableamount.Text; ds.bill_table.Rows.Add(drbill_table);

for (int i = 0; i <= listViewbilling.Items.Count - 1; i++) {

drbill_detail = ds.bill_detail.NewRow();

drbill_detail["srno"] = listViewbilling.Items[i].Text; drbill_detail["billno"] = textBoxbillno.Text;

drbill_detail["item_code"] = listViewbilling.Items[i].SubItems[1].Text;

drbill_detail["item_name"] = listViewbilling.Items[i].SubItems[2].Text;

drbill_detail["price"] = listViewbilling.Items[i].SubItems[3].Text; drbill_detail["quantity"] =

listViewbilling.Items[i].SubItems[4].Text;

drbill_detail["vat"] = listViewbilling.Items[i].SubItems[5].Text; drbill_detail["total"] = listViewbilling.Items[i].SubItems[6].Text; ds.bill_detail.Rows.Add(drbill_detail); } ta1.Update(ds.bill_table); ta2.Update(ds.bill_detail); ta1.Fill(ds.bill_table); ta2.Fill(ds.bill_detail); MessageBox.Show("Bill Raised");

printPreviewDialog1.Document = printDocument1; printPreviewDialog1.ShowDialog(); listViewbilling.Items.Clear(); textBoxitemcode.Text = ""; textBoxquantity.Text = ""; textBoxtotalprice.Text = ""; textBoxtotalvat.Text = ""; textBoxpayableamount.Text = ""; textBoxitemcode.Focus();

textBoxdateofbilling.Text = DateTime.Now.ToShortDateString(); ta1.Fill(ds.bill_table);

ta2.Fill(ds.bill_detail);

if (ds.bill_table.Rows.Count == 0) {

textBoxbillno.Text = Convert.ToString(1000); }

else

{

int x;

x = Convert.ToInt32(ta1.ScalarQuery()); textBoxbillno.Text = Convert.ToString(x + 1); }

} }

109

else if (rbhomedelivery.Checked == true ) {

if ((radioButtoncustid.Checked == true || radioButtonphoneno.Checked == true

) && textBoxsearch.Text == "") {

MessageBox.Show("Enter Search Criteria"); } else { DataRow drbill_table; DataRow drbill_detail; if (listViewbilling.Items.Count == 0) {

MessageBox.Show("Empty Bill"); }

else

{

drbill_table = ds.bill_table.NewRow(); drbill_table["billno"] = textBoxbillno.Text;

drbill_table["dateofbilling"] = textBoxdateofbilling.Text; drbill_table["totalprice"] = textBoxtotalprice.Text; drbill_table["totalvat"] = textBoxtotalvat.Text; drbill_table["discount"] = textBoxdiscount.Text;

drbill_table["amt_payable"] = textBoxpayableamount.Text; ds.bill_table.Rows.Add(drbill_table);

for (int i = 0; i <= listViewbilling.Items.Count - 1; i++) {

drbill_detail = ds.bill_detail.NewRow();

drbill_detail["srno"] = listViewbilling.Items[i].Text; drbill_detail["billno"] = textBoxbillno.Text;

drbill_detail["item_code"] = listViewbilling.Items[i].SubItems[1].Text;

drbill_detail["item_name"] = listViewbilling.Items[i].SubItems[2].Text;

drbill_detail["price"] = listViewbilling.Items[i].SubItems[3].Text; drbill_detail["quantity"] =

listViewbilling.Items[i].SubItems[4].Text;

drbill_detail["vat"] = listViewbilling.Items[i].SubItems[5].Text; drbill_detail["total"] = listViewbilling.Items[i].SubItems[6].Text; ds.bill_detail.Rows.Add(drbill_detail); } DataRow drhd; drhd = ds.homedelivery.NewRow(); drhd["cust_name"] = textBoxcustname.Text; drhd["address"] = textBoxaddress.Text; drhd["phone"] = textBoxphoneno.Text; drhd["billno"] = textBoxbillno.Text; ds.homedelivery.Rows.Add(drhd); ta1.Update(ds.bill_table); ta2.Update(ds.bill_detail); ta4.Update(ds.homedelivery);

110

ta1.Fill(ds.bill_table); ta2.Fill(ds.bill_detail); ta4.Fill(ds.homedelivery); MessageBox.Show("Bill Raised");

printPreviewDialog1.Document = printDocument1; printPreviewDialog1.ShowDialog(); listViewbilling.Items.Clear(); textBoxitemcode.Text = ""; textBoxquantity.Text = ""; textBoxtotalprice.Text = ""; textBoxtotalvat.Text = ""; textBoxpayableamount.Text = ""; textBoxsearch.Text = ""; textBoxcustname.Text = ""; textBoxaddress.Text = ""; textBoxphoneno.Text = ""; textBoxitemcode.Focus();

textBoxdateofbilling.Text = DateTime.Now.ToShortDateString(); ta1.Fill(ds.bill_table);

ta2.Fill(ds.bill_detail); ta4.Fill(ds.homedelivery);

if (ds.bill_table.Rows.Count == 0) {

textBoxbillno.Text = Convert.ToString(1000); }

else

{

int x;

x = Convert.ToInt32(ta1.ScalarQuery()); textBoxbillno.Text = Convert.ToString(x + 1); } } } } else {

MessageBox.Show("Select Type of Customer"); }

}

catch (Exception ex) {

MessageBox.Show(ex.Message); }

}

private void radioButtonwalkin_CheckedChanged(object sender, EventArgs e) { if (radioButtonwalkin.Checked == true) { panel1.Visible = false; } }

111

private void rbhomedelivery_CheckedChanged(object sender, EventArgs e) { if (rbhomedelivery.Checked == true) { panel1.Visible = true; } }

private void buttonsearch_Click(object sender, EventArgs e) { try { //DataRow drcust; if (radioButtoncustid.Checked == true) { string n; n = Convert.ToString(textBoxsearch.Text); ta3.Fill(dsc.Customer);

int i, count, pos = -1;

count = dsc.Customer.Rows.Count; for (i = 0; i <= count - 1; i++) {

if (dsc.Customer.Rows[i]["customer_id"].ToString() == n) { pos = i; break; } } if (pos == -1) {

MessageBox.Show("No Customer Record Found"); }

else

{

textBoxcustname.Text = dsc.Customer.Rows[pos]["cust_name"].ToString(); textBoxaddress.Text = dsc.Customer.Rows[pos]["address"].ToString(); textBoxphoneno.Text = dsc.Customer.Rows[pos]["phone"].ToString(); } } if (radioButtonphoneno.Checked == true) { string n1; n1 = Convert.ToString(textBoxsearch.Text); ta3.Fill(dsc.Customer);

int j, count1, pos1 = -1;

count1 = dsc.Customer.Rows.Count; for (j = 0; j <= count1 - 1; j++) {

if (dsc.Customer.Rows[j]["phone"].ToString() == n1) { pos1 = j; break; } } if (pos1 == -1) {

112

} else

{

textBoxcustname.Text = dsc.Customer.Rows[pos1]["cust_name"].ToString(); textBoxaddress.Text = dsc.Customer.Rows[pos1]["address"].ToString(); textBoxphoneno.Text = dsc.Customer.Rows[pos1]["phone"].ToString(); }

} }

catch (Exception ex) {

MessageBox.Show(ex.Message); }

}

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)

{

Font heading = new Font("lucida handwriting", 22);

Font heading1 = new Font("Bradley Hand ITC", 28,FontStyle.Bold); Font letter = new Font("times new roman", 14);

Font letter1 =new Font ("times new roman",14, FontStyle.Bold);

e.Graphics.DrawString("WELCOME", heading, Brushes.DarkGreen,330, 70);

e.Graphics.DrawString("THE SPICY HUT", heading1, Brushes.Firebrick, 280, 120); e.Graphics.DrawImage(Image.FromFile("C:\\Documents and

Settings\\Administrator\\Desktop\\FOODVILLA\\restaurant pic\\spice1.jpg"),70,60); e.Graphics.DrawImage(Image.FromFile("C:\\Documents and

Settings\\Administrator\\Desktop\\FOODVILLA\\restaurant pic\\spinach1.jpg"), 650, 50); e.Graphics.DrawString("Bill No :", letter1, Brushes.Black, 100, 250); e.Graphics.DrawString(textBoxbillno.Text,letter , Brushes.Black, 180, 250); e.Graphics.DrawString("Dated :", letter1, Brushes.Black, 600, 250);

e.Graphics.DrawString(textBoxdateofbilling.Text, letter, Brushes.Black, 670, 250); e.Graphics.DrawString("Sr No.", letter1, Brushes.Black, 60, 350);

e.Graphics.DrawString("Item Code", letter1, Brushes.Black, 140, 350); e.Graphics.DrawString("Item Name", letter1, Brushes.Black, 250, 350); e.Graphics.DrawString("Price", letter1, Brushes.Black, 460, 350); e.Graphics.DrawString("Qauntity", letter1, Brushes.Black, 550, 350); e.Graphics.DrawString("VAT", letter1, Brushes.Black, 650, 350); e.Graphics.DrawString("Total", letter1, Brushes.Black, 740, 350); int q=400;

int p; int i;

for (i = 0; i <= listViewbilling.Items.Count - 1; i++) {

p = q + i * 25;

e.Graphics.DrawString(listViewbilling.Items[i].Text, letter, Brushes.Black, 80, p); e.Graphics.DrawString(listViewbilling.Items[i].SubItems[1].Text, letter, Brushes.Black, 150, p); e.Graphics.DrawString(listViewbilling.Items[i].SubItems[2].Text, letter, Brushes.Black, 250, p); e.Graphics.DrawString(listViewbilling.Items[i].SubItems[3].Text, letter, Brushes.Black, 460, p);

113

e.Graphics.DrawString(listViewbilling.Items[i].SubItems[4].Text, letter, Brushes.Black, 575, p); e.Graphics.DrawString(listViewbilling.Items[i].SubItems[5].Text, letter, Brushes.Black, 655, p); e.Graphics.DrawString(listViewbilling.Items[i].SubItems[6].Text, letter, Brushes.Black, 740, p); } i = i + 1; p = q + i * 25;

e.Graphics.DrawString("Total Price :", letter1, Brushes.Black, 470, p); e.Graphics.DrawString(textBoxtotalprice.Text, letter, Brushes.Black, 700, p); i = i + 1;

p = q + i * 25;

e.Graphics.DrawString("Total VAT :", letter1, Brushes.Black, 470, p); e.Graphics.DrawString(textBoxtotalvat.Text, letter, Brushes.Black, 700, p); i = i + 1;

p = q + i * 25;

e.Graphics.DrawString("Discount :", letter1, Brushes.Black, 470, p);

e.Graphics.DrawString(textBoxdiscount.Text+"%", letter, Brushes.Black, 700, p); i = i + 1;

p = q + i * 25;

e.Graphics.DrawString("Payable Amount :", letter1, Brushes.Black, 470, p); e.Graphics.DrawString(textBoxpayableamount.Text, letter, Brushes.Black, 700, p); i = i + 1;

e.Graphics.DrawString("THANKS FOR VISITING", heading, Brushes.DarkGreen, 230, 920);

e.Graphics.DrawString("=========================================================", letter1,

Brushes.Black, 100, 955);

e.Graphics.DrawString("7, Block-B",letter1,Brushes.Black,365,980);

e.Graphics.DrawString("The District Shopping Complex", letter1, Brushes.Black, 275, 1000);

e.Graphics.DrawString("Amritsar", letter1, Brushes.Black, 375, 1025); e.Graphics.DrawString("Phone no: 0183-2509876,98765-43210", letter1,

Brushes.Black, 260, 1050); }

private void textBoxdiscount_TextChanged(object sender, EventArgs e) {

if (textBoxdiscount.Text != "") {

discount = Convert.ToDouble(textBoxdiscount.Text); discount = (discount * amountpayable) / 100; amountpayable = amountpayable - discount;

textBoxpayableamount.Text = amountpayable.ToString(); }

} }

114