private void HistoryExpense_Load(object sender, EventArgs e) { LogIn li = new LogIn(); string acc = LogIn.acoount; button1.Text = acc + ""; try { DataCon.ConnectionDB("ENDROX", "BookStore"); string sql = "SELECT *from Expense where expenseid = (select max(expenseid) from Expense) or expenseid = (select max(expenseid)-1 from Expense) or expenseid = (select max(expenseid)-2 from Expense); "; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); SqlDataReader r = s.ExecuteReader(); while (r.Read()) { string expenseID = r.GetValue(0) + ""; string eid = r.GetValue(3) + ""; string date = r.GetValue(1) + ""; string total = r.GetValue(2) + ""; dataGridView1.Rows.Add(expenseID, eid, Convert.ToDateTime(date), total); dataGridView1.Columns[2].DefaultCellStyle.Format = "MM/dd/yyyy".Trim(); } r.Close(); s.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button1_Click(object sender, EventArgs e) { dataGridView1.Rows.Clear(); try { DataCon.ConnectionDB("ENDROX", "BookStore"); string sql = "select* from Supplier where supname like '%" + textBox2.Text + "%' ; "; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); SqlDataReader r = s.ExecuteReader(); while (r.Read()) { string id = r.GetValue(0) + ""; string name = r.GetValue(1) + ""; string address = r.GetValue(2) + ""; string contact = r.GetValue(3) + ""; dataGridView1.Rows.Add(id, name, address, contact); } r.Close(); s.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button7_Click(object sender, EventArgs e) { try { DataCon.ConnectionDB("ENDROX", "BookStore"); int row = Convert.ToInt16(textBox1.Text); string id = textBox1.Text.Trim(); string name = textBox6.Text.Trim(); string pass = textBox7.Text.Trim(); string type = comboBox1.SelectedItem + ""; string sql = "update Username SET username=N'" + name + "', password=N'" + pass + "', acctype=N'" + type + "'Where eid=" + row + " ;"; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); s.ExecuteNonQuery(); s.Dispose(); string message = "Successfully Updated"; string title = " Message "; MessageBox.Show(message, title); textBox6.Text = ""; textBox7.Text = ""; comboBox1.SelectedIndex = -1; User u = new User(); u.Show(); this.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void salehistory_Load(object sender, EventArgs e) { LogIn li = new LogIn(); string acc = LogIn.acoount; button1.Text = acc + ""; try { DataCon.ConnectionDB("ENDROX", "BookStore"); string sql = "SELECT *from Sale; "; double sum = 0; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); SqlDataReader r = s.ExecuteReader(); while (r.Read()) { string saleid = r.GetValue(0) + ""; string employee = r.GetValue(3) + ""; string date = r.GetValue(1) + ""; string GrandTotal = r.GetValue(2) + ""; dataGridView1.Rows.Add(saleid, Convert.ToDateTime(date), employee, GrandTotal); dataGridView1.Columns[1].DefaultCellStyle.Format = "MM/dd/yyyy".Trim(); sum += Convert.ToDouble(GrandTotal); textBox2.Text = sum + ""; } r.Close(); s.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Employee_Load(object sender, EventArgs e) { button4.Enabled = true; LogIn li = new LogIn(); string acc = LogIn.acoount; button1.Text = acc + ""; try { DataCon.ConnectionDB("ENDROX", "BookStore"); string sql = "select * from Employee"; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); SqlDataReader r = s.ExecuteReader(); while (r.Read()) { string id = r.GetValue(0) + ""; string name = r.GetValue(1) + ""; string address = r.GetValue(3) + ""; string contact = r.GetValue(4) + ""; string position = r.GetValue(2) + ""; dataGridView1.Rows.Add(id, name, address, contact, position); } r.Close(); s.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button6_Click(object sender, EventArgs e) { try { DataCon.ConnectionDB("ENDROX", "BookStore"); int row = Convert.ToInt16(textBox1.Text); string sql = "delete from Username Where eid=" + row + " ;"; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); s.ExecuteNonQuery(); s.Dispose(); string message = "One Row Deleted"; string title = " Message "; MessageBox.Show(message, title); textBox6.Text = ""; textBox7.Text = ""; comboBox1.SelectedIndex = -1; LogIn em = new LogIn(); em.Show(); this.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button6_Click(object sender, EventArgs e) { try { DataCon.ConnectionDB("ENDROX", "BookStore"); int row = Convert.ToInt16(textBox1.Text); string sql = "delete from Employee Where eid=" + row + " ;"; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); s.ExecuteNonQuery(); s.Dispose(); string message = "One Row Deleted"; string title = " Message "; MessageBox.Show(message, title); textBox6.Text = ""; textBox7.Text = ""; textBox8.Text = ""; textBox9.Text = ""; button4.Enabled = true; button7.Enabled = false; button6.Enabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button7_Click(object sender, EventArgs e) { try { DataCon.ConnectionDB("ENDROX", "BookStore"); int row = dataGridView1.CurrentCell.RowIndex + 1; string name = textBox6.Text.Trim(); string contact = textBox8.Text.Trim(); string position = textBox9.Text.Trim(); string address = textBox7.Text.Trim(); string sql = "update Employee SET ename=N'" + name + "', position=N'" + position + "', address=N'" + address + "', telephone='" + contact + "'Where eid=" + row + " ;"; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); s.ExecuteNonQuery(); s.Dispose(); string message = "Successfully Updated"; string title = " Message "; MessageBox.Show(message, title); textBox6.Text = ""; textBox7.Text = ""; textBox8.Text = ""; textBox9.Text = ""; Employee em = new Employee(); em.Show(); this.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button8_Click(object sender, EventArgs e) { LogIn li = new LogIn(); string acc = LogIn.acoount; button1.Text = acc + ""; try { DataCon.ConnectionDB("ENDROX", "BookStore"); string sql; int indexx = Convert.ToInt16(textBox1.Text); double gtotal = Convert.ToDouble(textBox2.Text); int eid = Convert.ToInt16(textBox4.Text); sql = "insert into Expense(expenseid,expensedate, expensetotal, eid) values ('" + indexx + "',N'" + dateTimePicker1.Text + "','" + gtotal + "','" + eid + "');"; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); s.ExecuteNonQuery(); s.Dispose(); int ro = dataGridView1.RowCount - 1; for (int i = 0; i < ro; i++) { sql = "insert into ExpenseDetail(expenseid,qty, description, price, amount) values ('" + Convert.ToInt16(dataGridView1.Rows[i].Cells["expense_id"].Value) + "','" + Convert.ToInt16(dataGridView1.Rows[i].Cells["Quantity"].Value) + "',N'" + dataGridView1.Rows[i].Cells["Description"].Value + "','" + Convert.ToSingle(dataGridView1.Rows[i].Cells["Cost"].Value) + "','" + Convert.ToSingle(dataGridView1.Rows[i].Cells["Amount"].Value) + "');"; SqlCommand si = new SqlCommand(sql, DataCon.DataConnection); si.ExecuteNonQuery(); } string message = "Successfully Saved"; string title = " Message "; MessageBox.Show(message, title); textBox2.Text = ""; dateTimePicker1.Value = System.DateTime.Now; dataGridView1.Rows.Clear(); comboBox1.Text = ""; textBox6.Text = ""; textBox7.Text = ""; textBox8.Text = ""; textBox8.Enabled = false; textBox8.Text = "1"; textBox8.Visible = false; Visible = false; Expense ep = new Expense(); ep.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button4_Click(object sender, EventArgs e) { textBox1.Text = ""; Employee em = new Employee(); int ide = Convert.ToInt16(Employee.sendtext); textBox1.Text = ide + ""; try { DataCon.ConnectionDB("ENDROX", "BookStore"); string sqlx = "select username from Username where username = '******'"; SqlCommand a = new SqlCommand(sqlx, DataCon.DataConnection); SqlDataReader r = a.ExecuteReader(); while (r.Read()) { string idx = r.GetValue(0) + ""; textBox4.Text = idx; } r.Close(); if (textBox4.Text != "") { MessageBox.Show("Username has already been taken..."); textBox6.Text = ""; textBox7.Text = ""; comboBox1.Text = ""; } else if ((textBox4.Text == "")) { string id = textBox1.Text.Trim(); string name = textBox6.Text.Trim(); string pass = textBox7.Text.Trim(); string type = comboBox1.SelectedItem + ""; string sql = "insert into Username(eid,username, password, acctype) values ('" + ide + "',N'" + name + "',N'" + pass + "',N'" + type + "')"; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); s.ExecuteNonQuery(); s.Dispose(); string message = "Successfully ADD"; string title = " Message "; MessageBox.Show(message, title); User u = new User(); u.Show(); this.Dispose(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void User_Load(object sender, EventArgs e) { Employee em = new Employee(); int ide = Convert.ToInt16(Employee.sendtext); textBox1.Text = ide + ""; textBox2.Text = Employee.row + ""; LogIn li = new LogIn(); string acc = LogIn.acoount; button1.Text = acc + ""; try { DataCon.ConnectionDB("ENDROX", "BookStore"); string sql = "select * from Username where eid ='" + ide + "'"; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); SqlDataReader r = s.ExecuteReader(); while (r.Read()) { string id = r.GetValue(3) + ""; string name = r.GetValue(0) + ""; string pass = r.GetValue(1) + ""; string type = r.GetValue(2) + ""; dataGridView1.Rows.Add(id, name, pass, type); } r.Close(); s.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } textBox3.Text = dataGridView1.RowCount + ""; if (Convert.ToInt16(textBox3.Text) > 1) { button4.Enabled = false; button7.Enabled = true; button6.Enabled = true; } else if (Convert.ToInt16(textBox3.Text) <= 1) { button4.Enabled = true; button7.Enabled = false; button6.Enabled = false; } }
private void MainForm_Load(object sender, EventArgs e) { LogIn li = new LogIn(); string acc = LogIn.acoount; password.Text = acc + ""; try { DataCon.ConnectionDB("ENDROX", "BookStore"); string sql = "SELECT acctype FROM Username WHERE username='******';"; SqlCommand a = new SqlCommand(sql, DataCon.DataConnection); SqlDataReader r = a.ExecuteReader(); while (r.Read()) { string id = r.GetValue(0) + ""; boxx.Text = id + ""; } r.Close(); if (boxx.Text == "admin") { Book.Enabled = true; Expense.Enabled = true; Sale.Enabled = true; User.Enabled = true; } if (boxx.Text == "stock") { Book.Enabled = true; Expense.Enabled = false; Sale.Enabled = false; User.Enabled = false; } if (boxx.Text == "cashier") { Book.Enabled = false; Expense.Enabled = false; Sale.Enabled = true; User.Enabled = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button2_Click(object sender, EventArgs e) { dataGridView1.Rows.Clear(); try { DataCon.ConnectionDB("ENDROX", "BookStore"); string sql = "declare @x varchar(25);set @x = '" + textBox6.Text.Trim() + "';declare @y varchar(25);set @y = '" + textBox1.Text.Trim() + "';select* from Sale where saledate between @x and @y; "; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); SqlDataReader r = s.ExecuteReader(); double sum = 0, count = 0; while (r.Read()) { string saleid = r.GetValue(0) + ""; string employee = r.GetValue(3) + ""; string date = r.GetValue(1) + ""; string GrandTotal = r.GetValue(2) + ""; dataGridView1.Rows.Add(saleid, Convert.ToDateTime(date), employee, GrandTotal); dataGridView1.Columns[1].DefaultCellStyle.Format = "MM/dd/yyyy".Trim(); sum += Convert.ToDouble(GrandTotal); textBox2.Text = sum + ""; count += 1; textBox3.Text = count + ""; } r.Close(); s.Dispose(); if (dataGridView1.Rows.Count > 1) { count = Convert.ToDouble(textBox3.Text); string message = "Found " + count + ""; string title = " Message "; MessageBox.Show(message, title); } else { string message = "No Record Found"; string title = " Message "; MessageBox.Show(message, title); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "") { if (textBox1.Text == "") { textBox1.Focus(); MessageBox.Show("Please fill in 'Supplier No.'"); } if (textBox2.Text == "") { textBox2.Focus(); MessageBox.Show("Please fill in 'Name'"); } if (textBox3.Text == "") { textBox3.Focus(); MessageBox.Show("Please fill in 'Address'"); } if (textBox4.Text == "") { textBox4.Focus(); MessageBox.Show("Please fill in 'Contact'"); } } else { try { DataCon.ConnectionDB("ENDROX", "BookStore"); string id = textBox1.Text.Trim(); string name = textBox2.Text.Trim(); string contact = textBox3.Text.Trim(); string address = textBox4.Text.Trim(); string sql = "insert into Supplier(supid,supname, supaddress, supcontact) values ('" + id + "',N'" + name + "',N'" + contact + "',N'" + address + "')"; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); s.ExecuteNonQuery(); s.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } Visible = false; } }
private void stockaj_Load(object sender, EventArgs e) { Stock sk = new Stock(); textBox3.Text = Stock.sendtext; try { DataCon.ConnectionDB("ENDROX", "BookStore"); string sql = "SELECT * from Book where bid = '" + textBox3.Text.Trim() + "';"; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); SqlDataReader r = s.ExecuteReader(); while (r.Read()) { textBox4.Text = r.GetValue(0) + ""; textBox5.Text = r.GetValue(1) + ""; textBox6.Text = r.GetValue(2) + ""; string Price = r.GetValue(3) + ""; textBox2.Text = Price + ""; textBox10.Text = r.GetValue(4) + ""; textBox7.Text = r.GetValue(5) + ""; textBox8.Text = r.GetValue(6) + ""; textBox9.Text = r.GetValue(7) + ""; textBox11.Text = r.GetValue(8) + ""; pictureBox1.Image = Image.FromFile(textBox11.Text); pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; } r.Close(); s.Dispose(); string sql1 = "SELECT cname from Category where catid = '" + textBox10.Text.Trim() + "';"; SqlCommand s1 = new SqlCommand(sql1, DataCon.DataConnection); SqlDataReader r1 = s1.ExecuteReader(); while (r1.Read()) { comboBox1.Text = r1.GetValue(0) + ""; } r1.Close(); s1.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void sale_Load(object sender, EventArgs e) { button4.Enabled = true; LogIn li = new LogIn(); string acc = LogIn.acoount; button1.Text = acc + ""; textBox3.Text = acc + ""; DataCon.ConnectionDB("ENDROX", "BookStore"); int index; string sql = "select MAX(saleid) from Sale"; SqlCommand a = new SqlCommand(sql, DataCon.DataConnection); SqlDataReader r = a.ExecuteReader(); while (r.Read()) { string id = r.GetValue(0) + ""; index = Convert.ToInt16(id) + 1; textBox1.Text = index + ""; } r.Close(); a.Dispose(); sql = "select eid from Username where username='******';"; SqlCommand ai = new SqlCommand(sql, DataCon.DataConnection); SqlDataReader ri = ai.ExecuteReader(); while (ri.Read()) { string eidi = ri.GetValue(0) + ""; index = Convert.ToInt16(eidi); textBox4.Text = index + ""; } ri.Close(); ai.Dispose(); }
private void Supplier_Load(object sender, EventArgs e) { try { DataCon.ConnectionDB("ENDROX", "BookStore"); int index; string sql = "select MAX(supid) from Supplier"; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); SqlDataReader r = s.ExecuteReader(); while (r.Read()) { string id = r.GetValue(0) + ""; index = Convert.ToInt16(id) + 1; textBox1.Text = index.ToString(); } r.Close(); s.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void bntlogin_Click(object sender, EventArgs e) { try { DataCon.ConnectionDB("ENDROX", "BookStore"); SqlDataAdapter sda = new SqlDataAdapter("SELECT COUNT(*) FROM Username WHERE username='******' AND password='******'", DataCon.DataConnection); DataTable dt = new DataTable(); sda.Fill(dt); if (dt.Rows[0][0].ToString() == "1") { string message = "Successfully login"; string title = " Message "; MessageBox.Show(message, title); acoount = txtuser.Text.ToString(); MainForm mf = new MainForm(); mf.Show(); this.Visible = false; } else { string message = "Incorrect Username or Password"; string title = " Message "; MessageBox.Show(message, title); txtuser.Text = ""; txtpass.Text = ""; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Stock_Load(object sender, EventArgs e) { LogIn li = new LogIn(); string acc = LogIn.acoount; button2.Text = acc + ""; button1.Text = "By Book Name"; try { DataCon.ConnectionDB("ENDROX", "BookStore"); string sql = "SELECT * from Book; "; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); SqlDataReader r = s.ExecuteReader(); while (r.Read()) { string Book_Code = r.GetValue(0) + ""; string Title = r.GetValue(1) + ""; string Quantity = r.GetValue(2) + ""; string Author = r.GetValue(5) + ""; string year = r.GetValue(6) + ""; string Location = r.GetValue(7) + ""; string Price = r.GetValue(3) + ""; string Genre = r.GetValue(4) + ""; string Attachment = r.GetValue(8) + ""; dataGridView1.Rows.Add(Book_Code, Title, Quantity, Author, year, Location, Price, Genre, Attachment); } r.Close(); s.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void bntreset_Click(object sender, EventArgs e) { LogIn li = new LogIn(); string acc = LogIn.acoount; if (txtpass.Text == txtpass2.Text) { try { DataCon.ConnectionDB("ENDROX", "BookStore"); string pass = txtpass.Text.Trim(); string pass2 = txtpass2.Text.Trim(); string sql = "update Username SET password=N'" + pass + "'Where username=N'" + acc + "' ;"; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); s.ExecuteNonQuery(); s.Dispose(); string message = "Successfully Updated"; string title = " Message "; MessageBox.Show(message, title); MainForm mf = new MainForm(); mf.Show(); this.Visible = false; } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Incorrect Confirm Password..."); } }
private void button2_Click(object sender, EventArgs e) { if (textBox4.Text == "") { MessageBox.Show("Please Complete form filling ..."); } else { double D = 0, kh = 0, cb; D += Convert.ToDouble(textBox7.Text); kh += Convert.ToDouble(textBox8.Text) / 4000; cb = (D + kh) - Convert.ToDouble(textBox2.Text); if (cb >= 0) { try { DataCon.ConnectionDB("ENDROX", "BookStore"); int dindex, x; float y; string sql = "select bid, bqty from Book where bid ='" + textBox16.Text + "'"; SqlCommand a = new SqlCommand(sql, DataCon.DataConnection); SqlDataReader r = a.ExecuteReader(); while (r.Read()) { string id = r.GetValue(0) + ""; dindex = Convert.ToInt16(id); textBox14.Text = dindex + ""; string idx = r.GetValue(1) + ""; x = Convert.ToInt16(idx); textBox15.Text = x + ""; } r.Close(); int indexx = Convert.ToInt16(textBox1.Text); double gtotal = Convert.ToDouble(textBox2.Text); int eid = Convert.ToInt16(textBox4.Text); sql = "insert into Sale(saleid,saledate, samount, eid) values ('" + indexx + "',N'" + dateTimePicker1.Text + "','" + gtotal + "','" + eid + "');"; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); s.ExecuteNonQuery(); s.Dispose(); int ro = dataGridView1.RowCount - 1; for (int i = 0; i < ro; i++) { sql = "insert into SaleDetail(saleid,sdqty, sdprice, sdtotal, bid) values ('" + indexx + "','" + Convert.ToInt16(dataGridView1.Rows[i].Cells["Quantity"].Value) + "','" + Convert.ToSingle(dataGridView1.Rows[i].Cells["Price"].Value) + "','" + Convert.ToSingle(dataGridView1.Rows[i].Cells["totals"].Value) + "','" + dataGridView1.Rows[i].Cells["Book_Code"].Value + "');"; SqlCommand si = new SqlCommand(sql, DataCon.DataConnection); si.ExecuteNonQuery(); int nbqty = Convert.ToInt16(textBox15.Text) - Convert.ToInt16(dataGridView1.Rows[i].Cells["Quantity"].Value); sql = "update Book set bqty ='" + nbqty + "' where bid = '" + textBox16.Text + "' ;"; SqlCommand sa = new SqlCommand(sql, DataCon.DataConnection); sa.ExecuteNonQuery(); } string message = "Cashback = " + cb + ""; string title = " Message "; MessageBox.Show(message, title); message = "Successfully Saved"; title = " Message "; MessageBox.Show(message, title); textBox2.Text = ""; dateTimePicker1.Value = System.DateTime.Now; dataGridView1.Rows.Clear(); textBox6.Text = ""; textBox10.Text = ""; textBox11.Text = ""; Visible = false; sale sl = new sale(); sl.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { string message = "Need " + cb + " to Complete the Payment"; string title = " Message "; MessageBox.Show(message, title); } } }
private void button4_Click(object sender, EventArgs e) { if (textBox6.Text == "" || textBox10.Text == "") { if (textBox6.Text == "") { textBox6.Focus(); MessageBox.Show("Please fill in 'Book Code'"); } if (textBox10.Text == "") { textBox10.Focus(); MessageBox.Show("Please fill in 'Quantity'"); } } else { for (int i = 0; i < dataGridView1.RowCount; i++) { if (textBox6.Text == dataGridView1["Book_Code", i].Value + "") { MessageBox.Show("Duplicate ...."); DataGridViewRow rowa = this.dataGridView1.Rows[i]; textBox12.Text = rowa.Cells["Quantity"].Value + ""; int x = Convert.ToInt16(textBox12.Text) + Convert.ToInt16(textBox10.Text); textBox13.Text = rowa.Cells["Price"].Value + ""; int y = x * Convert.ToInt16(textBox13.Text); int total = 0; total += y; textBox2.Text = total + ""; DataGridViewRow newDataRow = dataGridView1.Rows[i]; newDataRow.Cells["Quantity"].Value = x; newDataRow.Cells["totals"].Value = y; goto x; } } int index; string sql; DataCon.ConnectionDB("ENDROX", "BookStore"); sql = "select catid,bprice from Book where bid='" + textBox6.Text + "';"; SqlCommand ae = new SqlCommand(sql, DataCon.DataConnection); SqlDataReader re = ae.ExecuteReader(); while (re.Read()) { string Gid = re.GetValue(0) + ""; string Bprice = re.GetValue(1) + ""; index = Convert.ToInt16(Gid); textBox5.Text = Gid + ""; textBox11.Text = Bprice; } re.Close(); ae.Dispose(); sql = "select cname from Category where catid='" + textBox5.Text + "';"; SqlCommand ai = new SqlCommand(sql, DataCon.DataConnection); SqlDataReader ri = ai.ExecuteReader(); while (ri.Read()) { string cname = ri.GetValue(0) + ""; textBox9.Text = cname + ""; } ri.Close(); ai.Dispose(); int row = 0; dataGridView1.Rows.Add(); row = dataGridView1.Rows.Count - 2; dataGridView1["Book_Code", row].Value = textBox6.Text; dataGridView1["Category", row].Value = textBox9.Text; dataGridView1["Quantity", row].Value = textBox10.Text; dataGridView1["Price", row].Value = textBox11.Text; dataGridView1["totals", row].Value = Convert.ToDouble(textBox10.Text) * Convert.ToDouble(textBox11.Text); textBox16.Text = textBox6.Text; string message = "Successfully Add"; string title = " Message "; MessageBox.Show(message, title); x: double total1 = 0, sum = 0; for (int i = 0; i < dataGridView1.Rows.Count; i++) { total1 += Convert.ToDouble(dataGridView1.Rows[i].Cells["totals"].Value); } sum += total1; textBox2.Text = sum + ""; if (dataGridView1.RowCount > 1) { textBox7.Enabled = true; textBox8.Enabled = true; } else { textBox7.Enabled = false; textBox8.Enabled = false; } button2.Enabled = true; textBox10.Text = ""; textBox6.Text = ""; } }
private void button1_Click(object sender, EventArgs e) { if (textBox2.Text != "" && button1.Text == "By Book Name") { dataGridView1.Rows.Clear(); try { DataCon.ConnectionDB("ENDROX", "BookStore"); string sql = "SELECT * from Book where bname like '%" + textBox2.Text.Trim() + "%';"; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); SqlDataReader r = s.ExecuteReader(); int c = 0; while (r.Read()) { string Book_Code = r.GetValue(0) + ""; string Title = r.GetValue(1) + ""; string Quantity = r.GetValue(2) + ""; string Author = r.GetValue(5) + ""; string year = r.GetValue(6) + ""; string Location = r.GetValue(7) + ""; string Price = r.GetValue(3) + ""; string Genre = r.GetValue(4) + ""; string Attachment = r.GetValue(8) + ""; dataGridView1.Rows.Add(Book_Code, Title, Quantity, Author, year, Location, Price, Genre, Attachment); c++; textBox3.Text = c + ""; } r.Close(); s.Dispose(); MessageBox.Show(textBox3.Text + " Record Found"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else if (textBox2.Text == "" && button1.Text == "By Book Name") { button1.Text = "By Book Code"; } else if (textBox2.Text != "" && button1.Text == "By Book Code") { dataGridView1.Rows.Clear(); try { DataCon.ConnectionDB("ENDROX", "BookStore"); string sql = "SELECT * from Book where bid like '%" + textBox2.Text.Trim() + "%';"; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); SqlDataReader r = s.ExecuteReader(); int c = 0; while (r.Read()) { string Book_Code = r.GetValue(0) + ""; string Title = r.GetValue(1) + ""; string Quantity = r.GetValue(2) + ""; string Author = r.GetValue(5) + ""; string year = r.GetValue(6) + ""; string Location = r.GetValue(7) + ""; string Price = r.GetValue(3) + ""; string Genre = r.GetValue(4) + ""; string Attachment = r.GetValue(8) + ""; dataGridView1.Rows.Add(Book_Code, Title, Quantity, Author, year, Location, Price, Genre, Attachment); c++; textBox3.Text = c + ""; } r.Close(); s.Dispose(); MessageBox.Show(textBox3.Text + " Record Found"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else if (textBox2.Text == "" && button1.Text == "By Book Code") { button1.Text = "By Book Name"; } }
private void button9_Click_1(object sender, EventArgs e) { textBox22.Text = ""; textBox7.Text = ""; textBox13.Text = ""; textBox8.Text = ""; textBox11.Text = ""; textBox10.Text = ""; textBox5.Text = ""; textBox12.Text = ""; comboBox1.SelectedIndex = -1; if (textBox6.Text == "") { textBox6.Focus(); MessageBox.Show("Please fill in 'Book Code'"); } else { DataCon.ConnectionDB("ENDROX", "BookStore"); string sql = "select * from Book where bid ='" + textBox6.Text + "'"; SqlCommand a = new SqlCommand(sql, DataCon.DataConnection); SqlDataReader r = a.ExecuteReader(); while (r.Read()) { textBox22.Text = r.GetValue(1) + ""; textBox7.Text = textBox22.Text; textBox12.Text = r.GetValue(3) + ""; textBox8.Text = r.GetValue(5) + ""; comboBox1.SelectedIndex = Convert.ToInt32(r.GetValue(4)) - 1; textBox11.Text = r.GetValue(6) + ""; textBox10.Text = r.GetValue(7) + ""; textBox17.Text = r.GetValue(8) + ""; pictureBox1.Image = Image.FromFile(r.GetValue(8) + ""); textBox7.Enabled = false; textBox8.Enabled = false; comboBox1.Enabled = false; textBox11.Enabled = false; textBox10.Enabled = false; textBox17.Enabled = false; textBox12.Enabled = false; button3.Enabled = false; } r.Close(); if (textBox22.Text == "") { MessageBox.Show("No Record Found..."); textBox7.Enabled = true; textBox8.Enabled = true; comboBox1.Enabled = true; textBox11.Enabled = true; textBox10.Enabled = true; textBox17.Enabled = true; textBox12.Enabled = true; button3.Enabled = true; } } }
private void button8_Click(object sender, EventArgs e) { LogIn li = new LogIn(); string acc = LogIn.acoount; button1.Text = acc + ""; if (textBox4.Text == "") { MessageBox.Show("Please Fill in Supplier No."); } else { try { DataCon.ConnectionDB("ENDROX", "BookStore"); int dindex, x; float y; string sql = "select bid, bqty, bprice from Book where bid ='" + textBox21.Text + "'"; SqlCommand a = new SqlCommand(sql, DataCon.DataConnection); SqlDataReader r = a.ExecuteReader(); while (r.Read()) { string id = r.GetValue(0) + ""; dindex = Convert.ToInt16(id); textBox18.Text = dindex + ""; string idx = r.GetValue(1) + ""; x = Convert.ToInt16(idx); textBox19.Text = x + ""; string idy = r.GetValue(2) + ""; y = Convert.ToSingle(idy); textBox20.Text = y + ""; } r.Close(); int indexx = Convert.ToInt16(textBox1.Text); double gtotal = Convert.ToDouble(textBox2.Text); int eid = Convert.ToInt16(textBox14.Text); int supid = Convert.ToInt16(textBox4.Text); sql = "insert into Import(Importid,Importdate, total, eid, supid) values ('" + indexx + "','" + dateTimePicker1.Text + "','" + gtotal + "','" + eid + "','" + supid + "');"; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); s.ExecuteNonQuery(); s.Dispose(); int ro = dataGridView1.RowCount - 1; for (int i = 0; i < ro; i++) { if (textBox18.Text == "") { sql = "insert into Book(bid, bname, bqty, bprice, catid, author, Year, location, Attachment) values ('" + dataGridView1.Rows[i].Cells["Book_Code"].Value + "','" + dataGridView1.Rows[i].Cells["Title"].Value + "','" + Convert.ToInt16(dataGridView1.Rows[i].Cells["Quantity"].Value) + "','" + Convert.ToSingle(dataGridView1.Rows[i].Cells["Price"].Value) + "','" + Convert.ToInt16(dataGridView1.Rows[i].Cells["Genre"].Value) + "','" + dataGridView1.Rows[i].Cells["Author"].Value + "','" + dataGridView1.Rows[i].Cells["year"].Value + "','" + dataGridView1.Rows[i].Cells["Location"].Value + "',N'" + dataGridView1.Rows[i].Cells["Attachment"].Value + "');"; SqlCommand sa = new SqlCommand(sql, DataCon.DataConnection); sa.ExecuteNonQuery(); } else { int nbqty = Convert.ToInt16(textBox19.Text) + Convert.ToInt16(dataGridView1.Rows[i].Cells["Quantity"].Value); sql = "update Book set bqty ='" + nbqty + "' where bid = '" + textBox18.Text + "' ;"; SqlCommand sa = new SqlCommand(sql, DataCon.DataConnection); sa.ExecuteNonQuery(); } sql = "insert into Importdetail(Importid,iqty, iamout, iprice, bid) values ('" + indexx + "','" + Convert.ToInt16(dataGridView1.Rows[i].Cells["Quantity"].Value) + "','" + Convert.ToSingle(dataGridView1.Rows[i].Cells["Cost"].Value) + "','" + Convert.ToSingle(dataGridView1.Rows[i].Cells["Price"].Value) + "','" + dataGridView1.Rows[i].Cells["Book_Code"].Value + "');"; SqlCommand si = new SqlCommand(sql, DataCon.DataConnection); si.ExecuteNonQuery(); } string message = "Successfully Saved"; string title = " Message "; MessageBox.Show(message, title); textBox2.Text = ""; dateTimePicker1.Value = System.DateTime.Now; dataGridView1.Rows.Clear(); comboBox1.SelectedIndex = -1; textBox6.Text = ""; textBox7.Text = ""; textBox8.Text = ""; Visible = false; HistoryImport hi = new HistoryImport(); hi.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }