private void btn_close_Click(object sender, EventArgs e) { SELECTCOMPANY FRM = new SELECTCOMPANY(); FRM.Show(); this.Close(); }
private void btn_save_Click(object sender, EventArgs e) { try { con = new OleDbConnection(cs); con.Open(); string ct = "select COMPANYNAME from Company where COMPANYNAME='" + txtCompanyName.Text + "'"; cmd = new OleDbCommand(ct); cmd.Connection = con; rdr = cmd.ExecuteReader(); if (rdr.Read()) { MessageBox.Show("Company Name Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtCompanyName.Text = ""; txtCompanyName.Focus(); if ((rdr != null)) { rdr.Close(); } return; } System.IO.Directory.CreateDirectory(@"C:\\ACCOUNTMANAGEMENT\\ACCOUNTMANAGEMENT\\Data" + "\\" + txtCompanyName.Text); System.IO.File.Copy(@"C:\\ACCOUNTMANAGEMENT\\ACCOUNTMANAGEMENT\\Data\\accountmanagement.accdb", @"C:\\ACCOUNTMANAGEMENT\\ACCOUNTMANAGEMENT\\Data" + "\\" + txtCompanyName.Text + "\\accountmanagement.accdb"); con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\ACCOUNTMANAGEMENT\\ACCOUNTMANAGEMENT\\Data" + "\\" + txtCompanyName.Text + "\\accountmanagement.accdb;"); con.Open(); string cb2 = "DELETE * FROM Company "; cmd = new OleDbCommand(cb2); cmd.Connection = con; cmd.ExecuteReader(); con.Close(); con = new OleDbConnection(cs); con.Open(); string PATH = @"C:\\ACCOUNTMANAGEMENT\\ACCOUNTMANAGEMENT\\Data" + "\\" + txtCompanyName.Text + "\\accountmanagement.accdb"; string cb = "insert into Company(COMPANYNAME,ADDRESS,PHONENO,EMAIL,WEB,FINANCIALYEARFROM,FINANCIALYEAREND,TINNO,CSTNO,EXTRA1,EXTRA2,PATH) VALUES ('" + txtCompanyName.Text + "','" + txtAddress.Text + "','" + txtPhoneNo.Text + "','" + txtEmail.Text + "','" + txtWeb.Text + "','" + dtpfromDate.Text + "','" + dtpclosingdate.Text + "','" + txtTinNo.Text + "','" + txtCstNo.Text + "','" + txt_extra1.Text + "','" + "','" + PATH + "')"; cmd = new OleDbCommand(cb); cmd.Connection = con; cmd.ExecuteReader(); con.Close(); con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\ACCOUNTMANAGEMENT\\ACCOUNTMANAGEMENT\\Data" + "\\" + txtCompanyName.Text + "\\accountmanagement.accdb;"); con.Open(); string cb1 = "insert into Company(COMPANYNAME,ADDRESS,PHONENO,EMAIL,WEB,FINANCIALYEARFROM,FINANCIALYEAREND,TINNO,CSTNO,EXTRA1,EXTRA2,PATH) VALUES ('" + txtCompanyName.Text + "','" + txtAddress.Text + "','" + txtPhoneNo.Text + "','" + txtEmail.Text + "','" + txtWeb.Text + "','" + dtpfromDate.Text + "','" + dtpclosingdate.Text + "','" + txtTinNo.Text + "','" + txtCstNo.Text + "','" + txt_extra1.Text + "','" + PATH + "')"; cmd = new OleDbCommand(cb1); cmd.Connection = con; cmd.ExecuteReader(); con.Close(); MessageBox.Show("Successfully saved", "Company", MessageBoxButtons.OK, MessageBoxIcon.Information); Reset(); btn_save.Enabled = false; SELECTCOMPANY frm = new SELECTCOMPANY(); frm.Show(); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }