static void doPrint()
        {
            try
            {
                print_receipt.printerResolution = new PrinterResolution();
                GF.printError("INIT PRINT DOCUMENT FOR 'SHOP RECEIPT' ...");

                if (GF.Settings("receipt_printer") == "")
                {
                    GF.Error("ไม่พบ PRINTER สำหรับออกใบเสร็จ !!");
                    GF.closeLoading();
                }
                else if (GF.Settings("receipt_printer") == "ไม่มี")
                {
                    GF.Error("ไม่สามารถพิมพ์ใบเสร็จได้ จนกว่าจะตั้งค่า PRINTER สำหรับออกใบเสร็จ !!");
                    GF.closeLoading();
                    return;
                }
                else
                {
                    print_receipt.printerName = GF.Settings("receipt_printer");
                    GF.printError("PRINTER : " + print_receipt.printerName);
                }

                initPrintDocument();
            }
            catch (Exception e)
            {
                GF.printError(e.Message + "\r\n\r\n" + e.StackTrace.ToString());
                GF.Error(e.Message, "PRINTER ERROR !!");
                GF.closeLoading();
            }
        }
Esempio n. 2
0
        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            try
            {
                GF.closeLoading();
                Exception ex = (Exception)e.Exception;

                GF.printError("********** THREAD FATAL ERROR **********");
                GF.printError("[" + ex.TargetSite.ToString() + "]");
                GF.printError(ex.ToString() + "\r\n");

                GF.printError("FILE : " + new StackTrace(ex, true).GetFrame(0).GetFileName());
                GF.printError("LINE : " + new StackTrace(ex, true).GetFrame(0).GetFileLineNumber());

                GF.printError("STACK-TRACE : \r\n" + ex.StackTrace.ToString() + "\r\n");

                waitHandle.WaitOne();
            }
            finally
            {
                foreach (Process theProcess in Process.GetProcessesByName("EXCEL"))
                {
                    theProcess.Kill();
                }

                if (currentProcess != null)
                {
                    foreach (Process theProcess in Process.GetProcessesByName("FAMS"))
                    {
                        theProcess.Kill();
                    }
                }
                System.Environment.Exit(0);
            }
        }
 public static void checkPaperSource(System.Drawing.Printing.PrintDocument pd)
 {
     GF.printError("********** PAPER SOURCE **********");
     foreach (System.Drawing.Printing.PaperSource source in pd.PrinterSettings.PaperSources)
     {
         GF.printError("**** [" + source.RawKind.ToString() + "][" + source.Kind.ToString() + "] " + source.SourceName);
     }
 }
 public static void checkPaperSize(System.Drawing.Printing.PrintDocument pd)
 {
     GF.printError("********** PAPER SIZE **********");
     foreach (System.Drawing.Printing.PaperSize size in pd.PrinterSettings.PaperSizes)
     {
         GF.printError("**** [" + size.RawKind.ToString() + "][" + size.Kind.ToString() + "] " + size.Width.ToString() + "x" + size.Height.ToString());
     }
 }
Esempio n. 5
0
        public void calculateExpiryDate()
        {
            if (string.IsNullOrEmpty(start_date.Text.Replace(" ", "").Replace("/", "").Trim()))
            {
                expiry_date.Text = "-";
                return;
            }

            if (start_date.Text.Trim().Length < 10)
            {
                expiry_date.Text = "-";
                return;
            }

            if (string.IsNullOrEmpty(age.Text.Trim()))
            {
                expiry_date.Text = "-";
                return;
            }

            if (Convert.ToInt32(age.Text.Trim()) <= 0)
            {
                expiry_date.Text = "-";
                return;
            }

            int months = Convert.ToInt32(age.Text.Trim());

            string[] tmpDate = start_date.Text.Split('/');

            if (!DateTime.TryParse(((Convert.ToInt32(tmpDate[2]) - 543)).ToString("0000") + "-" + Convert.ToInt32(tmpDate[1]).ToString("00") + "-" + Convert.ToInt32(tmpDate[0]).ToString("00"), out var DateStart))
            {
                string errTxt = "วัน เดือน ปี ไม่อยู่ในรูปแบบที่ถูกต้อง !\r\nค่าปัจจุบัน : " + start_date;
                GF.printError("***" + errTxt + "*** (DateTime.TryParse @ member_pt.calculateExpiryDate)");
                //GF.submitErrorLog();
                GF.Error(errTxt);
                return;
            }

            DateTime DateEnd = DateStart.AddMonths(months).AddDays(-1);

            expiry_date.Text = DateEnd.Day.ToString("00") + "/" + DateEnd.Month.ToString("00") + "/" + (DateEnd.Year + 543).ToString("0000");
        }
