Exemple #1
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Model.business model)
 {
     return(dal.Update(model));
 }
        public void showExistingBusinessInformation()
        {
            try
            {
                using (var db = new Model.posdbEntities())
                {
                    var query = (from d in db.businesses
                                 select new
                    {
                        BusinessName = d.BusinessName,
                        BusLogoFile = d.BusLogoFileName,
                        City = d.City,
                        Country = d.Country,
                        CurrencyCode = d.CurrencyCode,
                        State = d.State,
                        Address = d.Address,
                        CellNumber = d.CellNumber,
                        EmailAddress = d.EmailAddress,
                        OfficeNumber = d.OfficeNumber,
                        Slogan = d.Slogan
                    }).SingleOrDefault();
                    if (query != null)
                    {
                        var d = new Model.business();
                        BusinessNameField.Text = query.BusinessName;

                        string str             = Application.ExecutablePath;
                        string applicationPath = Path.GetDirectoryName(Application.ExecutablePath);
                        var    dir             = new DirectoryInfo(applicationPath);
                        foreach (var file in dir.EnumerateFiles("companylogo.*"))
                        {
                            fileextension = file.Extension;
                        }
                        string destFile = System.IO.Path.Combine(applicationPath, "companylogo2" + fileextension);
                        filename = System.IO.Path.Combine(applicationPath, "companylogo" + fileextension);

                        //File.Delete(destFile);
                        //File.Copy(filename, destFile, true);


                        //File.Copy(System.IO.Path.Combine(applicationPath, "companylogo" + fileextension), System.IO.Path.Combine(applicationPath, "companylogo2" + fileextension), true);

                        FileStream fs = new FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                        pictureBox1.Image = Image.FromStream(fs);
                        fs.Close();

                        CityNameField.Text       = query.City;
                        CountryNameField.Text    = query.Country;
                        CurrencyNameList.Text    = query.CurrencyCode;
                        StateNameField.Text      = query.State;
                        AddressField.Text        = query.Address;
                        CellNumberField.Text     = query.CellNumber;
                        EmailAddressField.Text   = query.EmailAddress;
                        OfficeNumberField.Text   = query.OfficeNumber;
                        BusinessSloganField.Text = query.Slogan;
                        //pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
                    }
                }
            }
            catch (Exception e)
            {
            }
        }
Exemple #3
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public bool Add(Model.business model)
 {
     return(dal.Add(model));
 }
        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);
        }