예제 #1
0
        private void CityCombobox_DropDownClosed(object sender, EventArgs e)
        {
            string ctyslct = CityCombobox.GetItemText(CityCombobox.SelectedItem);

            using (MySqlConnection cmn = new MySqlConnection(Globals.connStr))
            {
                cmn.Open();
                MySqlCommand     mmmd = new MySqlCommand("SELECT cityId from city where city = '" + ctyslct + "';", cmn);
                MySqlDataAdapter mapt = new MySqlDataAdapter(mmmd);
                DataTable        mdm  = new DataTable();
                mapt.Fill(mdm);

                if (mdm.Rows.Count > 0)
                {
                    int idc = (int)mdm.Rows[0][0];
                    Globals.CtyID = idc;
                }
                cmn.Close();
            }
        }
예제 #2
0
        private void ACAddButton_Click(object sender, EventArgs e)
        {//SAVE NEW CUSTOMER
            if (String.IsNullOrEmpty(ACNameTextbox.Text))
            {
                MessageBox.Show("Please enter a name.");
                return;
            }
            if (String.IsNullOrEmpty(ACAddressTextbox.Text))
            {
                MessageBox.Show("Please enter an address.");
                return;
            }
            if (String.IsNullOrEmpty(ACZipTextbox.Text))
            {
                MessageBox.Show("Please enter a zip code.");
                return;
            }
            if (String.IsNullOrEmpty(ACPhoneTextBox.Text))
            {
                MessageBox.Show("Please enter a phone number.");
                return;
            }

            try
            {
                //Get City ID
                string ctd = CityCombobox.GetItemText(CityCombobox.SelectedItem);

                using (MySqlConnection comn = new MySqlConnection(Globals.connStr))
                {
                    comn.Open();
                    MySqlCommand     mmd = new MySqlCommand("SELECT cityId from city where city = '" + ctd + "';", comn);
                    MySqlDataAdapter apt = new MySqlDataAdapter(mmd);
                    DataTable        md  = new DataTable();
                    apt.Fill(md);

                    if (md.Rows.Count > 0)
                    {
                        int idc = (int)md.Rows[0][0];
                        Globals.CtyID = idc;
                    }
                    comn.Close();
                }

                //insert ADDRESS/CITY/COUNTRY
                string Query = "Insert into address(address,cityId,postalCode,phone,createDate,createdBy) " +
                               "Values('" + ACAddressTextbox.Text + "','" + Globals.CtyID + "','" + ACZipTextbox.Text + "','" + ACPhoneTextBox.Text + "','" + TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-dd HH:mm:ss") + "','" + Globals.CurrUserName + "');";
                MySqlConnection con2 = new MySqlConnection(Globals.connStr);
                MySqlCommand    comm = new MySqlCommand(Query, con2);
                MySqlDataReader rdr;
                con2.Open();
                rdr = comm.ExecuteReader();
                con2.Close();

                //get ADDRESS ID
                MySqlConnection  cmn  = new MySqlConnection(Globals.connStr);
                MySqlCommand     mmmd = new MySqlCommand("SELECT addressId from address where phone = '" + ACPhoneTextBox.Text + "';", cmn);
                MySqlDataAdapter mapt = new MySqlDataAdapter(mmmd);
                cmn.Open();
                DataTable mdm = new DataTable();
                mapt.Fill(mdm);

                if (mdm.Rows.Count > 0)
                {
                    int idc = (int)mdm.Rows[0][0];
                    Globals.AddID = idc;
                }
                cmn.Close();


                //insert into CUSTOMER
                string Queryx = "Insert into customer(customerName,addressId,active,createDate,createdBy)" +
                                "Values('" + ACNameTextbox.Text + "','" + Globals.AddID + "','1','" + TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-dd HH:mm:ss") + "','" + Globals.CurrUserName + "');";
                MySqlConnection con2x = new MySqlConnection(Globals.connStr);
                MySqlCommand    commx = new MySqlCommand(Queryx, con2x);
                MySqlDataReader rdrx;
                con2x.Open();
                rdrx = commx.ExecuteReader();
                MessageBox.Show("Data Saved");
                while (rdrx.Read())
                {
                }
                con2x.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Customer could not be added.", "Error");
            }


            this.Hide();
            Dashboard db = new Dashboard();

            db.ShowDialog();
        }
예제 #3
0
        protected void StateCombobox_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                String State   = StateCombobox.Text;
                String Country = CountryCombobox.Text;

                System.Net.WebClient web = new System.Net.WebClient();
                web.QueryString.Add("Country", Country);
                web.QueryString.Add("State", State);
                string response = web.DownloadString("http://jnitinc.com/WebService/GetCity.php?Country=" + Country + "&State=" + State + "");

                //List<City> ls = deserializeJson<List<LocationValues>>(response);
                List <CityNames> lst = new List <CityNames>();

                DataContractJsonSerializer jsonSer = new DataContractJsonSerializer(lst.GetType());
                System.IO.MemoryStream     ms      = new System.IO.MemoryStream(System.Text.Encoding.Unicode.GetBytes(response));
                lst = (List <CityNames>)jsonSer.ReadObject(ms);

                DataTable dt = new DataTable();
                dt.Columns.Add("City");

                foreach (CityNames city in lst)
                {
                    DataRow row = dt.NewRow();
                    row["City"] = city.City;
                    dt.Rows.Add(row);
                }


                CityCombobox.DataSource = dt;
                CityCombobox.TextField  = "City";
                CityCombobox.ValueField = "City";
                CityCombobox.DataBind();
                CityCombobox.Focus();
            }
            catch (Exception ex)
            {
                Log.Entry.Ins.WriteHistoryEntry(DateTime.Now.ToString() + " Exception - " + ex);
                throw ex;
            }
            finally { }



/*
 *
 *                      try
 *                      {
 *
 *                              DataTable dt = new DataTable();
 *                              dt = VSWebBL.SecurityBL.LocationsBL.Ins.GetCitiesFromStateAndCountry(StateCombobox.Text, CountryCombobox.Text);
 *
 *                      }
 *                      catch (Exception ex)
 *                      {
 *                              Log.Entry.Ins.WriteHistoryEntry(DateTime.Now.ToString() + " Exception - " + ex);
 *                              throw ex;
 *                      }
 *                      finally { }
 */
        }