示例#1
0
        //This function will update user modified data
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(txtFID.Text))
            {
                lblMessage.Text = "";
                using (LicenseEntities le = new LicenseEntities())
                {
                    try
                    {
                        int fid            = Convert.ToInt32(txtFID.Text);
                        var updataeLicense = le.LicenseDBs.FirstOrDefault(n => n.FID == fid);
                        if (updataeLicense != null)
                        {
                            updataeLicense.Business_Name         = txtBusiness_Name.Text;
                            updataeLicense.Business_Phone_Number = txtBusiness_Phone_Number.Text;
                            updataeLicense.City           = txtCity.Text;
                            updataeLicense.State          = txtState.Text;
                            updataeLicense.Zip            = txtZip.Text;
                            updataeLicense.License_Status = txtLicense_Status.Text;

                            updataeLicense.Classification_Code        = txtClassficationCode.Text;
                            updataeLicense.Classification_Description = txtClassficationDes.Text;

                            le.Entry(updataeLicense).State = System.Data.EntityState.Modified;
                            le.SaveChanges();
                            lblMessage.Text = "Update Success!";
                        }
                    }
                    catch (Exception)
                    {
                        lblMessage.Text = "Update failed!";
                    }
                }
            }
        }
示例#2
0
        /**
         * This function will remvoe all the content of database
         *
         */

        protected void btnRemove_Click(object sender, EventArgs e)
        {
            using (LicenseEntities le = new LicenseEntities())
            {
                //remove records one by one
                foreach (var entity in le.LicenseDBs)
                {
                    le.LicenseDBs.Remove(entity);
                }
                le.SaveChanges();
            }
            //show information to user
            lblMessage.Text = "All the data has been removed from database!";
        }
示例#3
0
        /*
         * The Submit function will pull the data from webpage, put into a LicenseDB object
         * Then store it inot the database
         */
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                //check the fid field is exist or not, empty throw a excetion to stop
                //the process
                if (CheckFID(Convert.ToInt32(txtFID.Text)))
                {
                    throw new Exception();
                }
                lblSuccess.Text = "";
                //create a entity framework object
                using (LicenseEntities le = new LicenseEntities())
                {
                    LicenseDB lDB = new LicenseDB();
                    lDB.Business_Name         = txtBusiness_Name.Text;
                    lDB.Business_Phone_Number = txtBusiness_Phone_Number.Text;
                    lDB.City                       = txtCity.Text;
                    lDB.State                      = txtState.Text;
                    lDB.Zip                        = txtZip.Text;
                    lDB.License_Status             = txtLicense_Status.Text;
                    lDB.FID                        = Convert.ToInt32(txtFID.Text);
                    lDB.Classification_Code        = txtClassficationCode.Text;
                    lDB.Classification_Description = txtClassficationDes.Text;

                    //add new record to entity framework
                    le.LicenseDBs.Add(lDB);
                    le.SaveChanges();
                    lblSuccess.Text = "Adding Success!!";
                }
            }
            catch (Exception)
            {
                lblSuccess.Text = "FID is already Existed!!";
            }
        }
示例#4
0
        /**
         * This function will take the path of user select csv file,
         * then create a license list to store csv file information
         * then store the license into entity framework
         */
        protected void btnSubmit_Click(object sender, EventArgs e)

        {
            string path = "";

            lblMessage.Text = "";
            try
            {
                //check user selection of textbox empty or not
                if (!String.IsNullOrWhiteSpace(fuCSV.FileName))
                {
                    path = fuCSV.FileName;
                    //get the full path of user select file
                    path = Convert.ToString(fuCSV.PostedFile.FileName);
                    //print out the full path of file
                    lblMessage.Text = path;
                    //read the file from
                    LicenseCollection lc = new LicenseCollection(path);
                    //create entity frame work
                    LicenseEntities en = new LicenseEntities();

                    //store licene once a time to the entiry framework
                    foreach (var l in lc)
                    {   //check fid existence
                        if (Existed(l.Fid))
                        {
                            continue;
                        }
                        LicenseDB lDB = new LicenseDB();
                        lDB.Business_Name         = l.Business_Name;
                        lDB.Street_Address        = l.Street_Address;
                        lDB.Business_Phone_Number = l.Business_Phone_Number;
                        lDB.City                = l.City;
                        lDB.State               = l.State;
                        lDB.Zip                 = l.Zip;
                        lDB.License_Status      = l.License_Status;
                        lDB.FID                 = l.Fid;
                        lDB.Classification_Code = l.ClassficationCode;
                        //this part is from the phase 4 , revese back to orginal
                        if (l.GetType() == typeof(Hotel))
                        {
                            lDB.Classification_Description = ((Hotel)l).ClassficationDis;
                        }
                        else if (l.GetType() == typeof(Auto))
                        {
                            lDB.Classification_Description = ((Auto)l).ClassficationDis;
                        }
                        else if (l.GetType() == typeof(Restaurant))
                        {
                            lDB.Classification_Description = ((Restaurant)l).ClassficationDis;
                        }
                        else if (l.GetType() == typeof(OtherBusiness))
                        {
                            OtherBusiness newOther = (OtherBusiness)l;
                            lDB.Classification_Description = newOther.ClassficationDis;
                        }
                        //lDB.Classification_Description = l.ClassficationDis;
                        //save data to database
                        en.LicenseDBs.Add(lDB);
                        en.SaveChanges();
                    }
                }
                //show the final information to user
                lblMessage.Text = "Your data has been update Database!";
            }catch (Exception)
            {
                lblMessage.Text = "The CSV file format is not right";
            }
        }