예제 #1
0
        public void getPrinterConfig()
        {
            using (var db = new Model.posdbEntities())
            {
                var printertype = (from p in db.terminals
                                   where p.TerminalName == AppConfig.MacAddress
                                   select new { PrinterType = p.PrinterType }).SingleOrDefault();

                if (printertype != null)
                {
                    AppConfig.PrinterType = printertype.PrinterType.ToString();
                    if (AppConfig.PrinterType == "80")
                    {
                        mmPaperToolStripMenuItem.Checked  = true;
                        mmPaperToolStripMenuItem1.Checked = false;
                    }
                    else if (AppConfig.PrinterType == "60")
                    {
                        mmPaperToolStripMenuItem.Checked  = false;
                        mmPaperToolStripMenuItem1.Checked = true;
                    }
                }
                else
                {
                    terminal ter = new terminal();
                    ter.StoreID           = 1;
                    ter.TerminalName      = AppConfig.MacAddress;
                    ter.PrinterType       = 80;
                    AppConfig.PrinterType = "80".ToString();
                    db.terminals.Add(ter);
                    db.SaveChanges();
                }
            }
        }
예제 #2
0
        private void mmPaperToolStripMenuItem1_CheckedChanged(object sender, EventArgs e)
        {
            ToolStripMenuItem temp;

            // uncheck the old one
            //temp.CheckState = CheckState.Unchecked;
            temp = (ToolStripMenuItem)sender;
            // check the new one
            //temp.CheckState = CheckState.Checked;

            using (var db = new Model.posdbEntities())
            {
                if (temp.CheckState == CheckState.Checked)
                {
                    var printertype = (from p in db.terminals
                                       where p.TerminalName == AppConfig.MacAddress
                                       select p).Single();
                    if (temp.Text == "60mm Paper")
                    {
                        printertype.PrinterType = 60;
                        AppConfig.PrinterType   = "60";
                    }
                    else if (temp.Text == "80mm Paper")
                    {
                        printertype.PrinterType = 80;
                        AppConfig.PrinterType   = "80";
                    }
                    db.SaveChanges();

                    mmPaperToolStripMenuItem.CheckState = CheckState.Unchecked;
                }
            }
        }
        public int saveBusinessInformation()
        {
            string applicationPath = Path.GetDirectoryName(Application.ExecutablePath);
            string destFile        = System.IO.Path.Combine(applicationPath, "companylogo" + fileextension);

            string businessname      = "";
            string addressfield      = "";
            string citynamefield     = "";
            string statenamefield    = "";
            string countrynamefield  = "";
            string currencycodefield = "";
            string cellnumber        = "";
            string officenumber      = "";
            string emailaddress      = "";
            string businessslogan    = "";

            if (filename.Length > 0 && ispicturechanged == true)
            {
                var dir = new DirectoryInfo(applicationPath);
                foreach (var file in dir.EnumerateFiles("companylogo.*"))
                {
                    file.Delete();
                }
                File.Copy(filename, destFile, true);
                Model.AppConfig.imagefile = destFile;

                if (BusinessSloganField.Text.Length > 0)
                {
                    Model.AppConfig.businessSlogan = BusinessNameField.Text;
                }

                FileStream fs = new FileStream(Model.AppConfig.imagefile, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                pictureBox1.Image = Image.FromStream(fs);
                fs.Close();
            }

            try
            {
                if (BusinessNameField.Text.Length > 0)
                {
                    businessname = BusinessNameField.Text;
                }
                else
                {
                    MessageBox.Show("Enter business name");
                    return(0);
                }
                if (AddressField.Text.Length > 0)
                {
                    addressfield = AddressField.Text;
                }
                else
                {
                    MessageBox.Show("Enter business address");
                    return(0);
                }
                if (CityNameField.Text.Length > 0)
                {
                    citynamefield = CityNameField.Text;
                }
                if (StateNameField.Text.Length > 0)
                {
                    statenamefield = StateNameField.Text;
                }
                if (CountryNameField.Text.Length > 0)
                {
                    countrynamefield = CountryNameField.Text;
                }
                else
                {
                    MessageBox.Show("Enter Country name");
                    return(0);
                }
                if (CurrencyNameList.GetItemText(CurrencyNameList.SelectedItem).Length > 0)
                {
                    currencycodefield = CurrencyNameList.GetItemText(CurrencyNameList.SelectedItem).ToString();
                }
                else
                {
                    MessageBox.Show("Enter Currency Code");
                    return(0);
                }

                if (CellNumberField.Text.Length > 0)
                {
                    cellnumber = CellNumberField.Text;
                }

                if (OfficeNumberField.Text.Length > 0)
                {
                    officenumber = OfficeNumberField.Text;
                }

                if (EmailAddressField.Text.Length > 0)
                {
                    emailaddress = EmailAddressField.Text;
                }

                if (BusinessSloganField.Text.Length > 0)
                {
                    businessslogan = BusinessSloganField.Text;
                }

                using (var db = new Model.posdbEntities())
                {
                    var query = (from d in db.businesses
                                 select new { BusinessID = d.BusinessID }).SingleOrDefault();
                    if (query == null)
                    {
                        var d = new Model.business();
                        d.BusinessName = businessname;
                        d.Address      = addressfield;
                        //string str = convertSlashes(filename);
                        //d.BusLogoFileName = str;
                        string str = "companylogo" + Path.GetExtension(filename);
                        d.BusLogoFileName = str;
                        d.City            = citynamefield;
                        d.Country         = countrynamefield;
                        d.CurrencyCode    = currencycodefield;
                        d.State           = statenamefield;
                        //pictureBox1.Image = null;

                        System.Text.RegularExpressions.Regex regex = new Regex(@"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
                        Match match = regex.Match(emailaddress);
                        if (match.Success)
                        {
                            d.EmailAddress = emailaddress;
                            d.OfficeNumber = officenumber;
                            d.CellNumber   = cellnumber;
                            d.Slogan       = businessslogan;
                            db.businesses.Add(d);
                            db.SaveChanges();
                            MessageBox.Show("New Business has been registered.");
                            SuccessfulPictureChange();
                            return(1);
                        }
                        else
                        {
                            MessageBox.Show("Invalid Email Address.");
                        }
                    }
                    else
                    {
                        var original = db.businesses.Find(query.BusinessID);
                        if (original != null)
                        {
                            original.BusinessID   = query.BusinessID;
                            original.BusinessName = businessname;
                            original.Address      = addressfield;
                            //string str = convertSlashes(filename);
                            //original.BusLogoFileName = str;
                            string str = "companylogo" + Path.GetExtension(filename);
                            original.BusLogoFileName = str;
                            original.City            = citynamefield;
                            original.Country         = countrynamefield;
                            original.CurrencyCode    = currencycodefield;
                            original.State           = statenamefield;

                            System.Text.RegularExpressions.Regex regex = new Regex(@"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
                            Match match = regex.Match(emailaddress);
                            if (match.Success)
                            {
                                original.EmailAddress          = emailaddress;
                                original.OfficeNumber          = officenumber;
                                original.CellNumber            = cellnumber;
                                original.Slogan                = businessslogan;
                                Model.AppConfig.businessSlogan = businessslogan;
                                //pictureBox1.Image = null;
                                db.SaveChanges();
                                MessageBox.Show("Business Information has been updated.");
                                SuccessfulPictureChange();
                                return(1);
                            }
                            else
                            {
                                MessageBox.Show("Invalid Email Address.");
                            }
                        }
                    }
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException e1)
            {
                MessageBox.Show(e1.Message);
            }
            return(0);
        }