private void buttonSave_Click(object sender, EventArgs e) { if (textBoxPatch.Text != null) { try { using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("sp_tblOption_update_defaultAttachFolder", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@id", 1); cmd.Parameters.AddWithValue("@patch", DefaultFolder); con.Open(); cmd.ExecuteNonQuery(); } } label1.Text = DefaultFolder; MessageBox.Show("عملیات مورد نظر با موفقیت انجام شد", "", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void btnAdd_Click(object sender, EventArgs e) { if (IsValid()) { if (IsUpdate) { using (SqlConnection sqlCon = new SqlConnection(ApplicationSetting.ConnectionString())) { SqlCommand sqlCmd = sqlCon.CreateCommand(); sqlCmd.CommandType = CommandType.Text; sqlCmd.CommandText = $"UPDATE [dbo].[Category] SET CategoryName ='{txtCategory.Text}' WHERE CategoryId ={this.CategoryId}"; sqlCon.Open(); sqlCmd.ExecuteNonQuery(); MessageBox.Show($"Category Updated Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { using (SqlConnection sqlCon = new SqlConnection(ApplicationSetting.ConnectionString())) { SqlCommand sqlCmd = sqlCon.CreateCommand(); sqlCmd.CommandType = CommandType.Text; sqlCmd.CommandText = $"INSERT INTO [dbo].[Category] ([CategoryName]) VALUES('{txtCategory.Text}')"; sqlCon.Open(); sqlCmd.ExecuteNonQuery(); MessageBox.Show($"Category Add Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } clearForNewCategory(); LoadAllCategoryIntoGrid(); } }
private void btnlogin_Click(object sender, EventArgs e) { if (isvalid()) { using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("sp_loginverify", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@username", txtusername.Text.Trim()); cmd.Parameters.AddWithValue("@password", txtpassword.Text.Trim()); con.Open(); SqlDataReader sdr = cmd.ExecuteReader(); if (sdr.Read()) { this.Hide(); Dashboard db = new Dashboard(); db.Show(); } else { MessageBox.Show("Username or Password is not Valid", "Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
private void Loginbtn_Click(object sender, EventArgs e) { if (IsValid()) { //string constring = ApplicationSetting.ConnectionString(); //MessageBox.Show(constring); using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("usp_Login_VerifyLoginDetails", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserName", UserNametxtBox.Text.Trim()); cmd.Parameters.AddWithValue("@Password", PasswordtxtBox.Text.Trim()); con.Open(); SqlDataReader srd = cmd.ExecuteReader(); if (srd.Read()) { //MessageBox.Show("Welcome"); this.Hide(); DashBoardForm df = new DashBoardForm(); df.Show(); } else { MessageBox.Show("User Name or Password is incorrect", "Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
private void LoadStockReport() { try { using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { SqlCommand cmd = con.CreateCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "usp_Load_Stock"; SqlDataAdapter sda = new SqlDataAdapter(cmd); System.Data.DataSet ds = new System.Data.DataSet(); sda.Fill(ds, "usp_Load_Stock"); ReportDocument rd = new ReportDocument(); string reportPath = Application.StartupPath + @"\Screens\Reports\StockReport.rpt"; rd.Load(reportPath); rd.SetDataSource(ds); StockReportForm rv = new StockReportForm(); rv.StockReportViewer.ReportSource = rd; rv.Show(this); } } catch (Exception) { throw; } }
private void btnSave_Click(object sender, EventArgs e) { if (IsValid()) { if (IsUpdate) { using (SqlConnection sqlCon = new SqlConnection(ApplicationSetting.ConnectionString())) { SqlCommand sqlCmd = sqlCon.CreateCommand(); sqlCmd.CommandType = CommandType.Text; sqlCmd.CommandText = $"UPDATE [dbo].[Customers] SET Name ='{txtCustomerName.Text}',Mobile ={txtMobileNo.Text},Address ='{txtAddress.Text}' WHERE CustomerId ={this.CustomerId} "; sqlCon.Open(); sqlCmd.ExecuteNonQuery(); MessageBox.Show($"Customer Updated Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { using (SqlConnection sqlCon = new SqlConnection(ApplicationSetting.ConnectionString())) { SqlCommand sqlCmd = sqlCon.CreateCommand(); sqlCmd.CommandType = CommandType.Text; sqlCmd.CommandText = $"INSERT INTO [dbo].[Customers] ([Name],[Mobile],[Address]) VALUES('{txtCustomerName.Text}',{txtMobileNo.Text},'{txtAddress.Text}')"; sqlCon.Open(); sqlCmd.ExecuteNonQuery(); MessageBox.Show($"Customer Add Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } clearForNewCustomer(); } }
private void buttonSave_Click(object sender, EventArgs e) { if (File_name != null) { try { if (!System.IO.Directory.Exists(DefaultFolder + @"\" + Shomare_Name)) { System.IO.Directory.CreateDirectory(DefaultFolder + @"\" + Shomare_Name); } File_name = LetterID + "_" + File_name; System.IO.File.Copy(openFileDialog1.FileName, DefaultFolder + @"\" + Shomare_Name + @"\" + File_name, false); using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("sp_tblAttachment_insert", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Letter_ID", LetterID); cmd.Parameters.AddWithValue("@Attachment", File_name); con.Open(); cmd.ExecuteNonQuery(); } } MessageBox.Show("عملیات مورد نظر با موفقیت انجام شد", "", MessageBoxButtons.OK, MessageBoxIcon.Information); dataGridView1.DataSource = LoadAllData(); File_name = null; } catch (Exception ex) { MessageBox.Show(ex.Message, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void حذفنامهToolStripMenuItem_Click_1(object sender, EventArgs e) { if (dataGridView1.Rows.Count > 0) { DialogResult a = new DialogResult(); a = MessageBox.Show("هستید ؟" + " " + dataGridView1.SelectedRows[0].Cells["شماره نامه"].Value.ToString() + " " + "آیا مایل به حذف نامه", "حذف نامه", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (a == DialogResult.Yes) { try { using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("delete from tblBayegani where id=" + dataGridView1.SelectedRows[0].Cells["id"].Value.ToString(), con)) { con.Open(); cmd.ExecuteNonQuery(); } } MessageBox.Show("عملیات مورد نظر با موفقیت انجام شد", "", MessageBoxButtons.OK, MessageBoxIcon.Information); dataGridView1.DataSource = GetAllData(); } catch (Exception ex) { MessageBox.Show(ex.Message, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void buttonDelete_Click(object sender, EventArgs e) { if (Id_Vahed > 0) { try { using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("delete from tblVahed where id=" + Convert.ToString(Id_Vahed), con)) { con.Open(); cmd.ExecuteNonQuery(); } } MessageBox.Show("عملیات مورد نظر با موفقیت انجام شد", "", MessageBoxButtons.OK, MessageBoxIcon.Information); Id_Vahed = 0; name_Vahed = null; loadlistbox(); } catch (Exception ex) { MessageBox.Show(ex.Message, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void timer1_Tick(object sender, EventArgs e) { try { using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { con.Open(); if (con.State == ConnectionState.Open) { btnstatus.BackColor = Color.Green; UserNamecomboBox.Enabled = true; PasswodTextBox.Enabled = true; LoginButton.Enabled = true; label4.Text = "ارتباط برقرار است"; label4.ForeColor = Color.Green; timer1.Enabled = false; UserNamecomboBox.DataSource = Load_UserNames(); UserNamecomboBox.DisplayMember = "Username"; UserNamecomboBox.ValueMember = "Username"; } } } catch { btnstatus.BackColor = Color.Red; UserNamecomboBox.Enabled = false; PasswodTextBox.Enabled = false; LoginButton.Enabled = false; label4.Text = "ارتباط برقرار نیست"; label4.ForeColor = Color.Red; } }
private void buttonNew_Click(object sender, EventArgs e) { if (textBoxName.Text != "") { try { name_Vahed = textBoxName.Text; using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("sp_tblVahed_Insert", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@name_vahed", name_Vahed); con.Open(); cmd.ExecuteNonQuery(); } } MessageBox.Show("عملیات مورد نظر با موفقیت انجام شد", "", MessageBoxButtons.OK, MessageBoxIcon.Information); Id_Vahed = 0; name_Vahed = null; textBoxName.Text = ""; loadlistbox(); } catch (Exception ex) { MessageBox.Show(ex.Message, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void btnLogin_Click(object sender, EventArgs e) { if (IsValid()) { //string conString = ApplicationSetting.ConnectionString(); //MessageBox.Show(conString); using (SqlConnection sqlCon = new SqlConnection(ApplicationSetting.ConnectionString())) { SqlCommand sqlCmd = sqlCon.CreateCommand(); sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.CommandText = "usp_Login_VerifyLoginDetails"; sqlCmd.Parameters.Add(new SqlParameter("@userName", txtUserName.Text)); sqlCmd.Parameters.Add(new SqlParameter("@password", txtPassword.Text)); sqlCon.Open(); SqlDataReader reader = sqlCmd.ExecuteReader(); if (reader.Read()) { this.Hide(); DeshBoardform df = new DeshBoardform(); df.Show(); } else { MessageBox.Show("Incorect Password Or User Name!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void buttonSave_Click(object sender, EventArgs e) { if (ISvalid()) { try { using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("sp_Users_Update", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserName", textBoxUserName.Text.Trim()); cmd.Parameters.AddWithValue("@Password", textBoxPassword.Text.Trim()); con.Open(); cmd.ExecuteNonQuery(); } } MessageBox.Show("عملیات مورد نظر با موفقیت انجام شد", "", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadAllData(); } catch (Exception ex) { MessageBox.Show(ex.Message, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void buttonNew_Click(object sender, EventArgs e) { if (ISvalid()) { try { using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("sp_Users_Insert", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserName", textBoxUserName.Text.Trim()); cmd.Parameters.AddWithValue("@Password", textBoxPassword.Text.Trim()); con.Open(); cmd.ExecuteNonQuery(); } } MessageBox.Show("عملیات مورد نظر با موفقیت انجام شد", "", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadAllData(); } catch (SqlException ex) { switch (ex.Number) { case 2627: MessageBox.Show("نام کاربری نمیتواند تکراری باشد", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error); break; default: MessageBox.Show(ex.Message, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } } } }
private void SaveButton_Click(object sender, EventArgs e) { if (IsValid()) { SizesCart.Clear(); LoadDataIntoSizesCart(); using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("usp_Products_InsertNewProduct", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Name", ProductNameTextBox.Text); cmd.Parameters.AddWithValue("@CategoryID", CategoryComboBox.SelectedValue); cmd.Parameters.AddWithValue("@SupplierID", SupplierComboBox.SelectedValue); cmd.Parameters.AddWithValue("@PurchasePrice", PurchasePriceTextBox.Text); cmd.Parameters.AddWithValue("@SalesPrice", SalesPriceTextBox.Text); con.Open(); int id = Convert.ToInt32(cmd.ExecuteScalar()); SaveSizes(id); MessageBox.Show("Product no." + id.ToString() + " is Saved Succcessfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
private void LoginButton_Click(object sender, EventArgs e) { if (isValid()) { using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("sp_Users_VerifyLoginDetails", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserName", UserNamecomboBox.SelectedValue); cmd.Parameters.AddWithValue("@Password", PasswodTextBox.Text.Trim()); con.Open(); SqlDataReader sdr = cmd.ExecuteReader(); if (sdr.Read()) { this.Hide(); Main frm = new Main(); LoginInfo.UserID = UserNamecomboBox.SelectedValue.ToString(); frm.Show(); } else { MessageBox.Show("نام کاربری یا کلمه عبور اشتباه است", "ورود ناموفق", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
private void gridProductRecords_CellClick(object sender, DataGridViewCellEventArgs e) { if (gridProductRecords.CurrentCell.ColumnIndex == 7) { int _id = (int)gridProductRecords.SelectedRows[0].Cells[0].Value; if (_id > 0) { using (SqlConnection sqlCon = new SqlConnection(ApplicationSetting.ConnectionString())) { SqlCommand sqlCmd = sqlCon.CreateCommand(); sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.CommandText = "usp_Products_DeleteProductAndSizes"; sqlCmd.Parameters.Add(new SqlParameter("@ProductID", _id)); sqlCon.Open(); sqlCmd.ExecuteNonQuery(); MessageBox.Show($"Proudect Deleted Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadAllProductIntoDataGridView(); } } } }
private void UpdateDataIntoStocktable() { using (SqlConnection sqlCon = new SqlConnection(ApplicationSetting.ConnectionString())) { SqlCommand sqlCmd = sqlCon.CreateCommand(); sqlCmd.CommandType = CommandType.Text; sqlCmd.CommandText = $"UPDATE [dbo].[Stock] SET [Quantity] =[Quantity] +{txtQuantity.Text} WHERE [ProductId] ={txtProductId.Text}"; sqlCon.Open(); sqlCmd.ExecuteNonQuery(); MessageBox.Show($"Category Updated Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private DataTable Load_UserNames() { DataTable dtrecord = new DataTable(); using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("Select Username from Users", con)) { con.Open(); SqlDataReader dtr = cmd.ExecuteReader(); dtrecord.Load(dtr); } } return(dtrecord); }
private DataTable GetAllData() { DataTable dtrecord = new DataTable(); using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("Select * from tblVahed", con)) { con.Open(); SqlDataReader dtr = cmd.ExecuteReader(); dtrecord.Load(dtr); } } return(dtrecord); }
private DataTable GetComboBoxData(string v) { DataTable dtrecord = new DataTable(); using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("select * from " + v, con)) { con.Open(); SqlDataReader sdr = cmd.ExecuteReader(); dtrecord.Load(sdr); } } return(dtrecord); }
private void SaveDataIntoStocktable() { if (IsValid()) { using (SqlConnection sqlCon = new SqlConnection(ApplicationSetting.ConnectionString())) { SqlCommand sqlCmd = sqlCon.CreateCommand(); sqlCmd.CommandType = CommandType.Text; sqlCmd.CommandText = $"INSERT INTO [dbo].[Stock] ([ProductId],[SizeId],[PurchasePrice],[SalePrice],[Quantity]) VALUES ({txtProductId.Text},{txtSizeId.Text},{txtPurchasePrice.Text},{txtSallPrice.Text},{txtQuantity.Text})"; sqlCon.Open(); sqlCmd.ExecuteNonQuery(); MessageBox.Show($"Stock Entry Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private object LoadAllData() { DataTable dtrecord = new DataTable(); using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("select Attachment from tblAttachment where Letter_ID=" + Convert.ToString(LetterID), con)) { con.Open(); SqlDataReader dtr = cmd.ExecuteReader(); dtrecord.Load(dtr); } } return(dtrecord); }
private DataTable GetData() { DataTable dtrecord = new DataTable(); using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("usp_Products_LoadAllProductsForDataGridView", con)) { cmd.CommandType = CommandType.StoredProcedure; con.Open(); SqlDataReader sdr = cmd.ExecuteReader(); dtrecord.Load(sdr); } } return(dtrecord); }
private DataTable GetData() { DataTable dtsizes = new DataTable(); using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("SelectAllIO", con)) { cmd.CommandType = CommandType.StoredProcedure; con.Open(); SqlDataReader sdr = cmd.ExecuteReader(); dtsizes.Load(sdr); } } return(dtsizes); }
private void GetDefaultFolder() { using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("select DefaultAttachFolder from tblOption", con)) { con.Open(); SqlDataReader dtr = cmd.ExecuteReader(); while (dtr.Read()) { DefaultFolder = dtr["DefaultAttachFolder"].ToString(); } } } label3.Text = DefaultFolder; }
private object GetProductByProductID() { DataTable dtrecord = new DataTable(); using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("usp_Product_LoadAllProductsByProductNames", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Name", ProductNameTextBox.Text.Trim()); con.Open(); SqlDataReader sdr = cmd.ExecuteReader(); dtrecord.Load(sdr); } } return(dtrecord); }
private object GetData() { DataTable User = new DataTable(); using (SqlConnection sqlCon = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand sqlCmd = sqlCon.CreateCommand()) { sqlCmd.CommandType = CommandType.Text; sqlCmd.CommandText = $"Select * from [dbo].[LoginUser]"; sqlCon.Open(); SqlDataReader reader = sqlCmd.ExecuteReader(); User.Load(reader); } } return(User); }
private DataTable GetDataByName() { DataTable UserData = new DataTable(); using (SqlConnection sqlCon = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand sqlCmd = sqlCon.CreateCommand()) { sqlCmd.CommandType = CommandType.Text; sqlCmd.CommandText = $"Select* from [POS].[dbo].[LoginUser] where [UserName] LIKE +'%'+'{txtSearch.Text}'+'%'"; sqlCon.Open(); SqlDataReader reader = sqlCmd.ExecuteReader(); UserData.Load(reader); } } return(UserData); }
private DataTable GetSizesData() { DataTable dtsizes = new DataTable(); using (SqlConnection con = new SqlConnection(ApplicationSetting.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("usp_Sizes_LoadAllSizes", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ListTypeID", 1); con.Open(); SqlDataReader sdr = cmd.ExecuteReader(); dtsizes.Load(sdr); } } return(dtsizes); }