static void initPrintDocument() { using (pd = new PrintDocument()) { pd.DocumentName = "ใบเสร็จค่าสินค้า"; pd.PrinterSettings.PrinterName = printerName; GF.checkPaperSize(pd); GF.checkPaperSource(pd); GF.printError("THIS RAW KIND : " + rawKind); GF.printError("THIS PAPER SIZE : " + paperSize); if (rawKind != 0) { pd.DefaultPageSettings.PaperSize.RawKind = rawKind; } if (paperSize != null) { pd.DefaultPageSettings.PaperSize = paperSize; } GF.printError(pd.DefaultPageSettings.PaperSize.Width.ToString() + " x " + pd.DefaultPageSettings.PaperSize.Height.ToString()); GF.printError("PD RAW KIND : " + pd.DefaultPageSettings.PaperSize.RawKind); GF.printError("PD PAPER SIZE : " + pd.DefaultPageSettings.PaperSize); if (printerResolution != null) { pd.DefaultPageSettings.PrinterResolution = printerResolution; } pd.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0); pd.PrintPage += (sender, e) => { int FontSize = 8; string FontName = "Calibri"; regular = new Font(FontName, FontSize); boldUnderline = new Font(FontName, FontSize, (FontStyle.Bold | FontStyle.Underline)); bold = new Font(FontName, FontSize, FontStyle.Bold); brush = new SolidBrush(Color.Black); alignRight = new StringFormat(); alignRight.Alignment = StringAlignment.Far; int width = e.MarginBounds.Width; string vat = ""; string net_price_before_vat = ""; string vat_amount = ""; string total_amount = ""; string cashier_name = ""; Dictionary <string, string> values = new() { { "bill_id", bill_id }, { "issue_vat", (hasVat ? "1" : "0") } }; Dictionary <string, object> Obj = DB.Post("Shop/getBillHeader/", values); int top = 10; if (Obj != null) { if (Obj.ContainsKey("result")) { Dictionary <string, object> item = GF.ToType <Dictionary <string, object> >(Obj["result"]); if (item.Keys.Count > 0) { bill_no = item["bill_no"].ToString(); print_bill_header.draw(e, item["branch_id"].ToString(), out top); top += 65; e.Graphics.DrawString("ใบเสร็จรับเงิน / ใบกำกับภาษีอย่างย่อ", boldUnderline, brush, new PointF((float)(((width - GF.margin_right) / 2) - (e.Graphics.MeasureString("ใบเสร็จรับเงิน / ใบกำกับภาษีอย่างย่อ", boldUnderline).Width / 2)), top)); top += 25; e.Graphics.DrawString("หมายเลขใบเสร็จ", bold, brush, new PointF((e.MarginBounds.Width) - e.Graphics.MeasureString(": " + bill_no, regular).Width - e.Graphics.MeasureString("หมายเลขใบเสร็จ", bold).Width - GF.margin_right + GF.margin_left, top)); e.Graphics.DrawString(": " + bill_no, regular, brush, new RectangleF(GF.margin_left, top, e.MarginBounds.Width - GF.margin_right, 15), alignRight); top += 20; e.Graphics.DrawString("วันที่", bold, brush, new PointF((e.MarginBounds.Width) - e.Graphics.MeasureString(": " + GF.formatDBDateTime(item["bill_datetime"].ToString()), regular).Width - e.Graphics.MeasureString("วันที่", bold).Width - GF.margin_right + GF.margin_left, top)); e.Graphics.DrawString(": " + GF.formatDBDateTime(item["bill_datetime"].ToString()), regular, brush, new RectangleF(GF.margin_left, top, e.MarginBounds.Width - GF.margin_right, 15), alignRight); vat = item["vat"].ToString(); vat_amount = item["vat_amount"].ToString(); net_price_before_vat = item["net_price_before_vat"].ToString(); total_amount = item["total_price"].ToString(); cashier_name = item["receive_by"].ToString(); } } } string seps = ""; while (e.Graphics.MeasureString(seps, regular).Width < e.MarginBounds.Width) { seps += "-"; } /*top += 25; * e.Graphics.DrawString(seps, regular, brush, new PointF(left, top));*/ values = new() { { "bill_no", bill_no } }; Obj = DB.Post("Shop/getDataByBillNo/", values); if (Obj != null) { if (Obj.ContainsKey("result")) { Dictionary <string, object> item = GF.ToType <Dictionary <string, object> >(Obj["result"]); if (item.Keys.Count > 0) { string Product_Data = item["product_data"].ToString(); string[] tmp_data = Product_Data.Split(new string[] { "!!" }, StringSplitOptions.None); foreach (string product in tmp_data) { string[] Item = product.Split(new string[] { "##" }, StringSplitOptions.None); top += 20; string item_name = Item[3].ToString() + " x " + Item[0].ToString() + " @" + Item[1].ToString() + ".00"; e.Graphics.DrawString(item_name, regular, brush, new RectangleF(GF.margin_left, top, e.MarginBounds.Width - e.Graphics.MeasureString(item_name, regular).Width - GF.margin_right, 15)); e.Graphics.DrawString(GF.formatNumber(Item[4].ToString()) + ".00", regular, brush, new RectangleF(GF.margin_left, top, e.MarginBounds.Width - GF.margin_right, 15), alignRight); } //======================================= SUB TOTAL ======================================// top += 20; e.Graphics.DrawString("ราคารวมก่อนภาษี", bold, brush, new PointF((e.MarginBounds.Width) - e.Graphics.MeasureString(": " + net_price_before_vat, bold).Width - e.Graphics.MeasureString("ราคารวมก่อนภาษี :", bold).Width - GF.margin_right + GF.margin_left, top)); e.Graphics.DrawString(": " + net_price_before_vat, bold, brush, new RectangleF(GF.margin_left, top, e.MarginBounds.Width - GF.margin_right, 15), alignRight); top += 20; e.Graphics.DrawString("ภาษี " + string.Format("{0:f2}", Convert.ToDouble(vat)) + "%", bold, brush, new PointF((e.MarginBounds.Width) - e.Graphics.MeasureString(": " + vat_amount, bold).Width - e.Graphics.MeasureString("ภาษี " + string.Format("{0:f2}", Convert.ToDouble(vat)) + "% : ", bold).Width - GF.margin_right + GF.margin_left, top)); e.Graphics.DrawString(": " + vat_amount, bold, brush, new RectangleF(GF.margin_left, top, e.MarginBounds.Width - GF.margin_right, 15), alignRight); top += 20; e.Graphics.DrawString("รวมเป็นเงิน", bold, brush, new PointF((e.MarginBounds.Width) - e.Graphics.MeasureString(": " + GF.formatNumber(total_amount) + ".00", bold).Width - e.Graphics.MeasureString("รวมเป็นเงิน :", bold).Width - GF.margin_right + GF.margin_left, top)); e.Graphics.DrawString(": " + GF.formatNumber(total_amount) + ".00", bold, brush, new RectangleF(GF.margin_left, top, e.MarginBounds.Width - GF.margin_right, 15), alignRight); top += 15; e.Graphics.DrawString(seps, regular, brush, new PointF(GF.margin_left, top)); //======================================= PAYMENT ======================================// string Payment_Data = item["payment_data"].ToString(); tmp_data = Payment_Data.Split(new string[] { "!!" }, StringSplitOptions.None); foreach (string payment in tmp_data) { string[] Item = payment.Split(new string[] { "##" }, StringSplitOptions.None); top += 20; if (Item[0].ToString() == "0") { // CASH e.Graphics.DrawString("เงินสด", bold, brush, new PointF((e.MarginBounds.Width) - e.Graphics.MeasureString(": " + GF.formatNumber(Item[1].ToString()) + ".00", bold).Width - e.Graphics.MeasureString("เงินสด", bold).Width - GF.margin_right + GF.margin_left, top)); } else if (Item[0].ToString() == "1") { // CARD string last4Digits = Item[2].ToString().Substring(Item[2].ToString().Length - 4, 4); e.Graphics.DrawString("บัตร XXXX-XXXX-XXXX-" + last4Digits, bold, brush, new PointF((e.MarginBounds.Width) - e.Graphics.MeasureString(": " + GF.formatNumber(Item[1].ToString()) + ".00", bold).Width - e.Graphics.MeasureString("บัตร XXXX-XXXX-XXXX-" + last4Digits, bold).Width - GF.margin_right + GF.margin_left, top)); } e.Graphics.DrawString(": " + GF.formatNumber(Item[1].ToString()) + ".00", bold, brush, new RectangleF(GF.margin_left, top, e.MarginBounds.Width - GF.margin_right, 15), alignRight); } } } } top += (13 * 3); e.Graphics.DrawString("ผู้รับเงิน : " + cashier_name, bold, brush, new PointF((float)(((width - GF.margin_right) / 2) - (e.Graphics.MeasureString("ผู้รับเงิน : " + cashier_name, bold).Width / 2)), top)); top += (20); string print_datetime = GF.NOW(); e.Graphics.DrawString("พิมพ์เมื่อ : " + print_datetime, bold, brush, new PointF((float)(((width - GF.margin_right) / 2) - (e.Graphics.MeasureString("พิมพ์เมื่อ : " + print_datetime, bold).Width / 2)), top)); top += (13 * 2); CreateBarcode(bill_no, e, top); e.Graphics.Dispose(); }; pd.EndPrint += (sender, e) => { if (e.PrintAction == PrintAction.PrintToPrinter) { if (PPD != null && !PPD.IsDisposed) { PPD.Close(); } Sender.Activate(); GF.closeLoading(); } }; GF.closeLoading(); using (PPD = new PrintPreviewDialog()) { ((Form)PPD).FormClosed += (ss, ee) => { Sender.Activate(); }; ((Form)PPD).TopMost = true; ((Form)PPD).WindowState = FormWindowState.Maximized; ((Form)PPD).FormBorderStyle = FormBorderStyle.None; PPD.Document = pd; PPD.PrintPreviewControl.Zoom = 1; PPD.PrintPreviewControl.UseAntiAlias = true; PPD.Document.OriginAtMargins = false; if (isPreview) { PPD.ShowDialog(); } else { pd.Print(); } } }
private void member_manage_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(member_id.Trim())) { GF.showLoading(this); Dictionary <string, string> values = new() { { "member_id", member_id.Trim() } }; Dictionary <string, object> Obj = DB.Post("Member/getMemberData/", values); if (Obj != null) { if (Obj.ContainsKey("result")) { Dictionary <string, object> Item = GF.ToType <Dictionary <string, object> >(Obj["result"]); if (Item.Keys.Count > 0) { member_no.Text = (Item["member_no"] ?? "").ToString(); current_member_type.Text = (Item["current_member_type"] ?? "").ToString(); during_date.Text = (Item["during_date"] ?? "").ToString(); first_date.Text = GF.formatDBDateTime((Item["create_date"] ?? "").ToString()); current_contract_no.Text = (Item["contract_no"] ?? "").ToString(); firstname_th.Text = (Item["firstname_th"] ?? "").ToString(); lastname_th.Text = (Item["lastname_th"] ?? "").ToString(); nickname_th.Text = (Item["nickname_th"] ?? "").ToString(); firstname_en.Text = (Item["firstname_en"] ?? "").ToString(); lastname_en.Text = (Item["lastname_en"] ?? "").ToString(); nickname_en.Text = (Item["nickname_en"] ?? "").ToString(); martial_status.Text = Item["martial_status"].ToString(); if (!string.IsNullOrEmpty((Item["birthday"] ?? "").ToString())) { birthday.Text = Item["birthday"].ToString(); current_age.Text = GF.calculateAge(Item["birthday"].ToString()); } if (!string.IsNullOrEmpty((Item["document_type"] ?? "").ToString())) { document_type.Text = Item["document_type"].ToString(); } document_no.Text = (Item["document_no"] ?? "").ToString(); email.Text = (Item["email"] ?? "").ToString(); occupation.Text = (Item["occupation"] ?? "").ToString(); gender.Text = Item["gender"].ToString(); address.Text = (Item["address"] ?? "").ToString(); company_name.Text = (Item["company_name"] ?? "").ToString(); work_phone.Text = (Item["work_phone"] ?? "").ToString(); home_phone.Text = (Item["home_phone"] ?? "").ToString(); mobile_phone.Text = (Item["mobile_phone"] ?? "").ToString(); emergency_contact_name.Text = (Item["emergency_contact_name"] ?? "").ToString(); emergency_contact_phone.Text = (Item["emergency_contact_phone"] ?? "").ToString(); emergency_contact_relationship.Text = (Item["emergency_contact_relationship"] ?? "").ToString(); weight.Text = (Item["weight"] ?? "").ToString(); height.Text = (Item["height"] ?? "").ToString(); congenital_disease.Text = (Item["congenital_disease"] ?? "").ToString(); pictureFilename = (Item["image_file"] ?? "").ToString(); if (!string.IsNullOrEmpty(pictureFilename.Trim())) { GF.getImage(pictureFilename, ref picture, "member_picture"); } } } } GF.closeLoading(); } else { picture.Visible = false; } }
private void member_pt_Load(object sender, EventArgs e) { GF.showLoading(this); if (onlySee) { disableAll(); } if (isForceEdit || isForceAdd) { amount_left_lbl1.Visible = amount_left.Visible = amount_left_lbl2.Visible = true; seller_emp_lbl.Visible = seller_emp_id.Visible = true; GF.disableBtn(add_payment_btn); payment_DGV.Enabled = false; } if (isAlreadyVoided) { amount_left.Enabled = false; seller_emp_id.Enabled = false; } Dictionary <string, string> values = new() { { "branch_id", ((isForceAdd || isForceEdit || onlySee) ? "-1" : GF.Settings("branch_id")) } }; Dictionary <string, object> Obj = DB.Post("PT/PTList/", values); if (Obj != null) { if (!isForceAdd && !isForceEdit) { pt_emp_id.Items.Add(new ComboItem(0, "เลือก 'เทรนเนอร์'")); } if (Obj.ContainsKey("result")) { foreach (Dictionary <string, object> Item in GF.ToType <Dictionary <string, object>[]>(Obj["result"])) { pt_emp_id.Items.Add(new ComboItem(GF.toInt(Item["emp_id"].ToString()), Item["fullname"].ToString() + " (" + Item["nickname"].ToString() + ")")); seller_emp_id.Items.Add(new ComboItem(GF.toInt(Item["emp_id"].ToString()), Item["fullname"].ToString() + " (" + Item["nickname"].ToString() + ")")); } } pt_emp_id.SelectedIndex = 0; seller_emp_id.SelectedIndex = 0; GF.resizeComboBox(pt_emp_id); GF.resizeComboBox(seller_emp_id); } else { GF.Error("ไม่มีข้อมูล 'เทรนเนอร์' !!\r\n\r\nกรุณาแจ้งผู้ดูแลระบบ !!"); } // GET BUY PT DATA if (!string.IsNullOrEmpty(member_pt_id)) { values = new() { { "member_pt_id", member_pt_id.Trim() } }; Obj = DB.Post("Member/getBuyPTData/", values); if (Obj != null) { if (Obj.ContainsKey("result")) { Dictionary <string, object> Item = GF.ToType <Dictionary <string, object> >(Obj["result"]); if (Item.Keys.Count > 0) { hours.Text = Item["max_hours"].ToString(); start_date.Text = (Item["start_date"] ?? "").ToString(); expiry_date.Text = Item["expiry_date"].ToString(); price.Text = Item["price"].ToString(); age.Text = (Item["age"] ?? "").ToString(); amount_left.Text = (Item["left_hours"] ?? "").ToString(); note_txt.Text = (Item["note"] ?? "").ToString(); foreach (ComboItem cb in pt_emp_id.Items) { if (cb.Key.ToString() == Item["pt_emp_id"].ToString()) { pt_emp_id.Text = cb.Value; } } foreach (ComboItem cb in seller_emp_id.Items) { if (cb.Key.ToString() == Item["pt_seller_id"].ToString()) { seller_emp_id.Text = cb.Value; } } string payment_data = (Item["payment_data"] ?? "").ToString().Trim(); if (!string.IsNullOrEmpty(payment_data)) { payment_DGV.Rows.Clear(); string[] payment_record = payment_data.Split(new string[] { "!!" }, StringSplitOptions.None); foreach (string payment_item in payment_record) { string[] tmp = payment_item.Split(new string[] { "##" }, StringSplitOptions.None); string the_payment_type = Array.Find(GF.payment_type, p => Convert.ToInt32(p.Key) == Convert.ToInt32(tmp[0].ToString())).Value; string[] Data = { the_payment_type, tmp[1].ToString(), (tmp[2] ?? "").ToString(), (tmp[3] ?? "").ToString(), tmp[4].ToString(), GF.formatDBDateTime(tmp[5].ToString()), tmp[6].ToString(), tmp[7].ToString() }; GF.addPaymentRow(payment_DGV, Data, tmp[6].ToString()); } payment_DGV.ClearSelection(); } } } } } GF.closeLoading(); }
private void bill_no_KeyUp(object sender, KeyEventArgs e) { if (!string.IsNullOrEmpty(bill_no.Text.Trim()) && e.KeyCode == Keys.Enter) { GF.showLoading(this); Dictionary <string, string> values = new() { { "bill_no", bill_no.Text.Trim() } }; Dictionary <string, object> Obj = DB.Post("Shop/getDataByBillNo/", values); if (Obj != null) { if (Obj.ContainsKey("result")) { Dictionary <string, object> item = GF.ToType <Dictionary <string, object> >(Obj["result"]); if (item.Keys.Count > 0) { string Product_Data = item["product_data"].ToString(); string Payment_Data = item["payment_data"].ToString(); (this.Owner as shop).bill_id = item["bill_id"].ToString(); if (item["is_void"].ToString() == "0" && GF.isAdmin) { (this.Owner as shop).void_btn.Visible = true; (this.Owner as shop).void_txt.Visible = false; (this.Owner as shop).void_txt.Left = 273; } if (item["is_void"].ToString() == "1") { (this.Owner as shop).void_txt.Visible = true; (this.Owner as shop).void_txt.Text = "*** บิลถูก VOID : " + item["void_reason"].ToString() + " ***\r\nโดย : " + item["void_by"].ToString() + " เมื่อ " + GF.formatDBDateTime(item["void_datetime"].ToString()); (this.Owner as shop).void_txt.Left = (this.Owner as shop).void_btn.Left; } string[] tmp_data = Product_Data.Split(new string[] { "!!" }, StringSplitOptions.None); foreach (string product in tmp_data) { string[] Item = product.Split(new string[] { "##" }, StringSplitOptions.None); (this.Owner as shop).addRow(Item[0].ToString(), Item[1].ToString(), Item[2].ToString(), Item[3].ToString(), Item[5].ToString(), Item[6].ToString(), Item[7].ToString()); } tmp_data = Payment_Data.Split(new string[] { "!!" }, StringSplitOptions.None); foreach (string payment in tmp_data) { string[] Item = payment.Split(new string[] { "##" }, StringSplitOptions.None); DataGridView DGV = (this.Owner as shop).payment_DGV; DGV.Rows.Add( GF.payment_type[Convert.ToInt32(Item[0].ToString())], GF.formatNumber(Convert.ToInt32(Item[1].ToString())), (Item[2] ?? "").ToString(), (Item[3] ?? "").ToString(), Item[4].ToString(), GF.formatDBDateTime(Item[5].ToString()), Item[0].ToString() ); } (this.Owner as shop).product_DGV.ClearSelection(); (this.Owner as shop).payment_DGV.ClearSelection(); (this.Owner as shop).bill_search_btn.Text = "เปิดบิลใหม่"; (this.Owner as shop).product_code.Enabled = false; GF.disableBtn((this.Owner as shop).add_product_btn); (this.Owner as shop).product_DGV.Enabled = false; GF.disableBtn((this.Owner as shop).add_payment_btn); (this.Owner as shop).payment_DGV.Enabled = false; GF.disableBtn((this.Owner as shop).manage_btn); (this.Owner as shop).print_btn.Visible = true; (this.Owner as shop).print_btn.Left = (this.Owner as shop).manage_btn.Left; (this.Owner as shop).print_btn.Top = (this.Owner as shop).manage_btn.Top; (this.Owner as shop).print_btn.BringToFront(); } } } GF.closeLoading(); this.Close(); } }