private void listOfCustomersToolStripMenuItem_Click(object sender, EventArgs e) { SearchCustomer frm1 = new SearchCustomer(); //NewCostumers frm1 = new NewCostumers(); frm1.MdiParent = this; frm1.Show(); }
private void btnEnter_Click(object sender, EventArgs e) { SqlConnection connection = SearchCustomer.CreateConection(); using (connection) { SqlCommand mycommand = new SqlCommand("sp_User", connection); mycommand.CommandType = CommandType.StoredProcedure; mycommand.CommandText = "sp_User"; SqlParameter user = new SqlParameter("@Name", SqlDbType.NVarChar); if (txtUsename.Text != "") { user.Value = txtUsename.Text; } mycommand.Parameters.Add(user); SqlParameter pass = new SqlParameter("@Pass", SqlDbType.NVarChar); if (txtPass.Text != "") { pass.Value = txtPass.Text; } mycommand.Parameters.Add(pass); try { //connection.Open(); //mycommand.ExecuteNonQuery(); //MessageBox.Show("Потребителя влезна успешно!"); connection.Open(); object res = mycommand.ExecuteScalar(); if (res == null) { MessageBox.Show("Грешен потребител/парола!"); } else { MessageBox.Show("Успешен вход!"); Menu menu = new Menu(); menu.Show(); this.Hide(); } } catch (SqlException ol) { MessageBox.Show(ol.Message.ToString()); } this.Refresh(); } // this.Hide(); }
private void btnSearchP_Click(object sender, EventArgs e) { SqlConnection connection = SearchCustomer.CreateConection(); using (connection) { SqlCommand mycommand = new SqlCommand("sp_ReportQtyProduct", connection); mycommand.CommandType = CommandType.StoredProcedure; mycommand.CommandText = "sp_ReportQtyProduct"; SqlParameter Prod = new SqlParameter("@Product_name", SqlDbType.NVarChar); if (cbProd.Text != "") { Prod.Value = cbProd.Text; } mycommand.Parameters.Add(Prod); //da smenq imeto na @parametara!!! //SqlParameter Product = new SqlParameter("@C_Fname", SqlDbType.NVarChar); //if (cbProd.Text != "") //{ // Product.Value = cbProd.Text; //} //mycommand.Parameters.Add(Product); try { connection.Open(); SqlDataReader reader = mycommand.ExecuteReader(); if (reader.HasRows) { DataTable dt = new DataTable(); dt.Load(reader); dgv_ReportP.DataSource = dt; //dt.Columns["C_id"].ColumnName = "Клиент номер"; //dt.Columns["Order_id"].ColumnName = "Поръчка №"; //dt.Columns["C_Fname"].ColumnName = "Име"; //dt.Columns["C_Lname"].ColumnName = "Фамилия"; } else { MessageBox.Show("Няма намерен продукт!"); } reader.Close(); } catch (SqlException ol) { MessageBox.Show(ol.Message.ToString()); } } }
private void btnSave_Click(object sender, EventArgs e) { SqlConnection connection = SearchCustomer.CreateConection(); using (connection) { SqlCommand mycommand = new SqlCommand("sp_User", connection); mycommand.CommandType = CommandType.StoredProcedure; mycommand.CommandText = "sp_User"; SqlParameter user = new SqlParameter("@Name", SqlDbType.NVarChar); if (txtUsername.Text != "") { user.Value = txtUsername.Text; } mycommand.Parameters.Add(user); SqlParameter pass = new SqlParameter("@Pass", SqlDbType.NVarChar); if (txtPass.Text != "") { pass.Value = txtPass.Text; } mycommand.Parameters.Add(pass); try { connection.Open(); mycommand.ExecuteNonQuery(); MessageBox.Show("Потребителя беше добавен успешно!"); Customer cus = new Customer(); cus.UserName = txtUsername.Text; cus.Pass = txtPass.Text; Login menu = new Login(cus); menu.Show(); this.Hide(); } catch (SqlException ol) { MessageBox.Show(ol.Message.ToString()); } this.Refresh(); } }
private void btnDelS_Click(object sender, EventArgs e) { SqlConnection connection = SearchCustomer.CreateConection(); //КАК ДА НАПРАВЯ ДЕЛ В НЯКОЛКО ТАБЛИЦИ??????????? using (connection) { //da PROBVAM DALI RABOTI!!!!! SqlCommand mycommand = new SqlCommand("sp_del_Customer", connection); mycommand.CommandType = CommandType.StoredProcedure; mycommand.CommandText = "sp_del_Customer"; SqlParameter CustomerID = new SqlParameter("@C_id", SqlDbType.Int); if (txtCNo.Text != "") { CustomerID.Value = Convert.ToInt32(txtCNo.Text); } mycommand.Parameters.Add(CustomerID); try { connection.Open(); mycommand.ExecuteNonQuery(); MessageBox.Show("Kлиента беше изтрит успешно!"); } catch (SqlException ol) { MessageBox.Show(ol.Message.ToString()); } //TODO !!!!!!!!!! } }
private void btnDelC_Click(object sender, EventArgs e) { DialogResult msg = MessageBox.Show("Сигурни ли сте, че искате да изтриете? "); if (msg == DialogResult.Yes) { SqlConnection connection = SearchCustomer.CreateConection(); using (connection) { SqlCommand mycommand = new SqlCommand("sp_del_Customer", connection); mycommand.CommandType = CommandType.StoredProcedure; mycommand.CommandText = "sp_del_Customer"; SqlParameter CustomerID = new SqlParameter("@C_id", SqlDbType.Int); if (txtCNo.Text != "") { CustomerID.Value = Convert.ToInt32(txtCNo.Text); } mycommand.Parameters.Add(CustomerID); //TODO try { connection.Open(); mycommand.ExecuteNonQuery(); MessageBox.Show("Kлиента беше изтрит успешно!"); } catch (SqlException ol) { MessageBox.Show(ol.Message.ToString()); } } } }
private void btnNS_Click(object sender, EventArgs e) { //insert SqlConnection connection = SearchCustomer.CreateConection(); using (connection) { SqlCommand mycommand = new SqlCommand("sp_isert_Customer", connection); mycommand.CommandType = CommandType.StoredProcedure; mycommand.CommandText = "sp_isert_Customer"; SqlParameter Name = new SqlParameter("@Fname", SqlDbType.NVarChar); if (txtCName.Text != "") { Name.Value = txtCName.Text; } mycommand.Parameters.Add(Name); SqlParameter LName = new SqlParameter("@Lname", SqlDbType.NVarChar); if (txtCLName.Text != "") { LName.Value = txtCLName.Text; } mycommand.Parameters.Add(LName); SqlParameter address = new SqlParameter("@address", SqlDbType.NVarChar); if (txtCAddress.Text != "") { address.Value = txtCAddress.Text; } mycommand.Parameters.Add(address); SqlParameter City = new SqlParameter("@City", SqlDbType.NVarChar); if (txtCCity.Text != "") { City.Value = txtCCity.Text; } mycommand.Parameters.Add(City); SqlParameter Country = new SqlParameter("@Country", SqlDbType.NVarChar); if (txtCCountry.Text != "") { Country.Value = txtCCountry.Text; } mycommand.Parameters.Add(Country); try { connection.Open(); mycommand.ExecuteNonQuery(); MessageBox.Show("Продажбата беше добавена успешно!"); } catch (SqlException ol) { MessageBox.Show(ol.Message.ToString()); } } SqlConnection conn = SearchCustomer.CreateConection(); using (conn) { SqlCommand mycommand1 = new SqlCommand("sp_insertOrders", conn); mycommand1.CommandType = CommandType.StoredProcedure; mycommand1.CommandText = "sp_insertOrders"; SqlParameter CustomerID = new SqlParameter("@C_id", SqlDbType.Int); if (txtCNo.Text != "") { CustomerID.Value = Convert.ToInt32(txtCNo.Text); } mycommand1.Parameters.Add(CustomerID); SqlParameter ord = new SqlParameter("@Order_date", SqlDbType.DateTime); if (txtCName.Text != "") { ord.Value = dateTimePicker1.Value; } mycommand1.Parameters.Add(ord); SqlParameter shd = new SqlParameter("@Sheeped_date", SqlDbType.DateTime); if (txtCLName.Text != "") { shd.Value = dateTimePicker2.Value; } mycommand1.Parameters.Add(shd); try { conn.Open(); mycommand1.ExecuteNonQuery(); MessageBox.Show("Продажбата беше добавена успешно!"); } catch (SqlException ol) { MessageBox.Show(ol.Message.ToString()); } } SqlConnection con = SearchCustomer.CreateConection(); using (con) { // sp_insertOrderDetail //@Product_id int=null, //@Order_id int=null, //@Quantity int=null, //@Price money=null SqlCommand mycommand = new SqlCommand("sp_insertOrderDetail", con); mycommand.CommandType = CommandType.StoredProcedure; mycommand.CommandText = "sp_insertOrderDetail"; //!!!!!!!!!!!!! SqlParameter ProdID = new SqlParameter("@Product_id", SqlDbType.Int); //if (txtCNo.Text != "") //{ ProdID.Value = Convert.ToInt32(cbProduct.SelectedIndex); //} mycommand.Parameters.Add(ProdID); SqlParameter OrderID = new SqlParameter("@Order_id", SqlDbType.Int); if (txtOrderID.Text != "") { OrderID.Value = Convert.ToInt32(txtOrderID.Text); } mycommand.Parameters.Add(OrderID); SqlParameter Qty = new SqlParameter("@Quantity", SqlDbType.Int); if (txtQuantity.Text != "") { Qty.Value = Convert.ToInt32(txtQuantity.Text); } mycommand.Parameters.Add(Qty); SqlParameter Price = new SqlParameter("@Price", SqlDbType.Int); if (txtPrice.Text != "") { Price.Value = Convert.ToInt32(txtPrice.Text); } mycommand.Parameters.Add(Price); try { con.Open(); mycommand.ExecuteNonQuery(); MessageBox.Show("detajla беше добавена успешно!!!"); } catch (SqlException ol) { MessageBox.Show(ol.Message.ToString()); } } }
private void BtnSearchC_Click(object sender, EventArgs e) { SqlConnection connection = SearchCustomer.CreateConection(); using (connection) { SqlCommand mycommand = new SqlCommand("sp_SearchCustomer", connection); mycommand.CommandType = CommandType.StoredProcedure; mycommand.CommandText = "sp_SearchCustomer"; SqlParameter CustomerID = new SqlParameter("@C_id", SqlDbType.Int); if (txtCNo.Text != "") { CustomerID.Value = Convert.ToInt32(txtCNo.Text); } mycommand.Parameters.Add(CustomerID); SqlParameter Name = new SqlParameter("@C_Fname", SqlDbType.NVarChar); if (txtCName.Text != "") { Name.Value = txtCName.Text; } mycommand.Parameters.Add(Name); SqlParameter LName = new SqlParameter("@C_Lname", SqlDbType.NVarChar); if (txtCLName.Text != "") { LName.Value = txtCLName.Text; } mycommand.Parameters.Add(LName); try { connection.Open(); SqlDataReader reader = mycommand.ExecuteReader(); if (reader.HasRows) { DataTable dt = new DataTable(); dt.Load(reader); dgv_SearchCustomer.DataSource = dt; dt.Columns["C_id"].ColumnName = "Клиент номер"; dt.Columns["C_Fname"].ColumnName = "Име"; dt.Columns["C_Lname"].ColumnName = "Фамилия"; //dt.Columns["CLIENT_TYPE"].ColumnName = "Тип клиент"; //dt.Columns["CLIENT_EGN_BULSTAT"].ColumnName = "ЕГН/БУЛСТАТ"; //dt.Columns["CLIENT_FULLNAME"].ColumnName = "Име/Фирма"; //dt.Columns["EMAIL"].ColumnName = "Емайл"; //dt.Columns["TELEPHONE"].ColumnName = "Телефон"; //dt.Columns["ADRESS_TEXT"].ColumnName = "Адрес"; //dt.Columns["CLIENT_NOTE"].ColumnName = "Заележка"; //dt.Columns["MODIF_DATE"].ColumnName = "модифицирам на :"; } else { MessageBox.Show("Няма намерен клиент!"); } reader.Close(); } catch (SqlException ol) { MessageBox.Show(ol.Message.ToString()); } } }
private void btnUpdateS_Click(object sender, EventArgs e) { SqlConnection connection = SearchCustomer.CreateConection(); using (connection) { //да проверя дали работи!!!!!!!!!!!! SqlCommand mycommand = new SqlCommand("sp_updateCustomers", connection); mycommand.CommandType = CommandType.StoredProcedure; mycommand.CommandText = "sp_updateCustomers"; SqlParameter CustomerID = new SqlParameter("@C_id", SqlDbType.Int); if (txtCNo.Text != "") { CustomerID.Value = Convert.ToInt32(txtCNo.Text); } mycommand.Parameters.Add(CustomerID); SqlParameter Name = new SqlParameter("@FName", SqlDbType.NVarChar); if (txtCName.Text != "") { Name.Value = txtCName.Text; } mycommand.Parameters.Add(Name); SqlParameter LName = new SqlParameter("@LName", SqlDbType.NVarChar); if (txtCLName.Text != "") { LName.Value = txtCLName.Text; } mycommand.Parameters.Add(LName); SqlParameter address = new SqlParameter("@Address", SqlDbType.NVarChar); if (txtCAddress.Text != "") { address.Value = txtCAddress.Text; } mycommand.Parameters.Add(address); SqlParameter city = new SqlParameter("@City", SqlDbType.NVarChar); if (txtCCity.Text != "") { city.Value = txtCCity.Text; } mycommand.Parameters.Add(city); SqlParameter country = new SqlParameter("@Country", SqlDbType.NVarChar); if (txtCCountry.Text != "") { country.Value = txtCCountry.Text; } mycommand.Parameters.Add(country); try { connection.Open(); mycommand.ExecuteNonQuery(); MessageBox.Show("Kлиента беше променен успешно!"); } catch (SqlException ol) { MessageBox.Show(ol.Message.ToString()); } } SqlConnection conn = SearchCustomer.CreateConection(); using (connection) { //да проверя дали работи!!!!!!!!!!!! SqlCommand mycommand = new SqlCommand("sp_updateProduct", conn); mycommand.CommandType = CommandType.StoredProcedure; mycommand.CommandText = "sp_updateProduct"; //SqlParameter CustomerID = new SqlParameter("@C_id", SqlDbType.Int); //if (txtCNo.Text != "") //{ // CustomerID.Value = Convert.ToInt32(txtCNo.Text); //} //mycommand.Parameters.Add(CustomerID); //SqlParameter Name = new SqlParameter("@FName", SqlDbType.NVarChar); //if (txtCName.Text != "") //{ // Name.Value = txtCName.Text; //} //mycommand.Parameters.Add(Name); } }
private void btnSaveNC_Click(object sender, EventArgs e) { SqlConnection connection = SearchCustomer.CreateConection(); using (connection) { SqlCommand mycommand = new SqlCommand("sp_isert_Customer", connection); mycommand.CommandType = CommandType.StoredProcedure; mycommand.CommandText = "sp_isert_Customer"; // @Fname nvarchar(20)=null, //@Lname nvarchar(20)=null, //@address nvarchar(max)=null, //@City nvarchar(50)=null, //@Country nvarchar(50)=null //SqlParameter CustomerID = new SqlParameter("@C_id", SqlDbType.Int); //if (txtCNo.Text != "") //{ // CustomerID.Value = Convert.ToInt32(txtCNo.Text); //} //mycommand.Parameters.Add(CustomerID); SqlParameter Name = new SqlParameter("@Fname", SqlDbType.NVarChar); if (txtCName.Text != "") { Name.Value = txtCName.Text; } mycommand.Parameters.Add(Name); SqlParameter LName = new SqlParameter("@Lname", SqlDbType.NVarChar); if (txtCLName.Text != "") { LName.Value = txtCLName.Text; } mycommand.Parameters.Add(LName); SqlParameter address = new SqlParameter("@address", SqlDbType.NVarChar); if (txtCAddress.Text != "") { address.Value = txtCAddress.Text; } mycommand.Parameters.Add(address); SqlParameter City = new SqlParameter("@City", SqlDbType.NVarChar); if (txtCCity.Text != "") { City.Value = txtCCity.Text; } mycommand.Parameters.Add(City); SqlParameter Country = new SqlParameter("@Country", SqlDbType.NVarChar); if (txtCCountry.Text != "") { Country.Value = txtCCountry.Text; } mycommand.Parameters.Add(Country); try { connection.Open(); mycommand.ExecuteNonQuery(); MessageBox.Show("Kлиента беше добавен успешно!"); } catch (SqlException ol) { MessageBox.Show(ol.Message.ToString()); } txtCName.Clear(); txtCLName.Clear(); txtCCountry.Clear(); txtCCity.Clear(); txtCAddress.Clear(); } }