Exemplo n.º 1
0
        private void addAddress_Click(object sender, System.EventArgs e)
        {
            if (this.address.Text.Trim().Length == 0)
            {
                MessageBox.Show("You must fill in the address.");
                this.address.Focus();
                return;
            }

            if (this.address2.Text.Trim().Length == 0)
            {
                MessageBox.Show("You must fill in the address 2.");
                this.address2.Focus();
                return;
            }

            if (this.city.Text.Trim().Length == 0)
            {
                MessageBox.Show("You must fill in the city.");
                this.city.Focus();
                return;
            }

            if (this.zipCode.Text.Trim().Length == 0)
            {
                MessageBox.Show("You must fill in the ZipCode.");
                this.zipCode.Focus();
                return;
            }

            //	Create new address generic
            ClarifyGeneric addressGen = dataSet.CreateGeneric("address");

            //	Add a new row to the address generic
            GenericDataRow addressRow = addressGen.AddNew();

            //	Set the values of the fields of the generic row
            addressRow["address"]      = address.Text.Trim();
            addressRow["address_2"]    = address2.Text.Trim();
            addressRow["city"]         = city.Text.Trim();
            addressRow["state"]        = state.SelectedItem.ToString().Trim();
            addressRow["city"]         = city.Text.Trim();
            addressRow["zipcode"]      = zipCode.Text.Trim();
            addressRow["update_stamp"] = session.GetCurrentDate();

            //	Relate this new row to existing records by relation and objid
            addressRow.RelateByID(FCApp.LocaleCache.GetCountryObjID(country.SelectedItem.ToString()), "address2country");
            addressRow.RelateByID(FCApp.LocaleCache.GetStateObjID(country.SelectedItem.ToString(), state.SelectedItem.ToString()), "address2state_prov");
            addressRow.RelateByID(FCApp.LocaleCache.GetTimeZoneObjID(timeZone.SelectedItem.ToString()), "address2time_zone");

            //	Commit the new row to the database
            addressRow.Update();

            MessageBox.Show("Address successfully added.");
        }
Exemplo n.º 2
0
        private static void InsertRecords(XmlDocument doc, ClarifyGeneric generic)
        {
            IClarifyApplication FCApp = ClarifyApplication.Instance;

            bool isValid = true;
            int  i       = 0;

            //	Loop for each address record in the xml file
            foreach (XmlNode address in doc.SelectNodes("//addresses/address"))
            {
                i++;

                //	Get values of attributes
                string address1 = GetAttributeValue(address, "address1", i);
                string address2 = GetAttributeValue(address, "address2", i);
                string city     = GetAttributeValue(address, "city", i);
                string state    = GetAttributeValue(address, "state", i);
                string zip      = GetAttributeValue(address, "zip", i);
                string country  = GetAttributeValue(address, "country", i);
                string timezone = GetAttributeValue(address, "timezone", i);

                //	Check to see if the country, timezone, and state are valid
                isValid = isValid & IsValid(country, timezone, state, i);

                //	Only add new rows if all previous rows are valid
                if (isValid)
                {
                    //	Add a new address row to the address generic
                    GenericDataRow row = generic.AddNew();

                    //	Set the field values of the new address row
                    row["address"]      = address1;
                    row["address_2"]    = address2;
                    row["city"]         = city;
                    row["state"]        = state;
                    row["zipcode"]      = zip;
                    row["update_stamp"] = DateTime.Now;

                    //	Relate this new row to existing records by relation and objid
                    row.RelateByID(FCApp.LocaleCache.GetCountryObjID(country), "address2country");
                    row.RelateByID(FCApp.LocaleCache.GetStateObjID(country, state), "address2state_prov");
                    row.RelateByID(FCApp.LocaleCache.GetTimeZoneObjID(timezone), "address2time_zone");
                }
            }

            try
            {
                //	If all the records are valid then commit new rows to the database
                if (isValid)
                {
                    //	Commit all the new rows to the database
                    generic.UpdateAll();
                    Console.WriteLine("Finished. Added {0} address records.", i);
                }
                else
                {
                    Console.WriteLine("No records were added due to invalid data.");
                }
            }
            catch (Exception ex)
            {
                // Error inserting rows
                Console.WriteLine("Error adding new addresses.\n{0}", ex.Message);
            }
        }