Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- using System.Threading;
- using System.Configuration;
- using System.Data.SQLite;
- using System.Drawing.Printing;
- using System.Globalization;
- using System.IO;
- using System.Runtime.CompilerServices;
- using FluentDate;
- using FluentDateTime;
- namespace Checkup_Diagnostic
- {
- public partial class Bill_Creation : Form
- {
- private string conString = Properties.Settings.Default.connectionString;
- private List<string> TestCatList = new List<string>();
- private List<string> PatientList = new List<string>();
- private int BillingID;
- private int invoiceID;
- /* Patiend data */
- private int patientID;
- private string patientName;
- private string patientMobile;
- private string patientSex;
- private string PatientAge;
- /* Patiend data end */
- /* Doctor Data */
- private int doctorID;
- private string doctorName;
- private string doctorMobile;
- private string doctorProfile;
- /* Doctor Data end */
- /* Refferer Data */
- private int reffererID;
- private string reffererName;
- private string reffererMobile;
- private decimal totalAmount;
- private decimal totalDiscount;
- /* Refferer Data end*/
- //user data
- private int userId;
- private string userName;
- private string fullName;
- private int userRole;
- private string loginTime;
- // end of user data
- //temporary item data for delete row
- private decimal tmpPC = 0;
- private decimal tmpAmount = 0;
- //end of temporary item data for delete row
- public Bill_Creation()
- {
- InitializeComponent();
- }
- private void loadMainTestCategory()
- {
- MySqlConnection Con = new MySqlConnection(this.conString);
- MySqlCommand Command = Con.CreateCommand();
- Command.CommandText = "SELECT `tg_name` FROM `dms_testgroup` WHERE `status` = 1";
- Con.Open();
- MySqlDataReader Reader = Command.ExecuteReader();
- while(Reader.Read()){
- TestCatList.Add(Reader["tg_name"].ToString());
- }
- Con.Close();
- }
- private void getBillId()
- {
- MySqlConnection Con = new MySqlConnection(this.conString);
- MySqlCommand Command = Con.CreateCommand();
- Command.CommandText = "SELECT `invoice_id` FROM `dms_invoice` ORDER BY `invoice_id` DESC LIMIT 0,1";
- Con.Open();
- MySqlDataReader Reader = Command.ExecuteReader();
- if(Reader.Read()){
- this.BillingID = int.Parse(Reader["invoice_id"].ToString());
- }
- Con.Close();
- }
- private void Bill_Creation_Load(object sender, EventArgs e)
- {
- loadUserInfo();
- //MessageBox.Show(fullName);
- getBillId();
- tbxBillNo.Text = BillingID.ToString();
- tbxBillNo.Enabled = false;
- tbxPatientID.Enabled = false;
- tbxPatientMobile.Enabled = false;
- tbxPatientName.Enabled = false;
- cbxPatientGender.Enabled = false;
- tbxAge.Enabled = false;
- dateTimePicker1.Value = DateTime.Now;
- /**
- tbxRefferedBy.Enabled = false;
- tbxRefference.Enabled = false;
- dateTimePicker1.Value = DateTime.Now;
- btnRefferedByNew.Enabled = false;
- btnRefferenceNew.Enabled = false;
- tbxSearch.Enabled = false;*/
- Load_Test_Item_Group();
- // cbxItem.Enabled = true;
- // cbxItemGroup.Enabled = false;
- // tbxPrice.Enabled = false;
- // tbxDiscount.Enabled = false;
- // btnAdd.Enabled = false;
- tbxOverallDiscount.Enabled = false;
- tbxAdvance.Enabled = false;
- dtmDelivery.Value = DateTime.Now.AddHours(3);
- }
- private void LoadPatientList()
- {
- MySqlConnection Con = new MySqlConnection(this.conString);
- MySqlCommand Command = Con.CreateCommand();
- Command.CommandText = "SELECT `patient_id` FROM `dms_patient` ORDER BY `patient_id` DESC";
- Con.Open();
- MySqlDataReader Reader = Command.ExecuteReader();
- if (Reader.Read())
- {
- ///this.BillingID = int.Parse(Reader["invoice_id"].ToString());
- PatientList.Add(Reader["patient_id"].ToString());
- }
- Con.Close();
- }
- private bool getPatientInfo(string term)
- {
- bool count;
- MySqlConnection Con = new MySqlConnection(this.conString);
- MySqlCommand Command = Con.CreateCommand();
- Command.CommandText = "SELECT * FROM `dms_patient` WHERE `patient_id` = @pid OR `patient_name` REGEXP @pname OR `patient_mobile` REGEXP @mobile ";
- Command.Parameters.AddWithValue("@pid", term.Trim());
- Command.Parameters.AddWithValue("@pname", term);
- Command.Parameters.AddWithValue("@mobile", term);
- // Command.Parameters.AddWithValue("@term", term);
- Con.Open();
- MySqlDataReader Reader = Command.ExecuteReader();
- if(Reader.Read()){
- count = true;
- this.patientID = int.Parse(Reader["patient_id"].ToString());
- this.patientName = Reader["patient_name"].ToString();
- this.PatientAge = Reader["patient_age"].ToString();
- this.patientMobile = Reader["patient_mobile"].ToString();
- this.patientSex = Reader["patient_sex"].ToString();
- }
- else
- {
- count = false;
- }
- tbxRefferedBy.Focus();
- return count;
- }
- private void tbxSearch_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == ' ')
- {
- if (tbxSearch.Text.Trim() != String.Empty)
- {
- //tbxPatientName.Text += tbxPatientID.Text;
- if (getPatientInfo(tbxSearch.Text.Trim().ToString()))
- {
- tbxPatientID.Text = this.patientID.ToString();
- tbxPatientName.Text = this.patientName;
- tbxPatientMobile.Text = this.patientMobile;
- tbxAge.Text = this.PatientAge;
- cbxPatientGender.SelectedIndex = cbxPatientGender.Items.IndexOf(this.patientSex);
- tbxPatientID.Enabled = false;
- tbxPatientMobile.Enabled = false;
- tbxPatientName.Enabled = false;
- cbxPatientGender.Enabled = false;
- tbxAge.Enabled = false;
- tbxSearch.Enabled = false;
- tbxSearch.Enabled = true;
- }
- else
- {
- MessageBox.Show("Search term doest not match", "Search Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- tbxSearch.Focus();
- }
- }
- else
- {
- MessageBox.Show("Search term must not be empty", "Search Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- tbxSearch.Focus();
- }
- }
- }
- private void tbxSearch_TextChanged(object sender, EventArgs e)
- {
- }
- private void tbxSearch_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyValue == 32)
- {
- }
- }
- private void tbxSearch_Leave(object sender, EventArgs e)
- {
- tbxSearch.Clear();
- }
- private void btnRefferedByNew_Click(object sender, EventArgs e)
- {
- }
- private void groupBox2_Enter(object sender, EventArgs e)
- {
- }
- private void label12_Click(object sender, EventArgs e)
- {
- }
- private void label13_Click(object sender, EventArgs e)
- {
- }
- private void label15_Click(object sender, EventArgs e)
- {
- }
- private void tbxRefferedBy_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == ' ')
- {
- if (tbxRefferedBy.Text.Trim() != String.Empty)
- {
- //tbxPatientName.Text += tbxPatientID.Text;
- if (getDoctorInfo(tbxRefferedBy.Text.Trim().ToString()))
- {
- lblDoctorID.Text = this.doctorID.ToString();
- lblDoctorName.Text = this.doctorName;
- lblDoctorPhone.Text = this.doctorMobile;
- lblDoctorProfile.Text = this.doctorProfile;
- tbxRefferedBy.Enabled = false;
- tbxRefferedBy.Enabled = true;
- tbxRefference.Focus();
- }
- else
- {
- MessageBox.Show("Search term doest not match", "Search Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- tbxRefferedBy.Focus();
- }
- }
- else
- {
- MessageBox.Show("Search term must not be empty", "Search Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- tbxRefferedBy.Focus();
- }
- }
- }
- private bool getDoctorInfo(string term)
- {
- bool count;
- MySqlConnection Con = new MySqlConnection(this.conString);
- MySqlCommand Command = Con.CreateCommand();
- Command.CommandText = "SELECT * FROM `doctors` WHERE `doctor_id` = @did OR `doctor_name` REGEXP @dname OR `doctor_phone` REGEXP @dobile";
- Command.Parameters.AddWithValue("@did", term.Trim());
- Command.Parameters.AddWithValue("@dname", term);
- Command.Parameters.AddWithValue("@dobile", term);
- // Command.Parameters.AddWithValue("@term", term);
- Con.Open();
- MySqlDataReader Reader = Command.ExecuteReader();
- if (Reader.Read())
- {
- count = true;
- this.doctorID = int.Parse(Reader["doctor_id"].ToString());
- this.doctorName = Reader["doctor_name"].ToString();
- this.doctorMobile = Reader["doctor_phone"].ToString();
- this.doctorProfile = Reader["doctor_degree"].ToString();
- }
- else
- {
- count = false;
- }
- Reader.Close();
- Con.Close();
- return count;
- }
- private void tbxRefferedBy_Leave(object sender, EventArgs e)
- {
- tbxRefferedBy.Clear();
- }
- private void tbxRefferedBy_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyValue == 32)
- {
- }
- }
- private void tbxRefferedBy_TextChanged(object sender, EventArgs e)
- {
- }
- private void tbxRefferedBy_Enter(object sender, EventArgs e)
- {
- tbxRefferedBy.Clear();
- }
- private bool getReffererInfo(string term)
- {
- bool count;
- MySqlConnection Con = new MySqlConnection(this.conString);
- MySqlCommand Command = Con.CreateCommand();
- Command.CommandText = "SELECT * FROM `reference` WHERE `ref_id` = @rid OR `ref_name` REGEXP @rname OR `ref_mobile` REGEXP @rmobile ";
- Command.Parameters.AddWithValue("@rid", term);
- Command.Parameters.AddWithValue("@rname", term);
- Command.Parameters.AddWithValue("@rmobile", term);
- Con.Open();
- MySqlDataReader Reader = Command.ExecuteReader();
- if (Reader.Read())
- {
- count = true;
- this.reffererID = int.Parse(Reader["ref_id"].ToString());
- this.reffererName = Reader["ref_name"].ToString();
- this.reffererMobile = Reader["ref_mobile"].ToString();
- }
- else
- {
- count = false;
- }
- Reader.Close();
- Con.Close();
- return count;
- }
- private void tbxRefference_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == ' ')
- {
- if (tbxRefference.Text.Trim() != String.Empty)
- {
- //tbxPatientName.Text += tbxPatientID.Text;
- if (getReffererInfo(tbxRefference.Text.Trim().ToString()))
- {
- lblReffererID.Text = this.reffererID.ToString();
- lblReffererName.Text = this.reffererName;
- lblReffererPhone.Text = this.reffererMobile;
- tbxRefference.Enabled = false;
- tbxRefference.Enabled = true;
- cbxItemGroup.Focus();
- }
- else
- {
- MessageBox.Show("Search term doest not match", "Search Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- tbxRefference.Focus();
- }
- }
- else
- {
- MessageBox.Show("Search term must not be empty", "Search Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- tbxRefference.Focus();
- }
- }
- }
- private void lblReffererID_Click(object sender, EventArgs e)
- {
- }
- private void tbxRefference_Leave(object sender, EventArgs e)
- {
- tbxRefference.Clear();
- }
- private void Load_Test_Item_Group()
- {
- MySqlConnection con = new MySqlConnection(conString);
- MySqlCommand command = con.CreateCommand();
- command.CommandText = "SELECT * FROM `dms_testgroup` WHERE `status` = 1 ORDER BY `tg_id` DESC";
- con.Open();
- MySqlDataReader Reader = command.ExecuteReader();
- while (Reader.Read())
- {
- // MessageBox.Show(Reader["tg_name"].ToString());
- cbxItemGroup.Items.Add(new ComboBoxItem(Reader["tg_name"].ToString(), Reader["tg_id"].ToString()));
- }
- }
- private void LoadTestItems()
- {
- cbxItem.Items.Clear();
- int testGroupId = int.Parse(((ComboBoxItem)cbxItemGroup.SelectedItem).HiddenValue);
- // MessageBox.Show(testGroupId.ToString());
- MySqlConnection con = new MySqlConnection(conString);
- MySqlCommand command = con.CreateCommand();
- command.CommandText = "SELECT * FROM `dms_testitems` WHERE `status` = 1 AND `item_cat` = @cat ORDER BY `item_id` DESC";
- command.Parameters.AddWithValue("@cat", testGroupId);
- con.Open();
- MySqlDataReader Reader = command.ExecuteReader();
- while (Reader.Read())
- {
- cbxItem.Items.Add(new ComboBoxItem(Reader["item_name"].ToString(), Reader["item_id"].ToString()));
- }
- }
- private void cbxItemGroup_SelectedIndexChanged(object sender, EventArgs e)
- {
- cbxItem.Enabled = true;
- LoadTestItems();
- cbxItem.Focus();
- }
- private void cbxItem_SelectedIndexChanged_1(object sender, EventArgs e)
- {
- int itemId = int.Parse(((ComboBoxItem)cbxItem.SelectedItem).HiddenValue);
- MySqlConnection con = new MySqlConnection(this.conString);
- MySqlCommand command = con.CreateCommand();
- command.CommandText = "SELECT `item_price` FROM `dms_testitems` WHERE `item_id` = @itemid ";
- command.Parameters.AddWithValue("@itemid",itemId);
- con.Open();
- MySqlDataReader Reader = command.ExecuteReader();
- if (Reader.Read())
- {
- tbxPrice.Text = Reader["item_price"].ToString();
- tbxDiscount.Text = "0";
- }
- command.Cancel();
- Reader.Close();
- con.Close();
- btnAdd.Focus();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (is_valid())
- {
- int itemId = int.Parse(((ComboBoxItem)cbxItem.SelectedItem).HiddenValue);
- MySqlConnection con = new MySqlConnection(this.conString);
- MySqlCommand command = con.CreateCommand();
- command.CommandText = "SELECT * FROM `dms_testitems` WHERE `item_id` = @itemid ";
- command.Parameters.AddWithValue("@itemid", itemId);
- con.Open();
- MySqlDataReader Reader = command.ExecuteReader();
- if (Reader.Read())
- {
- // decimal totalAmount = decimal.Parse(tbxPrice.Text) + decimal.Parse(tbxDiscount.Text);
- decimal totalAmount = decimal.Parse(tbxPrice.Text);
- int roomNo = getRoomNo(int.Parse(Reader["item_cat"].ToString()));
- this.dataGridView1.Rows.Add(Reader["item_name"], Reader["item_description"], tbxDiscount.Text, totalAmount.ToString(), roomNo);
- this.totalAmount += decimal.Parse(tbxPrice.Text);
- this.totalDiscount += decimal.Parse(tbxDiscount.Text);
- tbxPcPercentage.Text = this.totalDiscount.ToString();
- tbxSubTotal.Text = this.totalAmount.ToString();
- tbxGrandTotal.Text = this.totalAmount.ToString();
- }
- command.Cancel();
- // Reader.Close();
- con.Close();
- btnPrint.Enabled = true;
- tbxOverallDiscount.Enabled = true;
- tbxAdvance.Enabled = true;
- cbxItemGroup.Focus();
- //change payment status
- decimal value;
- bool isParsed = decimal.TryParse(tbxAdvance.Text.Trim(), out value);
- int grandTotal;
- int advance;
- grandTotal = decimal.ToInt32(decimal.Parse(tbxGrandTotal.Text));
- advance = decimal.ToInt32(value);
- if (grandTotal <= advance)
- {
- lblStatus.Text = "Paid";
- lblStatus.ForeColor = System.Drawing.Color.Green;
- }
- else
- {
- lblStatus.Text = "Due";
- lblStatus.ForeColor = System.Drawing.Color.Red;
- }
- }
- else
- {
- }
- }
- private int getRoomNo(int roomId)
- {
- MySqlConnection con = new MySqlConnection(this.conString);
- MySqlCommand command = con.CreateCommand();
- command.CommandText = "SELECT `room_no` FROM `dms_testgroup` WHERE `tg_id` = @id ";
- command.Parameters.AddWithValue("@id", roomId);
- con.Open();
- MySqlDataReader Reader = command.ExecuteReader();
- if (Reader.Read())
- {
- return int.Parse(Reader["room_no"].ToString());
- }
- command.Cancel();
- // Reader.Close();
- con.Close();
- return -1;
- }
- private bool is_valid()
- {
- if (cbxItemGroup.SelectedIndex == -1)
- {
- MessageBox.Show("Item group is not selected", "Item Add Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- cbxItemGroup.Focus();
- return false;
- }
- if (cbxItem.SelectedIndex == -1)
- {
- MessageBox.Show("Item is not selected", "Item Add Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- cbxItem .Focus();
- return false;
- }
- if (tbxPrice.Text.Trim() == String.Empty)
- {
- MessageBox.Show("Item Price is empty", "Item Add Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- tbxPrice.Focus();
- return false;
- }
- if (tbxDiscount.Text.Trim() == String.Empty)
- {
- MessageBox.Show("Discount is empty", "Item Add Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- tbxDiscount.Focus();
- return false;
- }
- return true;
- }
- private void btnPrint_Click(object sender, EventArgs e)
- {
- if (is_valid_for_print())
- {
- PrinterSettings ps = new PrinterSettings();
- printDocument1.PrinterSettings = ps;
- IEnumerable<PaperSize> paperSizes = ps.PaperSizes.Cast<PaperSize>();
- PaperSize sizeA4 = paperSizes.First<PaperSize>(size => size.Kind == PaperKind.A4); // setting paper size to A4 size
- //PaperSize paperSize = new PaperSize("My Envelope", 595, 842);
- // paperSize.RawKind = (int)PaperKind.Custom;
- printDocument1.DefaultPageSettings.PaperSize = sizeA4;
- printPreviewDialog1.Document = printDocument1;
- printPreviewDialog1.PrintPreviewControl.Zoom = 100 / 100f;
- ((Form)printPreviewDialog1).WindowState = FormWindowState.Maximized;
- printPreviewDialog1.ShowDialog();
- }
- }
- private bool is_valid_for_print()
- {
- if (dataGridView1.Rows.Count <= 1)
- {
- MessageBox.Show("Must add some item", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return false;
- }
- if (tbxPatientID.Text.Trim() == String.Empty)
- {
- MessageBox.Show("Patient is not selected", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return false;
- }
- return true;
- }
- private bool saveInvoiceInfo()
- {
- bool isSaveSuccess = false;
- decimal subTotal = 0, discount = 0, advance = 0, due = 0, grandTotal = 0;
- bool isSubtotal, isDiscount, isAdvance;
- isSubtotal = decimal.TryParse(tbxSubTotal.Text.Trim(), out subTotal);
- isDiscount = decimal.TryParse(tbxOverallDiscount.Text.Trim(), out discount);
- isAdvance = decimal.TryParse(tbxAdvance.Text.Trim(), out advance);
- if (isDiscount)
- {
- grandTotal = subTotal - discount;
- }
- else
- {
- grandTotal = subTotal;
- }
- if (isAdvance)
- {
- due = grandTotal - advance;
- if (due < 0)
- {
- due = 0;
- }
- }
- else
- {
- due = grandTotal;
- }
- MySqlConnection con = new MySqlConnection(this.conString);
- try
- {
- MySqlCommand command = con.CreateCommand();
- command.CommandText = "INSERT INTO `dms`.`dms_invoice` (`invoice_id`, `invoice_patient`, `invoice_creator`, `invoice_amount`, `invoice_discount`,`due`,`advance`,`delivery_date`, `invoice_date`, `invoice_refby`, `invoice_refferedby`, `time_added`, `time_updated`, `status`) VALUES (NULL, @patientid, @creator , @amount, @discount, @due , @advance , @delivery, @invoicedate , @refby , @refferer, CURDATE() , CURRENT_TIMESTAMP , '1')";
- command.Parameters.AddWithValue("@patientid", this.patientID);
- command.Parameters.AddWithValue("@creator", this.userId);
- command.Parameters.AddWithValue("@amount", grandTotal);
- command.Parameters.AddWithValue("@discount", discount);
- command.Parameters.AddWithValue("@due", due);
- command.Parameters.AddWithValue("@delivery", dtmDelivery.Value);
- command.Parameters.AddWithValue("@advance", advance);
- command.Parameters.AddWithValue("@refby", this.doctorID);
- command.Parameters.AddWithValue("@refferer", this.reffererID);
- command.Parameters.AddWithValue("@invoicedate", dateTimePicker1.Value.Date);
- con.Open();
- int a = command.ExecuteNonQuery();
- if (a > 0)
- {
- int InvoiceID = int.Parse(command.LastInsertedId.ToString());
- this.BillingID = InvoiceID;
- saveInvoiceItems(InvoiceID);
- if (lblReffererID.Text.Trim() != "Refferer ID")
- {
- if (!save_pc_info(InvoiceID))
- {
- MessageBox.Show("Database operation failed", "P.C. info Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- isSaveSuccess = true;
- }
- else
- {
- isSaveSuccess = false;
- }
- }
- catch (MySqlException e)
- {
- MessageBox.Show(e.Message, "Mysql insertion error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- con.Close();
- return isSaveSuccess;
- }
- private void saveInvoiceItems(int invoiceID)
- {
- MySqlConnection con = new MySqlConnection(this.conString);
- foreach (DataGridViewRow row in dataGridView1.Rows)
- {
- // MessageBox.Show(row.Cells[1].Value.ToString());
- if (row.Cells[1].Value != null)
- {
- MySqlCommand command = con.CreateCommand();
- command.CommandText = "INSERT INTO `dms`.`dms_invoiceitems` (`item_id`, `item_description`, `item_discount`, `item_price`, `item_amount`, `inovice_id`, `status`) VALUES (NULL , @itemdesc , @discount , @price , @amount , @invoiceid , '1')";
- command.Parameters.AddWithValue("@itemdesc", row.Cells[0].Value.ToString());
- command.Parameters.AddWithValue("@discount", row.Cells[1].Value.ToString());
- command.Parameters.AddWithValue("@price", DBNull.Value);
- command.Parameters.AddWithValue("@amount", row.Cells[3].Value.ToString());
- command.Parameters.AddWithValue("@invoiceid", invoiceID);
- con.Open();
- int a = command.ExecuteNonQuery();
- if (a > 0)
- {
- //MessageBox.Show("Command Executed");
- }
- else
- {
- // MessageBox.Show("Command not executed");
- }
- con.Close();
- }
- }
- }
- private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
- {
- decimal subTotal = 0, discount = 0, advance = 0, due = 0, grandTotal = 0;
- bool isSubtotal, isDiscount, isAdvance;
- isSubtotal = decimal.TryParse(tbxSubTotal.Text.Trim(), out subTotal);
- isDiscount = decimal.TryParse(tbxOverallDiscount.Text.Trim(), out discount);
- isAdvance = decimal.TryParse(tbxAdvance.Text.Trim(), out advance);
- if (isDiscount)
- {
- grandTotal = subTotal - discount;
- }
- else
- {
- grandTotal = subTotal;
- }
- if (isAdvance)
- {
- due = grandTotal - advance;
- if (due < 0)
- {
- due = 0;
- }
- }
- else
- {
- due = grandTotal;
- }
- //totalDue = grandtotal <= totalAdvance ? 0 : ((grandtotal - overallDiscount) - totalAdvance);
- string nameTitle;
- if (patientSex.Contains("Male"))
- {
- nameTitle = "MR. ";
- }
- else
- {
- nameTitle = "MRS. ";
- }
- /****************************
- * Copy 1
- **************************/
- /** Head Column 1**/
- string colorcode = "#2F2F30";
- int argb = Int32.Parse(colorcode.Replace("#", ""), NumberStyles.HexNumber);
- Color clr = Color.FromArgb(argb);
- //System.Drawing.Color col = System.Drawing.ColorTranslator.FromHtml("#2F2F30");
- Pen blackPen = new Pen(Color.DimGray, 1);
- int primaryHeight = 45;
- e.Graphics.DrawRectangle(blackPen, 40, primaryHeight, 725, 90);
- e.Graphics.DrawLine(blackPen, 460, 135, 460, primaryHeight);
- primaryHeight += 0;
- e.Graphics.DrawString("Check Up Diagnostic & Hospital ", new Font("Calibri", 14, FontStyle.Bold), new SolidBrush(Color.Black), new Point(45, primaryHeight));
- primaryHeight += 25;
- e.Graphics.DrawString("Balubari, Dinajpur", new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(45, primaryHeight));
- e.Graphics.DrawString("Tel: +8801738765544", new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(250, primaryHeight));
- primaryHeight += 20;
- e.Graphics.DrawString("Money Receipt / Voucher", new Font("Calibri", 12, FontStyle.Bold), Brushes.Black, new Point(130, primaryHeight));
- primaryHeight += 20;
- e.Graphics.DrawString("Ref. By: ", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(45, primaryHeight));
- e.Graphics.DrawString(doctorName +", " + doctorProfile, new Font("Calibri",10, FontStyle.Bold), Brushes.Black, new Point(110, primaryHeight));
- /** End of Head Column 1**/
- /** Head Colum2**/
- Random r = new Random();
- int height2 = 45;
- e.Graphics.DrawString("Voucher No: " + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + BillingID.ToString(), new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(470, height2));
- height2 += 15;
- e.Graphics.DrawString("Name:", new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(470, height2));
- e.Graphics.DrawString(nameTitle + this.patientName.ToUpper(), new Font("Calibri", 10, FontStyle.Bold), new SolidBrush(Color.Black), new Point(540, height2));
- height2 += 15;
- e.Graphics.DrawString("Reg. No:", new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(470, height2));
- e.Graphics.DrawString("" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + BillingID.ToString(), new Font("Calibri", 11, FontStyle.Regular), new SolidBrush(Color.Black), new Point(540, height2));
- e.Graphics.DrawString("CN: C-" + r.Next(1000, 9999) + "-" + r.Next(1000, 9999), new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(650, height2));
- height2 += 15;
- e.Graphics.DrawString("Date: " + dateTimePicker1.Value.ToString("dd/MM/yyyy h:mm"), new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(470, height2));
- e.Graphics.DrawString("Age: " + this.PatientAge.ToString() + " yrs.", new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(670, height2));
- height2 += 15;
- e.Graphics.DrawString("Delivery: " + dtmDelivery.Value.ToString("dd/MM/yyyy h:mm tt"), new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(470, height2));
- /** End of Head Colum2**/
- /**** Bar Code ***/
- height2 += 35;
- //var barcodeImg = System.Drawing.Image.FromFile(@"img\barcode.gif");
- // var barcodeImg2 = System.Drawing.Image.FromFile(@"img\barcode2.gif");
- // var barcodeImg3 = System.Drawing.Image.FromFile(@"img\barcode3.gif");
- e.Graphics.DrawImage(Properties.Resources.barcode, 45, height2, 180, 15);
- e.Graphics.DrawString("CN", new Font("Calibri", 10, FontStyle.Bold), new SolidBrush(Color.Black), new Point(250, height2));
- e.Graphics.DrawImage(Properties.Resources.barcode, 310, height2, 180, 15);
- e.Graphics.DrawString("HN", new Font("Calibri", 10, FontStyle.Bold), new SolidBrush(Color.Black), new Point(550, height2));
- e.Graphics.DrawImage(Properties.Resources.barcode, 585, height2, 180, 15);
- /** End of barcode**/
- /** Column Rectangle**/
- height2 += 20;
- e.Graphics.DrawRectangle(blackPen, 40, height2, 725, 25);
- /** end of Column Rectangle**/
- /* Bill To*/
- // e.Graphics.DrawString("BILL TO", new Font("Arial", 11, FontStyle.Bold), Brushes.Black, new Point(40, 200));
- // e.Graphics.DrawString("#2016-11-"+patientID.ToString(), new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(40, 220));
- // e.Graphics.DrawString(patientName.ToString().ToUpper(), new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(40, 240));
- // e.Graphics.DrawString(patientMobile, new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(40, 260));
- /* Bill to End*/
- /* Invoice*/
- // e.Graphics.DrawString("INVOICE SUMMARY", new Font("Arial", 11, FontStyle.Bold), Brushes.Black, new Point(650, 200));
- // e.Graphics.DrawString(String.Format("DATE: {0}-{1}-{2}", dateTimePicker1.Value.Day, dateTimePicker1.Value.Month, dateTimePicker1.Value.Year), new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(650, 220));
- // e.Graphics.DrawString("INVOICE: # " + this.BillingID.ToString(), new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(650, 240));
- /* Invoice End*/
- height2 += 5;
- /* Column Header */
- e.Graphics.DrawString("SL", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(45, height2));
- e.Graphics.DrawString("Item Description", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(75, height2));
- // e.Graphics.DrawString("Price", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(500, height2));
- e.Graphics.DrawString("Room No.", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(600, height2));
- e.Graphics.DrawString("Amount", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(700, height2));
- /* Column Header End*/
- int lineHeight = height2 + 25;
- int lineHeight2 = lineHeight + 250;
- int i = 1;
- foreach (DataGridViewRow row in dataGridView1.Rows)
- {
- // MessageBox.Show(row.Cells[1].Value.ToString());
- if (row.Cells[1].Value != null)
- {
- e.Graphics.DrawString(i.ToString(), new Font("Arial", 11, FontStyle.Bold), Brushes.Black, new Point(45,lineHeight));
- e.Graphics.DrawString(row.Cells[1].Value.ToString(), new Font("Calibri", 11, FontStyle.Regular), Brushes.Black, new Point(75, lineHeight));
- // e.Graphics.DrawString(row.Cells[3].Value.ToString(), new Font("Calibri", 11, FontStyle.Regular), Brushes.Black, new Point(500, lineHeight));
- e.Graphics.DrawString(row.Cells[4].Value.ToString(), new Font("Calibri", 11, FontStyle.Regular), Brushes.Black, new Point(600, lineHeight));
- e.Graphics.DrawString(row.Cells[3].Value.ToString(), new Font("Calibri", 11, FontStyle.Regular), Brushes.Black, new Point(700, lineHeight));
- }
- lineHeight += 20;
- i++;
- }
- e.Graphics.DrawRectangle(blackPen, 40, lineHeight2,725, 120);
- e.Graphics.DrawLine(blackPen, 600, lineHeight2, 600, lineHeight2 + 90);
- lineHeight2 += 5;
- /** Footer Column 1**/
- int ftColLineHeigh1 = lineHeight2;
- e.Graphics.DrawString("Subtotal:", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(500, ftColLineHeigh1));
- e.Graphics.DrawString(subTotal.ToString(), new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(700, ftColLineHeigh1));
- ftColLineHeigh1 += 20;
- e.Graphics.DrawString("Discount:", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(500, ftColLineHeigh1));
- e.Graphics.DrawString(discount.ToString(), new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(700, ftColLineHeigh1));
- ftColLineHeigh1 += 20;
- e.Graphics.DrawString("Advance:", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(500, ftColLineHeigh1));
- e.Graphics.DrawString(advance.ToString(), new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(700, ftColLineHeigh1));
- ftColLineHeigh1 += 20;
- e.Graphics.DrawString("Due:", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(500, ftColLineHeigh1));
- e.Graphics.DrawString(due.ToString(), new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(700, ftColLineHeigh1));
- /** Footer Column 1 end**/
- e.Graphics.DrawString("Payment Types: (Cash)", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(45, lineHeight2));
- e.Graphics.DrawString(grandTotal.ToString(), new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(220, lineHeight2));
- lineHeight2 += 20;
- int totalAmount = decimal.ToInt32(grandTotal);
- string amountInWords = this.NumberToWords(totalAmount).ToUpper() + " ONLY";
- e.Graphics.DrawString(amountInWords, new Font("Calibri", 9, FontStyle.Regular), Brushes.Black, new Point(45, lineHeight2));
- lineHeight2 += 40;
- e.Graphics.DrawString("(This is computer generated signature, no need to sign.)", new Font("Calibri", 9, FontStyle.Bold), Brushes.Black, new Point(100, lineHeight2));
- ftColLineHeigh1 += 25;
- // Create points that define line.
- Point point1 = new Point(40, ftColLineHeigh1);
- Point point2 = new Point(765, ftColLineHeigh1);
- // Draw line to screen.
- e.Graphics.DrawLine(blackPen, point1, point2);
- e.Graphics.DrawLine(blackPen, 450, ftColLineHeigh1, 450, ftColLineHeigh1 + 30);
- ftColLineHeigh1 += 5;
- e.Graphics.DrawString("Cashier Signature:", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(45, ftColLineHeigh1));
- e.Graphics.DrawString(fullName, new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(160, ftColLineHeigh1));
- e.Graphics.DrawString("Total Amount: ", new Font("Calibri", 11, FontStyle.Bold), Brushes.Black, new Point(470, ftColLineHeigh1));
- e.Graphics.DrawString(grandTotal.ToString(), new Font("Calibri", 11, FontStyle.Bold), Brushes.Black, new Point(700, ftColLineHeigh1));
- /****************************
- * Copy 1 End
- **************************/
- /****************************
- * Copy 2
- **************************/
- /** Head Column 1**/
- //System.Drawing.Color col = System.Drawing.ColorTranslator.FromHtml("#2F2F30");
- primaryHeight = ftColLineHeigh1+60;
- height2 = primaryHeight + 5;
- e.Graphics.DrawRectangle(blackPen, 40, primaryHeight, 725, 90);
- e.Graphics.DrawLine(blackPen, 460, primaryHeight, 460, primaryHeight+90);
- primaryHeight += 0;
- e.Graphics.DrawString("Check Up Diagnostic & Hospital ", new Font("Calibri", 14, FontStyle.Bold), new SolidBrush(Color.Black), new Point(45, primaryHeight));
- primaryHeight += 25;
- e.Graphics.DrawString("Balubari, Dinajpur", new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(45, primaryHeight));
- e.Graphics.DrawString("Tel: +8801738765544", new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(250, primaryHeight));
- primaryHeight += 20;
- e.Graphics.DrawString("Money Receipt / Voucher", new Font("Calibri", 12, FontStyle.Bold), Brushes.Black, new Point(130, primaryHeight));
- primaryHeight += 20;
- e.Graphics.DrawString("Ref. By: ", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(45, primaryHeight));
- e.Graphics.DrawString(doctorName + ", " + doctorProfile, new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(110, primaryHeight));
- /** End of Head Column 1**/
- /** Head Colum2**/
- e.Graphics.DrawString("Voucher No: " + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + BillingID.ToString(), new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(470, height2));
- height2 += 15;
- e.Graphics.DrawString("Name:", new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(470, height2));
- e.Graphics.DrawString(nameTitle + this.patientName.ToUpper(), new Font("Calibri", 10, FontStyle.Bold), new SolidBrush(Color.Black), new Point(540, height2));
- height2 += 15;
- e.Graphics.DrawString("Reg. No:", new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(470, height2));
- e.Graphics.DrawString("" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + BillingID.ToString(), new Font("Calibri", 11, FontStyle.Regular), new SolidBrush(Color.Black), new Point(540, height2));
- e.Graphics.DrawString("CN: C-" + r.Next(1000, 9999) + "-" + r.Next(1000, 9999), new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(650, height2));
- height2 += 15;
- e.Graphics.DrawString("Date: " + dateTimePicker1.Value.ToString("dd/MM/yyyy"), new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(470, height2));
- e.Graphics.DrawString("Age: " + this.PatientAge.ToString() + " yrs.", new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(670, height2));
- height2 += 15;
- e.Graphics.DrawString("Delivery: " + dtmDelivery.Value.ToString("dd/MM/yyyy h:mm tt"), new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(470, height2));
- /** End of Head Colum2**/
- /**** Bar Code ***/
- height2 += 35;
- //var barcodeImg = System.Drawing.Image.FromFile(@"img\barcode.gif");
- // var barcodeImg2 = System.Drawing.Image.FromFile(@"img\barcode2.gif");
- // var barcodeImg3 = System.Drawing.Image.FromFile(@"img\barcode3.gif");
- e.Graphics.DrawImage(Properties.Resources.barcode, 45, height2, 180, 15);
- e.Graphics.DrawString("CN", new Font("Calibri", 10, FontStyle.Bold), new SolidBrush(Color.Black), new Point(250, height2));
- e.Graphics.DrawImage(Properties.Resources.barcode, 310, height2, 180, 15);
- e.Graphics.DrawString("HN", new Font("Calibri", 10, FontStyle.Bold), new SolidBrush(Color.Black), new Point(550, height2));
- e.Graphics.DrawImage(Properties.Resources.barcode, 585, height2, 180, 15);
- /** End of barcode**/
- /** Column Rectangle**/
- height2 += 20;
- e.Graphics.DrawRectangle(blackPen, 40, height2, 725, 25);
- /** end of Column Rectangle**/
- /* Bill To*/
- // e.Graphics.DrawString("BILL TO", new Font("Arial", 11, FontStyle.Bold), Brushes.Black, new Point(40, 200));
- // e.Graphics.DrawString("#2016-11-"+patientID.ToString(), new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(40, 220));
- // e.Graphics.DrawString(patientName.ToString().ToUpper(), new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(40, 240));
- // e.Graphics.DrawString(patientMobile, new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(40, 260));
- /* Bill to End*/
- /* Invoice*/
- // e.Graphics.DrawString("INVOICE SUMMARY", new Font("Arial", 11, FontStyle.Bold), Brushes.Black, new Point(650, 200));
- // e.Graphics.DrawString(String.Format("DATE: {0}-{1}-{2}", dateTimePicker1.Value.Day, dateTimePicker1.Value.Month, dateTimePicker1.Value.Year), new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(650, 220));
- // e.Graphics.DrawString("INVOICE: # " + this.BillingID.ToString(), new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(650, 240));
- /* Invoice End*/
- height2 += 5;
- /* Column Header */
- e.Graphics.DrawString("SL", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(45, height2));
- e.Graphics.DrawString("Item Description", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(75, height2));
- // e.Graphics.DrawString("Price", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(500, height2));
- e.Graphics.DrawString("Room No.", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(600, height2));
- e.Graphics.DrawString("Amount", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(700, height2));
- /* Column Header End*/
- lineHeight = height2 + 25;
- lineHeight2 = lineHeight + 250;
- i = 1;
- foreach (DataGridViewRow row in dataGridView1.Rows)
- {
- // MessageBox.Show(row.Cells[1].Value.ToString());
- if (row.Cells[1].Value != null)
- {
- e.Graphics.DrawString(i.ToString(), new Font("Arial", 11, FontStyle.Bold), Brushes.Black, new Point(45, lineHeight));
- e.Graphics.DrawString(row.Cells[1].Value.ToString(), new Font("Calibri", 11, FontStyle.Regular), Brushes.Black, new Point(75, lineHeight));
- // e.Graphics.DrawString(row.Cells[3].Value.ToString(), new Font("Calibri", 11, FontStyle.Regular), Brushes.Black, new Point(500, lineHeight));
- e.Graphics.DrawString(row.Cells[4].Value.ToString(), new Font("Calibri", 11, FontStyle.Regular), Brushes.Black, new Point(600, lineHeight));
- e.Graphics.DrawString(row.Cells[3].Value.ToString(), new Font("Calibri", 11, FontStyle.Regular), Brushes.Black, new Point(700, lineHeight));
- }
- lineHeight += 20;
- i++;
- }
- e.Graphics.DrawRectangle(blackPen, 40, lineHeight2, 725, 120);
- e.Graphics.DrawLine(blackPen, 600, lineHeight2, 600, lineHeight2 + 90);
- lineHeight2 += 5;
- /** Footer Column 1**/
- ftColLineHeigh1 = lineHeight2;
- e.Graphics.DrawString("Subtotal:", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(500, ftColLineHeigh1));
- e.Graphics.DrawString(subTotal.ToString(), new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(700, ftColLineHeigh1));
- ftColLineHeigh1 += 20;
- e.Graphics.DrawString("Discount:", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(500, ftColLineHeigh1));
- e.Graphics.DrawString(discount.ToString(), new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(700, ftColLineHeigh1));
- ftColLineHeigh1 += 20;
- e.Graphics.DrawString("Advance:", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(500, ftColLineHeigh1));
- e.Graphics.DrawString(advance.ToString(), new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(700, ftColLineHeigh1));
- ftColLineHeigh1 += 20;
- e.Graphics.DrawString("Due:", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(500, ftColLineHeigh1));
- e.Graphics.DrawString(due.ToString(), new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(700, ftColLineHeigh1));
- /** Footer Column 1 end**/
- e.Graphics.DrawString("Payment Types: (Cash)", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(45, lineHeight2));
- e.Graphics.DrawString(grandTotal.ToString(), new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(220, lineHeight2));
- lineHeight2 += 20;
- totalAmount = decimal.ToInt32(grandTotal);
- amountInWords = this.NumberToWords(totalAmount).ToUpper() + " ONLY";
- e.Graphics.DrawString(amountInWords, new Font("Calibri", 9, FontStyle.Regular), Brushes.Black, new Point(45, lineHeight2));
- lineHeight2 += 40;
- e.Graphics.DrawString("(This is computer generated signature, no need to sign.)", new Font("Calibri", 9, FontStyle.Bold), Brushes.Black, new Point(100, lineHeight2));
- ftColLineHeigh1 += 25;
- // Create points that define line.
- point1 = new Point(40, ftColLineHeigh1);
- point2 = new Point(765, ftColLineHeigh1);
- // Draw line to screen.
- e.Graphics.DrawLine(blackPen, point1, point2);
- e.Graphics.DrawLine(blackPen, 450, ftColLineHeigh1, 450, ftColLineHeigh1 + 30);
- ftColLineHeigh1 += 5;
- e.Graphics.DrawString("Cashier Signature:", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(45, ftColLineHeigh1));
- e.Graphics.DrawString(fullName, new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(160, ftColLineHeigh1));
- e.Graphics.DrawString("Total Amount: ", new Font("Calibri", 11, FontStyle.Bold), Brushes.Black, new Point(470, ftColLineHeigh1));
- e.Graphics.DrawString(grandTotal.ToString(), new Font("Calibri", 11, FontStyle.Bold), Brushes.Black, new Point(710, ftColLineHeigh1));
- /****************************
- * Copy 2 End
- **************************/
- if (!saveInvoiceInfo())
- {
- MessageBox.Show("Database operation failed", "Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- else
- {
- }
- }
- private string NumberToWords(int number)
- {
- if (number == 0)
- return "zero";
- if (number < 0)
- return "minus " + NumberToWords(Math.Abs(number));
- string words = "";
- if ((number / 1000000) > 0)
- {
- words += NumberToWords(number / 1000000) + " million ";
- number %= 1000000;
- }
- if ((number / 1000) > 0)
- {
- words += NumberToWords(number / 1000) + " thousand ";
- number %= 1000;
- }
- if ((number / 100) > 0)
- {
- words += NumberToWords(number / 100) + " hundred ";
- number %= 100;
- }
- if (number > 0)
- {
- if (words != "")
- words += "and ";
- var unitsMap = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
- var tensMap = new[] { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
- if (number < 20)
- words += unitsMap[number];
- else
- {
- words += tensMap[number / 10];
- if ((number % 10) > 0)
- words += "-" + unitsMap[number % 10];
- }
- }
- return words;
- }
- private void loadUserInfo()
- {
- try
- {
- // SQLiteConnection.CreateFile("app.sqlite");
- SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source=app.sqlite;Version=3;");
- m_dbConnection.Open();
- string SQLTableRead = "SELECT * FROM login";
- SQLiteCommand command3 = new SQLiteCommand(SQLTableRead, m_dbConnection);
- //command2.ExecuteNonQuery();
- command3.CommandText = SQLTableRead;
- SQLiteDataReader TableReader = command3.ExecuteReader();
- if (TableReader.Read())
- {
- // MessageBox.Show(TableReader["id"].ToString());
- this.userId = int.Parse(TableReader["loginid"].ToString());
- this.userName = TableReader["username"].ToString();
- this.fullName = TableReader["fullname"].ToString();
- this.userRole = int.Parse(TableReader["role"].ToString());
- this.loginTime = TableReader["time_added"].ToString();
- }
- TableReader.Close();
- m_dbConnection.Close();
- }
- catch (Exception exc)
- {
- MessageBox.Show("Unable to load systemetic info. " + exc.Message.ToString());
- }
- }
- private void button1_Click_1(object sender, EventArgs e)
- {
- Form createPatient = new CreatePatient(this);
- createPatient.Show();
- }
- private void printPreviewDialog1_Load(object sender, EventArgs e)
- {
- }
- private void tbxOverallDiscount_KeyDown(object sender, KeyEventArgs e)
- {
- }
- private void tbxOverallDiscount_KeyUp(object sender, KeyEventArgs e)
- {
- decimal value;
- bool isParsed = decimal.TryParse(tbxOverallDiscount.Text.Trim(), out value);
- if (!isParsed)
- {
- MessageBox.Show("Invalid decimal value", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- tbxOverallDiscount.Clear();
- tbxOverallDiscount.Focus();
- }
- else
- {
- tbxGrandTotal.Text = (Decimal.Parse(tbxSubTotal.Text) - value).ToString();
- }
- }
- private void tbxAdvance_KeyUp(object sender, KeyEventArgs e)
- {
- decimal value;
- bool isParsed = decimal.TryParse(tbxAdvance.Text.Trim(), out value);
- if (!isParsed)
- {
- MessageBox.Show("Invalid decimal value", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- tbxAdvance.Clear();
- tbxAdvance.Focus();
- }
- else
- {
- int grandTotal;
- int advance;
- grandTotal = decimal.ToInt32(decimal.Parse(tbxGrandTotal.Text));
- advance = decimal.ToInt32(value);
- if (grandTotal <= advance)
- {
- lblStatus.Text = "Paid";
- lblStatus.ForeColor = System.Drawing.Color.Green;
- }
- else
- {
- lblStatus.Text = "Due";
- lblStatus.ForeColor = System.Drawing.Color.Red;
- }
- }
- }
- private void printDocument1_EndPrint(object sender, PrintEventArgs e)
- {
- }
- private bool save_pc_info(int invID)
- {
- // MessageBox.Show(invID.ToString());
- bool is_cussess = false;
- try
- {
- MySqlConnection con = new MySqlConnection(this.conString);
- MySqlCommand command = con.CreateCommand();
- command.CommandText = "INSERT INTO `dms_pc_percentage` (`pp_id`, `pc_id`, `pp_amount`, `pp_invoice`, `pp_paid`, `time_added`, `time_updated`, `status`) VALUES (NULL, @pc_id , @pp_amount , @pp_invoice , NULL, CURDATE() , CURRENT_TIMESTAMP, '1');";
- command.Parameters.AddWithValue("@pc_id", this.reffererID);
- command.Parameters.AddWithValue("@pp_amount", decimal.Parse(tbxPcPercentage.Text.Trim()));
- command.Parameters.AddWithValue("@pp_invoice", invID);
- con.Open();
- int a = command.ExecuteNonQuery();
- if (a > 0)
- {
- is_cussess = true;
- }
- else
- {
- is_cussess = false;
- }
- con.Close();
- }
- catch (MySqlException exc)
- {
- MessageBox.Show(exc.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- return is_cussess;
- }
- private void disableAllControl()
- {
- btnPrint.Enabled = false;
- }
- private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
- {
- DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
- if (row.Cells[2].Value != null)
- {
- this.tmpPC = decimal.Parse(row.Cells[2].Value.ToString());
- this.tmpAmount = decimal.Parse(row.Cells[3].Value.ToString());
- }
- }
- private void dataGridView1_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
- {
- this.totalAmount -= this.tmpAmount;
- this.totalDiscount -= this.tmpPC;
- tbxPcPercentage.Text = this.totalDiscount.ToString();
- tbxSubTotal.Text = this.totalAmount.ToString();
- tbxGrandTotal.Text = this.totalAmount.ToString();
- }
- private void tbxOverallDiscount_Leave(object sender, EventArgs e)
- {
- }
- private void tbxOverallDiscount_TextChanged(object sender, EventArgs e)
- {
- if (tbxPcPercentage.Text.Trim() != String.Empty && (Decimal.Parse(tbxPcPercentage.Text) > Decimal.Parse(tbxOverallDiscount.Text)))
- {
- Decimal totalPcPercentage = Decimal.Parse(tbxPcPercentage.Text) - Decimal.Parse(tbxOverallDiscount.Text);
- tbxPcPercentage.Text = totalPcPercentage.ToString();
- }
- }
- private void printPreviewDialog1_FormClosed(object sender, FormClosedEventArgs e)
- {
- Form billCreation = new Bill_Creation();
- this.Dispose();
- billCreation.Show();
- }
- private bool getPatientInfoWithID(int patientId)
- {
- bool count;
- MySqlConnection Con = new MySqlConnection(this.conString);
- MySqlCommand Command = Con.CreateCommand();
- Command.CommandText = "SELECT * FROM `dms_patient` WHERE `patient_id` = @pid ";
- Command.Parameters.AddWithValue("@pid", patientId);
- // Command.Parameters.AddWithValue("@term", term);
- Con.Open();
- MySqlDataReader Reader = Command.ExecuteReader();
- if (Reader.Read())
- {
- count = true;
- this.patientID = int.Parse(Reader["patient_id"].ToString());
- this.patientName = Reader["patient_name"].ToString();
- this.PatientAge = Reader["patient_age"].ToString();
- this.patientMobile = Reader["patient_mobile"].ToString();
- this.patientSex = Reader["patient_sex"].ToString();
- }
- else
- {
- count = false;
- }
- tbxRefferedBy.Focus();
- return count;
- }
- public void loadPatientDuringCreatePatient(int patientID)
- {
- // MessageBox.Show(patientID.ToString());
- if (getPatientInfoWithID(patientID))
- {
- tbxPatientID.Text = this.patientID.ToString();
- tbxPatientName.Text = this.patientName;
- tbxPatientMobile.Text = this.patientMobile;
- tbxAge.Text = this.PatientAge;
- cbxPatientGender.SelectedIndex = cbxPatientGender.Items.IndexOf(this.patientSex);
- tbxPatientID.Enabled = false;
- tbxPatientMobile.Enabled = false;
- tbxPatientName.Enabled = false;
- cbxPatientGender.Enabled = false;
- tbxAge.Enabled = false;
- tbxSearch.Enabled = false;
- tbxSearch.Enabled = true;
- tbxRefferedBy.Focus();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement