Esempio n. 1
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!!";
            }
        }
Esempio n. 2
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";
            }
        }