private void frmInvoice_FormClosing(object sender, FormClosingEventArgs e) { this.Hide(); frmMainMenu frm = new frmMainMenu(); frm.lblUser.Text = label6.Text; frm.Show(); }
private void btnUpdate_Click(object sender, EventArgs e) { try { con = new OleDbConnection(cs); con.Open(); string cb = "Update Stock set ConfigID=" + txtConfigID.Text + ",Quantity=" + txtQty.Text + ",Totalprice=" + txtTotalPrice.Text + ",StockDate= #" + dtpStockDate.Value + "# where StockID='" + txtStockID.Text + "'"; cmd = new OleDbCommand(cb); cmd.Connection = con; cmd.ExecuteReader(); con.Close(); MessageBox.Show("Successfully updated", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information); btnUpdate.Enabled = false; GetData(); frmMainMenu frm = new frmMainMenu(); frm.GetData(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnOK_Click(object sender, EventArgs e) { if (txtUserName.Text == "") { MessageBox.Show("Please enter user name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtUserName.Focus(); return; } if (txtPassword.Text == "") { MessageBox.Show("Please enter password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPassword.Focus(); return; } try { if (!Directory.Exists(ConfigurationManager.AppSettings["DatabaseFolder"])) { DirectoryInfo di = Directory.CreateDirectory(ConfigurationManager.AppSettings["DatabaseFolder"]); DirectorySecurity ds = di.GetAccessControl(); ds.AddAccessRule(new FileSystemAccessRule("Users",FileSystemRights.Delete,AccessControlType.Deny)); ds.AddAccessRule(new FileSystemAccessRule("Administrators", FileSystemRights.Delete, AccessControlType.Deny)); di.SetAccessControl(ds); di.Attributes = FileAttributes.Directory | FileAttributes.Hidden; if (!File.Exists(ConfigurationManager.AppSettings["DatabasePath"])) { File.Copy("SIS_DB.accdb", ConfigurationManager.AppSettings["DatabasePath"]); //OleDbConnection newConnection = default(OleDbConnection); //newConnection = new OleDbConnection(cs); //OleDbCommand newCommand = default(OleDbCommand); //newCommand = new OleDbCommand("INSERT INTO [Registration] ([NameOfUser], [UserName], [User_Password], [ContactNo], [Email], [JoiningDate]) VALUES (\"bala\", \"admin\", \"12345\", NULL, NULL, NULL);", newConnection); //newCommand.Connection.Open(); //newCommand.ExecuteNonQuery(); //newCommand.Connection.Close(); //newCommand = new OleDbCommand("INSERT INTO [Users] ([Username], [User_Password]) VALUES (\"admin\", \"12345\");", newConnection); //newCommand.Connection.Open(); //newCommand.ExecuteNonQuery(); //newCommand.Connection.Close(); } } OleDbConnection myConnection = default(OleDbConnection); myConnection = new OleDbConnection(cs); OleDbCommand myCommand = default(OleDbCommand); myCommand = new OleDbCommand("SELECT Username,User_password FROM Users WHERE Username = @username AND User_password = @UserPassword", myConnection); OleDbParameter uName = new OleDbParameter("@username", OleDbType.VarChar); OleDbParameter uPassword = new OleDbParameter("@UserPassword", OleDbType.VarChar); uName.Value = txtUserName.Text; uPassword.Value = txtPassword.Text; myCommand.Parameters.Add(uName); myCommand.Parameters.Add(uPassword); myCommand.Connection.Open(); OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection); if (myReader.Read() == true) { int i; ProgressBar1.Visible = true; ProgressBar1.Maximum = 5000; ProgressBar1.Minimum = 0; ProgressBar1.Value = 4; ProgressBar1.Step = 1; for (i = 0; i <= 5000; i++) { ProgressBar1.PerformStep(); } this.Hide(); frmMainMenu frm = new frmMainMenu(); frm.Show(); frm.lblUser.Text = txtUserName.Text; } else { MessageBox.Show("Login is Failed...Try again !", "Login Denied", MessageBoxButtons.OK, MessageBoxIcon.Error); txtUserName.Clear(); txtPassword.Clear(); txtUserName.Focus(); } if (myConnection.State == ConnectionState.Open) { myConnection.Dispose(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnSave_Click(object sender, EventArgs e) { if (txtProductname.Text == "") { MessageBox.Show("Please retrieve product name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtProductname.Focus(); return; } if (txtQty.Text == "") { MessageBox.Show("Please enter quantity", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtQty.Focus(); return; } try { con = new OleDbConnection(cs); con.Open(); String ct = "select ConfigID from stock where ConfigID=" + txtConfigID.Text +""; cmd = new OleDbCommand(ct); cmd.Connection = con; rdr = cmd.ExecuteReader(); if (rdr.Read()==true) { MessageBox.Show("Record already exists" + "\n" + "please update the stock of product", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); if ((rdr != null)) { rdr.Close(); } return; } auto(); con = new OleDbConnection(cs); con.Open(); string cb = "insert into Stock(StockID,ConfigID,Quantity,Totalprice,StockDate) VALUES ('" + txtStockID.Text + "'," + txtConfigID.Text + "," + txtQty.Text + "," + txtTotalPrice.Text +",#" + dtpStockDate.Value + "#)"; cmd = new OleDbCommand(cb); cmd.Connection = con; cmd.ExecuteReader(); con.Close(); MessageBox.Show("Successfully saved", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information); btnSave.Enabled = false; GetData(); frmMainMenu frm = new frmMainMenu(); frm.GetData(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }