예제 #1
0
        private void Get_Customers()
        {
            ExcoODBC instance = ExcoODBC.Instance;

            #region Get All Customers
            Customer_List = new List <Customer>();
            string query = "select customercode, name, pricelist from d_customer";
            instance.Open(masterDB);
            OdbcDataReader reader = instance.RunQuery(query);
            while (reader.Read())
            {
                Customer c = new Customer();
                c.custCode = reader[0].ToString().Trim();
                c.Name     = reader[1].ToString().Trim();
                c.PLCode   = reader[2].ToString().Trim();
                Customer_List.Add(c);
            }
            reader.Close();
            #endregion

            // Select database
            using (var DBS = new DatabaseSelector(parent, Customer_List, "Select Customer", this.Location, this.Size, false))
            {
                var returnv = DBS.ShowDialog();

                // If database valid
                if (returnv == DialogResult.OK && DBS.dbName.Length > 0)
                {
                    Ref_CustCode = DBS.dbName.Substring(DBS.dbName.Length - 7, 6);// Force form to redraw
                }
            }
        }
예제 #2
0
        private void Import_Charges()
        {
            ExcoODBC instance = ExcoODBC.Instance;

            string custname = "";

            #region Get Ref PL Code
            string query = "select pricelist, name from d_customer where customercode = '" + Ref_CustCode + "'";
            instance.Open(masterDB);
            OdbcDataReader reader = instance.RunQuery(query);
            while (reader.Read())
            {
                Ref_PLCode = reader[0].ToString().Trim();
                custname   = reader[1].ToString().Trim();
            }
            reader.Close();
            #endregion

            itemCharges ic;

            query = "select plcode, prefix, chargename, chargeprice, chargepercentage, maxqty from d_pricelistitemcharges where prefix like '" + Get_Die_Prefix((DieType)System.Enum.Parse(typeof(DieType), dieTypes.Text)) + "' " +
                    "and plcode = '" + Ref_PLCode + "' " + (custname.ToLower().Contains("sapa") ? "and chargename like '%sapa%'" : "and chargename not like '%sapa%'");

            instance.Open(masterDB);
            reader = instance.RunQuery(query);
            while (reader.Read())
            {
                ic            = new itemCharges();
                ic.chargeName = reader[2].ToString().Trim();
                ic.flatPrice  = Convert.ToDouble(reader[3].ToString().Trim());
                ic.percPrice  = Convert.ToDouble(reader[4].ToString().Trim());

                if (ic.percPrice > 0)
                {
                    dataGridView1.Rows.Add(ic.chargeName, "B" + (ic.percPrice / 100));
                }
                else
                {
                    dataGridView1.Rows.Add(ic.chargeName, "F" + ic.flatPrice);
                }
            }
            reader.Close();
            dataGridView1.Rows.Add("");

            // Remove last delete button
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                DataGridViewCellStyle style = new DataGridViewCellStyle();
                style.Padding      = new Padding(0, 0, (row == dataGridView1.Rows[dataGridView1.Rows.Count - 1] ? 1000 : 0), 0);
                style.BackColor    = Color.FromArgb(76, 76, 76);
                style.ForeColor    = Color.White;
                row.Cells[2].Style = style;
            }

            Save_Charges(dieTypes.Text);
        }
예제 #3
0
        private void button4_Click(object sender, EventArgs e)
        {
            Grey_Out();
            ExcoODBC instance = ExcoODBC.Instance;

            #region Get All Customers
            Customer_List = new List <Customer>();
            string query = "select customercode, name, pricelist from d_customer";
            instance.Open(masterDB);
            OdbcDataReader reader = instance.RunQuery(query);
            while (reader.Read())
            {
                Customer c = new Customer();
                c.custCode = reader[0].ToString().Trim();
                c.Name     = reader[1].ToString().Trim();
                c.PLCode   = reader[2].ToString().Trim();
                Customer_List.Add(c);
            }
            reader.Close();
            #endregion

            string custName = "";

            // Select database
            using (var DBS = new DatabaseSelector(parent, Customer_List, "Select Customer", this.Location, this.Size, false, "SAVE"))
            {
                var returnv = DBS.ShowDialog();

                // If database valid
                if (returnv == DialogResult.OK && DBS.dbName.Length > 0)
                {
                    Ref_CustCode = DBS.dbName.Substring(DBS.dbName.Length - 7, 6);
                    custName     = DBS.dbName.Substring(0, (DBS.dbName.Length - 9)).Length > 20 ? DBS.dbName.Substring(0, (DBS.dbName.Length - 9)).Substring(0, 20) : DBS.dbName.Substring(0, (DBS.dbName.Length - 9));
                }
            }

            #region Background save charges to retain later
            // create appData directory
            if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\ExcoPricingTool"))
            {
                Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\ExcoPricingTool");
            }

            string rootPath = "EPT-" + Ref_CustCode + "-" + custName + ".ecf";

            // Remove illegal path characters
            string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());

            foreach (char c in invalid)
            {
                rootPath = rootPath.Replace(c.ToString(), "");
            }

            string combRootPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\ExcoPricingTool\\" + rootPath;

            // Try and delete existing file
            try
            {
                File.Delete(combRootPath);
            }
            catch { }

            List <string> Lines = new List <string>();

            //save charges
            foreach (KeyValuePair <DieType, List <DieCharge> > Die_KVP in parent.Charge_Dictionary)
            {
                foreach (DieCharge DC in Die_KVP.Value)
                {
                    Lines.Add("DC" +
                              "|[D]=" + DC.Dietype +
                              "|[N]=" + DC.Name +
                              "|[F]=" + DC.Formula);
                }
            }

            //File.WriteAllLines(rootPath, Lines);
            File.WriteAllText(combRootPath, parent.Encrypt_Line(String.Join(Environment.NewLine, Lines)));
            #endregion

            Grey_In();
        }