Esempio n. 6
0
        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            try
            {
                GF.closeLoading();
                Exception ex = (Exception)e.ExceptionObject;

                GF.printError("********** FATAL UNHANDLED EXCEPTION ERROR *********");
                GF.printError("[" + ex.TargetSite.ToString() + "]");
                GF.printError(ex.ToString() + "\r\n");

                GF.printError("FILE : " + new StackTrace(ex, true).GetFrame(0).GetFileName());
                GF.printError("LINE : " + new StackTrace(ex, true).GetFrame(0).GetFileLineNumber());

                GF.printError("STACK-TRACE : \r\n" + ex.StackTrace.ToString() + "\r\n");

                waitHandle.WaitOne();

                /*MessageBox.Show("Whoops! Please contact the developers with the following"
                 + " information:\n\n" + ex.Message + ex.StackTrace,
                 +    "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);*/
            }
            finally
            {
                foreach (Process theProcess in Process.GetProcessesByName("EXCEL"))
                {
                    theProcess.Kill();
                }

                if (currentProcess != null)
                {
                    foreach (Process theProcess in Process.GetProcessesByName("FAMS"))
                    {
                        theProcess.Kill();
                    }
                }

                System.Environment.Exit(0);
            }
        }
        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();
                    }
                }
            }
Esempio n. 8
0
        static void Main()
        {
            try
            {
                waitHandle = new AutoResetEvent(false);
                foreach (Process theProcess in Process.GetProcessesByName("EXCEL"))
                {
                    theProcess.Kill();
                }

                if (Process.GetProcessesByName("FAMS").Length > 1)
                {
                    foreach (Process theProcess in Process.GetProcessesByName("FAMS"))
                    {
                        theProcess.Kill();
                    }
                }

#if !DEBUG
                //if (!IsRunningAsAdministrator()) { Restart(); return; }
#endif

                using (Microsoft.Win32.RegistryKey rkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Control Panel\International", true))
                {
                    rkey.SetValue("sShortDate", "dd/MM/yyyy");
                    rkey.Close();
                }

                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
                Application.ApplicationExit += (ss, ee) =>
                {
                    foreach (Process theProcess in Process.GetProcessesByName("EXCEL"))
                    {
                        theProcess.Kill();
                    }

                    foreach (Process theProcess in Process.GetProcessesByName("FAMS"))
                    {
                        theProcess.Kill();
                    }
                };

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                /*GF.Settings("Reset();
                 * GF.Settings("Save();*/

                Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("FAMS_Settings", true);
                if (key == null)
                {
                    key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("FAMS_Settings");
                    key.SetValue("host_url", "fams.fit-answer.com");
                    key.SetValue("branch_id", "");
                    key.SetValue("tmp_path", "C:\\FAMS\\TMP\\");
                    key.SetValue("member_prefix", "");
                    key.SetValue("localCardPath", "C:\\FAMS\\MEMBERCARD\\");
                    key.SetValue("card_printer", "");
                    key.SetValue("receipt_printer", "");
                    key.SetValue("vat", "");
                    key.SetValue("emp_card", "C:\\FAMS\\EMPCARD\\");
                }
                else
                {
                    if (key.GetValue("host_url") == null)
                    {
                        key.SetValue("host_url", "fams.fit-answer.com");
                    }
                    if (key.GetValue("branch_id") == null)
                    {
                        key.SetValue("branch_id", "");
                    }
                    if (key.GetValue("tmp_path") == null)
                    {
                        key.SetValue("tmp_path", "C:\\FAMS\\TMP\\");
                    }
                    if (key.GetValue("member_prefix") == null)
                    {
                        key.SetValue("member_prefix", "");
                    }
                    if (key.GetValue("localCardPath") == null)
                    {
                        key.SetValue("localCardPath", "C:\\FAMS\\MEMBERCARD\\");
                    }
                    if (key.GetValue("card_printer") == null)
                    {
                        key.SetValue("card_printer", "");
                    }
                    if (key.GetValue("receipt_printer") == null)
                    {
                        key.SetValue("receipt_printer", "");
                    }
                    if (key.GetValue("vat") == null)
                    {
                        key.SetValue("vat", "");
                    }
                    if (key.GetValue("emp_card") == null)
                    {
                        key.SetValue("emp_card", "C:\\FAMS\\EMPCARD\\");
                    }
                }

                //key.SetValue("host_url", "fams.topladyshop.net");
                key.SetValue("host_url", "fams.fit-answer.com");

                bool nullConfig = false;
                foreach (string valueName in key.GetValueNames())
                {
                    Console.WriteLine(valueName + " = " + key.GetValue(valueName));
                }

                foreach (string valueName in key.GetValueNames())
                {
                    if (string.IsNullOrEmpty((key.GetValue(valueName) ?? "").ToString()))
                    {
                        nullConfig = true;
                        break;
                    }
                }
                key.Close();
                key.Dispose();

                GF.cultureList = new List <string>();

                CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);

                foreach (CultureInfo culture in cultures)
                {
                    var region = new RegionInfo(culture.LCID);

                    if (!(GF.cultureList.Contains(region.EnglishName)))
                    {
                        GF.cultureList.Add(region.EnglishName);
                    }
                }

                string tmp_path = GF.Settings("tmp_path");

                if (!Directory.Exists(tmp_path))
                {
                    Directory.CreateDirectory(tmp_path);
                }
                else
                {
                    var di = new DirectoryInfo(tmp_path);

                    foreach (var file in di.GetFiles("*", SearchOption.AllDirectories))
                    {
                        file.Attributes &= ~FileAttributes.ReadOnly;
                    }
                }

                var downloadedMessageInfo = new DirectoryInfo(tmp_path);

                foreach (FileInfo file in downloadedMessageInfo.GetFiles())
                {
                    file.Delete();
                }
                foreach (DirectoryInfo dir in downloadedMessageInfo.GetDirectories())
                {
                    dir.Delete(true);
                }

                GF.CreateDirectoryWithEveryonePermission(tmp_path);

                Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-GB");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");

                if (nullConfig)
                {
                    Console.WriteLine("!! NULL CONFIG !!");
                }
                else
                {
                    Console.WriteLine("^^ HAS CONFIG ^^");
                }

                Global.Capture.StartupCheck();

                if (DB.IsServerAlive())
                {
                    if (DB.IsDBAlive())
                    {
                        if (nullConfig)
                        {
                            Application.Run(new init_config());
                        }
                        else
                        {
                            Application.Run(new Login());
                        }
                    }
                }

                return;
            }
            catch (Win32Exception e)
            {
                GF.printError("********** APPLICATION EXIT WITH CODE (" + e.ErrorCode + ") **********");
                GF.printError(e.Message + "\r\n");

                GF.printError("FILE : " + new StackTrace(e, true).GetFrame(0).GetFileName());
                GF.printError("LINE : " + new StackTrace(e, true).GetFrame(0).GetFileLineNumber());

                GF.printError("STACK-TRACE : \r\n" + e.StackTrace.ToString() + "\r\n");

                if (currentProcess != null)
                {
                    currentProcess.Kill();
                }
                System.Environment.Exit(0);
            }
        }