public SMS()
 {
     db       = new thisDatabase();
     gm       = new GlobalMethod();
     date     = new DateTime();
     portOpen = false;
     InitializeComponent();
     //sendSingleSms("", "");
 }
        public void load_unit_with_desc(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("itmunit", "unit_id, unit_shortcode ||' - '|| unit_desc", "", " ORDER BY unit_shortcode ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "unit_desc";
                cbo.ValueMember   = "unit_id";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_stktransfer_invoice(ComboBox cbo, String whs_code)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("rechdr", "rec_num, rec_num || ' - ' || trnx_date || ' - ' || reference  AS rec_desc", "whs_code='" + whs_code + "' AND trn_type='T' AND (cancel!='Y' OR cancel is null)", "ORDER BY rec_num ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "rec_desc";
                cbo.ValueMember   = "rec_num";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_pr_code(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("prhdr", "pr_code AS pr_code, pr_code ||' - '||reference ||' - '|| pr_date AS pr_desc", " cancel!='Y' ", " ORDER BY pr_code ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "pr_desc";
                cbo.ValueMember   = "pr_code";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_orhdr_inv_not_jrnlz(ComboBox cbo, String out_code)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("orhdr", "ord_code", " jrnlz IS NULL OR jrnlz!='Y' ", " ORDER BY ord_code ASC, out_desc ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "ord_code";
                cbo.ValueMember   = "ord_code";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_paymenttype(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("m10", "mp_code, mp_desc", "", " ORDER BY mp_code ASC, mp_code ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "mp_desc";
                cbo.ValueMember   = "mp_code";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        /*
         *
         * public void load_terms(ComboBox cbo)
         * {
         *  try
         *  {
         *      DataTable dt = new DataTable();
         *      thisDatabase db = new thisDatabase();
         *
         *      dt = db.QueryOnTableWithParams("m10", "mp_code, mp_desc", "isterms='Y' AND (cancel IS NULL OR cancel!='Y')", " ORDER BY mp_desc ASC");
         *      cbo.DataSource = dt;
         *      cbo.DisplayMember = "mp_desc";
         *      cbo.ValueMember = "mp_code";
         *      cbo.SelectedIndex = -1;
         *  }
         *  catch (Exception) { }
         * }
         *
         * public void load_vat(ComboBox cbo)
         * {
         *  try
         *  {
         *      DataTable dt = new DataTable();
         *      thisDatabase db = new thisDatabase();
         *
         *      dt = db.QueryOnTableWithParams("vat", "vat_code, vat_desc", "cancel IS NULL OR cancel!='Y'", "");
         *      cbo.DataSource = dt;
         *      cbo.DisplayMember = "vat_desc";
         *      cbo.ValueMember = "vat_code";
         *      cbo.SelectedIndex = -1;
         *  }
         *  catch (Exception) { }
         * }*/



        /*
         * public static int ToInt(String month)
         * {
         *  try
         *  {
         *      return DateTime.ParseExact(month, "MMMM", System.Globalization.CultureInfo.InvariantCulture).Month;
         *  }
         *  catch (Exception er)
         *  {
         *      MessageBox.Show(er.Message);
         *  }
         *
         *  return 0;
         * } */

        public void load_item_asc_desc(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("items", "item_code, item_desc", "", " ORDER BY item_desc ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "item_desc";
                cbo.ValueMember   = "item_code";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_category(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("itmgrp", "item_grp, grp_desc", "", " ORDER BY item_grp ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "grp_desc";
                cbo.ValueMember   = "item_grp";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_accountingperiod(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("x04", "mo, month_desc", "", " ORDER BY mo ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "month_desc";
                cbo.ValueMember   = "mo";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_userfullname(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("x08", "uid, opr_name", "", " ORDER BY uid ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "opr_name";
                cbo.ValueMember   = "uid";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_openperiod(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("x03", "fy ||'-'|| mo AS mo, fy || ' - ' ||month_desc AS month_desc", "", " ORDER BY \"from\" ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "month_desc";
                cbo.ValueMember   = "mo";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_discount(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("disctbl", "disc_code, disc_desc", "", "ORDER BY disc_code");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "disc_desc";
                cbo.ValueMember   = "disc_code";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_marketsegment(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("market", "mkt_code, mkt_desc", "", "ORDER BY mkt_code");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "mkt_desc";
                cbo.ValueMember   = "mkt_code";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_cartype(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("cartype", "id, ctyp_desc", "", "ORDER BY ctyp_desc");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "ctyp_desc";
                cbo.ValueMember   = "id";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_dr_number(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("pinvhd", "inv_num, reference", "cancel != 'Y'", " ORDER BY inv_num ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "reference";
                cbo.ValueMember   = "inv_num";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_supplier(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("m07", "c_code, c_name", "", " ORDER BY c_name ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "c_name";
                cbo.ValueMember   = "c_code";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        //for supplier ledger
        public void load_account_for_sup_ledger(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("m04", "at_code, at_desc", "dr_cr='C' AND sl='Y'", " ORDER BY at_desc ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "at_desc";
                cbo.ValueMember   = "at_code";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_brand(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("brand", "brd_code, brd_name", "cancel IS NULL OR cancel!='Y'", " ORDER BY brd_name ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "brd_name";
                cbo.ValueMember   = "brd_code";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_payee(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("payee", "payee", "", " ORDER BY payee ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "payee";
                cbo.ValueMember   = "payee";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_charge(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("charge", "chg_code, chg_desc", "", " ORDER BY chg_type ASC, chg_desc ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "chg_desc";
                cbo.ValueMember   = "chg_code";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_whouse(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("whouse", "whs_code, whs_desc", "", "");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "whs_desc";
                cbo.ValueMember   = "whs_code";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_outlet(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("outlet", "out_code, out_desc", "", " ORDER BY out_code ASC, out_code ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "out_desc";
                cbo.ValueMember   = "out_code";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_poinvoice_nonjrnlz(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("pinvhd", "inv_num, inv_num || ' - ' || supl_name || ' - ' || reference AS po_desc", "jrnlz!='Y' AND cancel='N'", "ORDER BY inv_num ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "po_desc";
                cbo.ValueMember   = "inv_num";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_pinvhd_inv_not_jrnlz(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("pinvhd", "inv_num", " jrnlz IS NULL OR jrnlz!='Y' ", " ORDER BY inv_num ASC, out_desc ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "inv_num";
                cbo.ValueMember   = "inv_num";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_poinvoice_return_nonjrnlz(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("prethdr", "pret_num, pret_num || ' - ' || reference || ' - ' || supl_name  AS pret_desc", "(jrnlz='N' OR jrnlz is null) AND cancel is null", "ORDER BY pret_num ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "pret_desc";
                cbo.ValueMember   = "pret_num";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_account_title_code_asc(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("m04", "at_code, at_desc", "", " ORDER BY at_code ASC");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "at_desc";
                cbo.ValueMember   = "at_code";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public void load_rr_number(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt                = db.QueryOnTableWithParams("rechdr", "rec_num AS rec_num, _reference", "trn_type='P' AND cancel !='Y'", "ORDER BY rec_num");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "_reference";
                cbo.ValueMember   = "rec_num";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
 public Form1()
 {
     InitializeComponent();
     db = new thisDatabase();
     disp_list();
     myReportDocument         = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
     crParameterValues        = new ParameterValues();
     crParameterDiscreteValue = new ParameterDiscreteValue();
     //
     g_time = db.get_m99time();
     //MaximizeBox = true;
     MinimizeBox = true;
     // g_number = db.get_m99smsrecipient();
     comp_name = db.get_m99comp_name();
     comp_addr = db.get_m99comp_addr();
     bgWorker.RunWorkerAsync();
 }
        public void load_po_number(ComboBox cbo)
        {
            try
            {
                DataTable    dt = new DataTable();
                thisDatabase db = new thisDatabase();

                dt = db.QueryOnTableWithParams("purhdr", "purc_ord AS pcode, purc_ord ||' - '|| supl_name AS cname", "", " ORDER BY purc_ord ASC");

                //dt = db.QueryBySQLCode("SELECT p.purc_ord AS pcode, p.purc_ord ||' - '|| m7.c_name AS cname FROM " + db.get_schema() + ".purhdr p LEFT JOIN " + db.get_schema() + ".m07 m7 ON p.supl_name=m7.c_code ORDER BY p.purc_ord");
                cbo.DataSource    = dt;
                cbo.DisplayMember = "cname";
                cbo.ValueMember   = "pcode";
                cbo.SelectedIndex = -1;
            }
            catch (Exception) { }
        }
        public String getFullName()
        {
            thisDatabase db = new thisDatabase();
            DataTable    dt = db.QueryOnTableWithParams("x08", "opr_name", "", "");

            String fullName = "";

            try
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    fullName = dt.Rows[i]["opr_name"].ToString();
                }
            }
            catch (Exception)
            {
            }

            return((fullName != null) ? fullName : "NONAME");
        }