示例#1
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";
            }
        }
示例#2
0
        /*
         * This function will create a new object by different child class
         */
        public void Add()
        {
            int fid = 0;
            //new parent object
            License newLicense;

            //object of Restaurant
            String classfication = GetClassficationCode();

            if (classfication.Equals("REST"))
            {
                Restaurant rest = new Restaurant();
                rest.ClassficationCode = "REST";
                newLicense             = rest;
            }
            //object of Auto business
            else if (classfication.Equals("AUTO"))
            {
                Auto at = new Auto();
                at.ClassficationCode = "AUTO";
                newLicense           = at;
            }//object of Hotel
            else if (classfication.Equals("HOTEL"))
            {
                Hotel ht = new Hotel();
                ht.ClassficationCode = "HOTEL";
                newLicense           = ht;
            }
            //object of Other Business
            else
            {
                OtherBusiness ob = new OtherBusiness();
                ob.ClassficationCode = "OTHER";
                newLicense           = ob;
            }

            //checking fid existing or not
            while (true)
            {
                fid = GetIntegerInput("FID");
                if (CheckFID(fid))
                {
                    Console.WriteLine("This ID is already Exist!");
                }
                else
                {
                    //put valid Fid to the new object
                    newLicense = newLicense.AddNewRecord(ref newLicense, fid);
                    break;
                }
            }

            //adding the new object to list
            LicenseList.Add(newLicense);
            //print out the new object
            foreach (var t in License.ColumnTitle())
            {
                Console.Write(t + "\t");
            }

            Console.WriteLine(newLicense);
        }