private void clear_control() { Email.Text = string.Empty; CompanyName.Text = string.Empty; EmailSec.Text = string.Empty; Password.Text = string.Empty; UserId.Text = string.Empty; PhoneNumber.Text = string.Empty; Fax.Text = string.Empty; PAddress.Text = string.Empty; BAddress.Text = string.Empty; City.Text = string.Empty; State.Text = string.Empty; ZipCode.Text = string.Empty; TaxID.Text = string.Empty; CompanyName.Focus(); }
}//ends create user method private void clear_control() { Email.Text = string.Empty; CompanyName.Text = string.Empty; Email.Text = string.Empty; Password.Text = string.Empty; UserName.Text = string.Empty; PhoneNumber.Text = string.Empty; FaxNumber.Text = string.Empty; Address.Text = string.Empty; Address2.Text = string.Empty; City.Text = string.Empty; ddState.SelectedItem.Value = string.Empty; Zipcode.Text = string.Empty; TaxID.Text = string.Empty; RegCode.Text = string.Empty; CompanyName.Focus(); }
private void Nip_KeyDown(object sender, KeyEventArgs e) { if (e.Key != Key.Enter) { return; } if (Nip.Text.Length != 10) { MessageBox.Show("NIP must be 10 characters long !", "Error 2"); } else if (!int.TryParse(Nip.Text, out _)) { MessageBox.Show("Nip must contain only numbers !", "Error 3"); } else { PreviewChange(); CompanyName.Focus(); } }
protected void Button1_Click(object sender, EventArgs e) { //delete data from the current table before new search DataGrid1.DataSource = null; DataGrid1.DataBind(); string valueToSearch = CompanyName.Text; using (SqlConnection con = new SqlConnection(CONNECTION_STRING)) { string sqlQuery = ""; if (String.IsNullOrEmpty(CompanyName.Text)) { sqlQuery = "select C.CustomerID, C.CompanyName, Count(O.OrderID) " + "from Customers C INNER JOIN Orders O on C.CustomerID = O.CustomerID " + "group by C.CustomerID, C.CompanyName"; } else { string howToSearch = SearchType.SelectedValue; switch (howToSearch) { case "Equal": sqlQuery = "select C.CustomerID, C.CompanyName, Count(O.OrderID) " + "from Customers C INNER JOIN Orders O on C.CustomerID = O.CustomerID " + "where C.CompanyName = @valueToSearch " + "group by C.CustomerID, C.CompanyName"; break; case "StartWith": sqlQuery = "select C.CustomerID, C.CompanyName, Count(O.OrderID) " + "from Customers C INNER JOIN Orders O on C.CustomerID = O.CustomerID " + "where C.CompanyName like @valueToSearch + '%' " + "group by C.CustomerID, C.CompanyName"; break; case "EndWith": sqlQuery = "select C.CustomerID, C.CompanyName, Count(O.OrderID) " + "from Customers C INNER JOIN Orders O on C.CustomerID = O.CustomerID " + "where C.CompanyName like '%' + @valueToSearch " + "group by C.CustomerID, C.CompanyName"; break; case "Middle": sqlQuery = "select C.CustomerID, C.CompanyName, Count(O.OrderID) " + "from Customers C INNER JOIN Orders O on C.CustomerID = O.CustomerID " + "where C.CompanyName like '%' + @valueToSearch + '%' " + "group by C.CustomerID, C.CompanyName"; break; default: Label1.Text = "You didnt pick how to search"; return; } } // Command ctor with the sql query and connection object SqlCommand cmd = new SqlCommand(sqlQuery, con); //adding parameter into command collection a way against SQL Injection cmd.Parameters.AddWithValue("@valueToSearch", valueToSearch); // bridge between a DataSet and SQL Server by mapping Fill, which changes the data inthe DataSet to match in the Data Source. SqlDataAdapter sde = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); sde.Fill(ds); DataGrid1.DataSource = ds; DataGrid1.DataBind(); // return the focus to the input text for fast new search CompanyName.Focus(); } }
private void MetroWindow_Loaded(object sender, System.Windows.RoutedEventArgs e) { CompanyName.Focus(); }