private void LoginAdmin() { DataTable read = cn.getDataTable("SELECT * FROM users WHERE username = '******' and passwordHash = '" + HamChung.EncodePassword(txtPassword.Text) + "' and active = 'true'"); if (read.Rows.Count > 0) { ThongTin.idUser = int.Parse(read.Rows[0][0].ToString()); ThongTin.ten = read.Rows[0][1].ToString(); ThongTin.ngaysinh = read.Rows[0][2].ToString(); ThongTin.sdt = read.Rows[0][3].ToString(); ThongTin.quequan = read.Rows[0][5].ToString(); ThongTin.username = read.Rows[0][6].ToString(); ThongTin.quyen = read.Rows[0][9].ToString(); if (ThongTin.quyen != Role.khachhang) { this.Hide(); Main fMain = new Main(); fMain.ShowDialog(); } else { this.Hide(); FormMain ff = new FormMain(); ff.ShowDialog(); } this.Hide(); } else { lbLoginFailed.Text = "Tài khoản hoặc mật khẩu không đúng !"; } }
private void Create() { string ten, sdt, quequan, username, quyen, password; int id; bool gioitinh, active; DateTime ngaysinh; ten = txtTen.Text; sdt = txtSdt.Text; quequan = txtQueQuan.Text; username = txtUsername.Text; quyen = cbQuyen.SelectedIndex != 0 ? cbQuyen.SelectedItem.ToString() : ""; gioitinh = HamChung.NamNuToTrueFalse(cbGioiTinh.SelectedItem.ToString()); active = checkActive.Checked; ngaysinh = dateTimePicker1.Value; password = HamChung.EncodePassword(txtPassword.Text); //NHAN VIEN if (!CheckUsername("users", username)) { MessageBox.Show("Tài khoản đã tồn tại trong hệ thống!", "Thông báo!"); } else { string sql = "Insert into users (ten,ngaysinh,sdt,gioitinh,quequan,username,passwordHash,active,quyen) values(N'" + ten + "','" + ngaysinh + "','" + sdt + "','" + gioitinh + "',N'" + quequan + "','" + username + "','" + password + "','" + active + "',N'" + quyen + "')"; cn.ExecuteNonQuery(sql); MessageBox.Show("Tạo tài khoản thành công!", "Thông báo"); } }
private void Create() { string ten, ngaysinh, sdt, quequan, username, password, quyen; bool active = true; bool gioitinh; ten = txtTen.Text; ngaysinh = datePicker.Value.ToString(); gioitinh = cbGioiTinh.SelectedItem.ToString() == "Nam" ? true : false; sdt = txtPhone.Text; quequan = txtDiaChi.Text; username = txtUser.Text; password = HamChung.EncodePassword(txtPassword.Text); quyen = cbQuyen.SelectedItem.ToString(); //NHAN VIEN if (!CheckUsername("users", username)) { MessageBox.Show("Tài khoản đã tồn tại trong hệ thống!", "Thông báo!"); } else { string sql = "Insert into users (ten,ngaysinh,sdt,gioitinh,quequan,username,passwordHash,active,quyen) values('" + ten + "','" + ngaysinh + "','" + sdt + "','" + gioitinh + "','" + quequan + "','" + username + "','" + password + "','" + active + "','" + quyen + "')"; cn.ExecuteNonQuery(sql); MessageBox.Show("Tạo tài khoản thành công!", "Thông báo"); } }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0 && e.RowIndex != -1) { var confirmResult = MessageBox.Show("Bạn có muốn xóa ??", "Cảnh báo!!", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { int id = Int32.Parse(dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString()); } } else if (e.RowIndex != -1) { txtMa.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); txtTen.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); dateTimePicker1.Value = DateTime.Parse(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString()); txtSdt.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); cbGioiTinh.SelectedItem = HamChung.TrueFalseToNamNu(Boolean.Parse(dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString())); txtQueQuan.Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString(); txtUsername.Text = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString(); //txtUsername.Text = dataGridView1.Rows[e.RowIndex].Cells[9].Value.ToString(); checkActive.Checked = Boolean.Parse(dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString()); cbQuyen.SelectedItem = dataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString(); } }
private void updateNhanVien() { string ten, sdt, quequan, username, quyen; int id; bool gioitinh, active; DateTime ngaysinh; id = int.Parse(txtMa.Text); ten = txtTen.Text; sdt = txtSdt.Text; quequan = txtQueQuan.Text; username = txtUsername.Text; quyen = cbQuyen.SelectedIndex != 0 ? cbQuyen.SelectedItem.ToString() : ""; gioitinh = HamChung.NamNuToTrueFalse(cbGioiTinh.SelectedItem.ToString()); active = checkActive.Checked; ngaysinh = dateTimePicker1.Value; string sql = "update users set ten = N'" + ten + "',ngaysinh = '" + ngaysinh + "',sdt = '" + sdt + "',gioitinh = '" + gioitinh + "'" + ",quequan = N'" + quequan + "',username = '******',active = '" + active + "',quyen =N'" + quyen + "' where id = " + id; try { cn.ExecuteNonQuery(sql); getDataNhanVien(); } catch (Exception) { MessageBox.Show("Kiểm tra lại thông tin", "Thông báo!"); } }
private void getGioHang() { dataHoaDon = TruyVan(); if (dataHoaDon.Rows.Count > 0) { panelEmpty.Visible = false; lbTrangThaiHD.Text = dataHoaDon.Rows[0][7].ToString(); txtGhiChu.Text = dataHoaDon.Rows[0][8].ToString(); emailKh = dataHoaDon.Rows[0][9].ToString(); IdHoaDong = Int32.Parse(dataHoaDon.Rows[0][6].ToString()); panelParent.Controls.Clear(); noidungEmail = "Đơn hàng của bạn đã được đặt hàng thành công <br />"; foreach (DataRow item in dataHoaDon.Rows) { thanhtien += Int32.Parse(item[5].ToString()); noidungEmail += "Đơn hàng : " + item[0].ToString() + " Số lương: " + item[2].ToString() + "<br />"; addRow(item); } noidungEmail += "Tổng hóa đơn: " + thanhtien + " đồng <br />"; noidungEmail += "Cảm ơn bạn đã ủng hộ, chúng tôi sẽ giao hàng sớm nhất có thê! ^^"; lbTongTien.Text = thanhtien.ToString(); lbTongTienChu.Text = "( " + HamChung.ChuyenSo(thanhtien.ToString()) + " đồng )"; } else { panelParent.Controls.Clear(); panelParent.Controls.Add(panelEmpty); panelEmpty.Visible = true; } }
private void DoiMatKhau() { string sdt, username, pass1, pass2; sdt = txtEmail.Text; username = txtUsername.Text; pass1 = txtPass1.Text; pass2 = txtPass2.Text; if (pass1.Length < 6 || pass2.Length < 6 || pass1 != pass2) { lbSuccess.Text = "Mật khẩu không hợp lệ!"; } else { //check user name var data = cn.getDataTable("select * from users where username = '******' and sdt = '" + sdt + "'"); if (data.Rows.Count < 1) { MessageBox.Show("Thông tin không đúng!", "Thông báo"); return; } string password = HamChung.EncodePassword(pass1); cn.ExecuteNonQuery("UPDATE users set passwordHash = '" + password + "' where sdt = '" + sdt + "' and username = '******'"); MessageBox.Show("Đổi mật khẩu thành công!", "Thông báo"); Login d = new Login(); d.Show(); this.Close(); } }
private void cbLoaiSanPham_SelectedIndexChanged(object sender, EventArgs e) { if (cbLoaiSanPham.SelectedIndex == 0) { SLoai = 0; } else { SLoai = HamChung.GetIdFromCombobox(cbLoaiSanPham.SelectedItem.ToString()); } GetSanPham(); }
private void UpdateTienChu() { var data = TruyVan(); thanhtien = 0; foreach (DataRow item in data.Rows) { thanhtien += Int32.Parse(item[5].ToString()); } lbTongTien.Text = thanhtien.ToString(); lbTongTienChu.Text = "( " + HamChung.ChuyenSo(thanhtien.ToString()) + "đồng)"; }
private void cbSNcc_SelectedIndexChanged(object sender, EventArgs e) { if (cbSNcc.SelectedIndex == 0) { NccId = 0; } else { NccId = HamChung.GetIdFromCombobox(cbSNcc.SelectedItem.ToString()); } GetSanPham(); }
private void InsertOrUpdate() { //try //{ string ten, mota, anh; int id, soluong, dongia, khoId, nccId, loaiId; DateTime ngaynhap; bool active; id = String.IsNullOrEmpty(txtMa.Text) ? 0 : int.Parse(txtMa.Text); ten = txtTen.Text; mota = txtMoTa.Text; anh = !String.IsNullOrEmpty(ptbAnh.Image.ToString()) ? HamChung.GetStringFromImage(ptbAnh.Image) : ""; soluong = Int32.Parse(txtSoLuong.Text); dongia = Int32.Parse(txtDonGia.Text); ngaynhap = DateTime.Now; khoId = HamChung.GetIdFromCombobox(cbKho.SelectedItem.ToString()); nccId = HamChung.GetIdFromCombobox(cbNCC.SelectedItem.ToString()); loaiId = HamChung.GetIdFromCombobox(cbLoaiSanPham.SelectedItem.ToString()); active = checkActive.Checked; if (id == 0) { // thêm cn.ExecuteNonQuery("INSERT INTO SANPHAM VALUES(N'" + ten + "',0," + dongia + ",'" + ngaynhap + "',N'" + mota + "'," + khoId + "," + nccId + "," + loaiId + ",1,0,'" + anh + "')"); MessageBox.Show("Thêm sản phẩm thành công"); } else { string sql = "UPDATE [dbo].[SanPham] SET [ten] = N'" + ten + "' ,[soluong] =" + soluong + " ,[dongia] = " + dongia + " ,[ngaynhap] = '" + ngaynhap + "' ,[mota] = N'" + mota + "' ,[khoId] = " + khoId + " ,[nccId] = " + nccId + " ,[LoaiSanPhamId] = " + loaiId + " ,[active] = '" + active + "' ,[luotxem] =luotxem ,[anh] = '" + anh + "' WHERE id = " + id; cn.ExecuteNonQuery(sql); MessageBox.Show("Sửa sản phẩm thành công"); } GetSanPham(); //} //catch (Exception) //{ // MessageBox.Show("Cách trường dữ liệu không đúng!", "Thông báo"); //} }
// LAY THÔNG TIN CHI TIẾT PHIẾU ĐỔ VÀO datagriopveiw private void getChiTietPhieu() { string sql = "SELECT ct.id as 'Mã',ct.IdSanPham as 'Mã SP',s.ten as 'Tên', ls.ten as 'Loại',ct.soluong as 'Số lượng',ct.dongia as 'Đơn giá'" + "from ChiTietLichSu ct join sanpham s on ct.IdSanPham = s.id left join nhacungcap ls on s.nccId = ls.id where IdLichSu =" + phieuId; DataTable dt = cn.getDataTable(sql); dataGridView1.DataSource = dt; if (dt.Rows.Count > 0) { int sl = 0; int tongtien = 0; foreach (DataRow item in dt.Rows) { sl += Int32.Parse(item[4].ToString()); tongtien += Int32.Parse((Int32.Parse(item[4].ToString()) * Int32.Parse(item[5].ToString())).ToString()); } lbSoLuong.Text = sl.ToString(); lbtongtien.Text = tongtien.ToString(); lbtongchu.Text = HamChung.ChuyenSo(tongtien.ToString()) + " đồng."; } }
private void AutoGenChon(string ma, string ten, string gianhap, string sl, string anh) { Panel panel = new Panel(); Panel panelFooter = new Panel(); Label lbMa = new Label(); Label lbTen = new Label(); Label lbGia = new Label(); Label lbSL = new Label(); Label Anh = new Label(); PictureBox picture1 = new PictureBox(); Label lbMa1 = new Label(); Label lbTen1 = new Label(); Label lbGia1 = new Label(); Label lbSL1 = new Label(); panel.Dock = panelCon.Dock; panel.Size = panelCon.Size; panel.Click += (object s, EventArgs e) => { PickSanPham(Int32.Parse(ma), panel); }; panel.Font = panelCon.Font; panel.BackColor = panelCon.BackColor; panelPickSP.Controls.Add(panel); panelFooter.Dock = panelFooterMau.Dock; panelFooter.BackColor = panelFooterMau.BackColor; panelFooter.Size = panelFooterMau.Size; panel.Controls.Add(panelFooter); // label ma tre lbMa.Text = lbMaTren.Text; lbMa.Size = lbMaTren.Size; lbMa.Location = lbMaTren.Location; lbMa.Click += (object s, EventArgs e) => { PickSanPham(Int32.Parse(ma), panel); }; panel.Controls.Add(lbMa); // label ma duoi lbMa1.Text = ma; lbMa1.Size = lbSMa.Size; lbMa1.Click += (object s, EventArgs e) => { PickSanPham(Int32.Parse(ma), panel); }; lbMa1.Location = lbSMa.Location; panel.Controls.Add(lbMa1); // label ten tre lbTen.Text = lbTenTren.Text; lbTen.Size = lbTenTren.Size; lbTen.Click += (object s, EventArgs e) => { PickSanPham(Int32.Parse(ma), panel); }; lbTen.Location = lbTenTren.Location; panel.Controls.Add(lbTen); // label ten duoi lbTen1.Text = ten; lbTen1.Location = lbSten.Location; lbTen1.Size = lbSten.Size; lbTen1.Click += (object s, EventArgs e) => { PickSanPham(Int32.Parse(ma), panel); }; lbTen1.AutoSize = lbSten.AutoSize; panel.Controls.Add(lbTen1); // label gia tre lbGia.Text = lbGiaNhapTren.Text; lbGia.Size = lbGiaNhapTren.Size; lbGia.Click += (object s, EventArgs e) => { PickSanPham(Int32.Parse(ma), panel); }; lbGia.Location = lbGiaNhapTren.Location; panel.Controls.Add(lbGia); // label gia duoi lbGia1.Text = gianhap; lbGia1.Size = lbSgia.Size; lbGia1.Click += (object s, EventArgs e) => { PickSanPham(Int32.Parse(ma), panel); }; lbGia1.Location = lbSgia.Location; panel.Controls.Add(lbGia1); // label sl tre lbSL.Text = lbSLTren.Text; lbSL.Size = lbSLTren.Size; lbSL.Click += (object s, EventArgs e) => { PickSanPham(Int32.Parse(ma), panel); }; lbSL.Location = lbSLTren.Location; panel.Controls.Add(lbSL); // label sl duoi lbSL1.Text = sl; lbSL1.Click += (object s, EventArgs e) => { PickSanPham(Int32.Parse(ma), panel); }; lbSL1.Size = lbSsl.Size; lbSL1.Location = lbSsl.Location; panel.Controls.Add(lbSL1); // label anh duoi Anh.Text = lbAnh.Text; Anh.Size = lbAnh.Size; Anh.Click += (object s, EventArgs e) => { PickSanPham(Int32.Parse(ma), panel); }; Anh.Location = lbAnh.Location; panel.Controls.Add(Anh); picture1.Size = picSanh1.Size; picture1.Image = HamChung.GetImageFromString(anh); picture1.Location = picSanh1.Location; picture1.SizeMode = picSanh1.SizeMode; picture1.Click += (object s, EventArgs e) => { PickSanPham(Int32.Parse(ma), panel); }; panel.Controls.Add(picture1); }
private void createDienThoai(DataRow row) { int id = Int32.Parse(row[0].ToString()); string ten = row[1].ToString(); string gia = String.Format("{0:#,##0.##}", row[2].ToString()); string view = row[3].ToString(); string anh = row[4].ToString(); Panel panel = new Panel(); PictureBox pic = new PictureBox(); Label Lten = new Label(); Label Lgia = new Label(); Label Lview = new Label(); // location w = (panelMau.Width + 5) * count; if (panelSP.Width < w + 110) { w = 0; count = 0; h += panelMau.Height + 5; } count++; // panel panel.Dock = panelMau.Dock; panel.Size = panelMau.Size; panel.BorderStyle = panelMau.BorderStyle; panel.Cursor = panelMau.Cursor; panel.BackColor = panelMau.BackColor; panel.Cursor = Cursors.Hand; panel.Click += (object s, EventArgs e) => { OpenChiTietSanPham(id); }; panel.Location = new Point(20 + w, h); // anh sp pic.Location = picMau.Location; pic.Size = picMau.Size; pic.Image = String.IsNullOrEmpty(anh) ? null : HamChung.GetImageFromString(anh); pic.SizeMode = picMau.SizeMode; pic.Cursor = Cursors.Hand; pic.Click += (object s, EventArgs e) => { OpenChiTietSanPham(id); }; panel.Controls.Add(pic); // ten sp Lten.Location = lbTenMau.Location; Lten.Text = ten; Lten.ForeColor = lbTenMau.ForeColor; Lten.Font = lbTenMau.Font; Lten.AutoSize = lbTenMau.AutoSize; Lten.Size = lbTenMau.Size; Lten.Click += (object s, EventArgs e) => { //OpenChiTietSanPham(id); }; panel.Controls.Add(Lten); Lgia.Text = gia; Lgia.Location = lbGiaMau.Location; Lgia.Font = lbGiaMau.Font; Lgia.AutoSize = true; Lgia.ForeColor = lbGiaMau.ForeColor; Lgia.Click += (object s, EventArgs e) => { //OpenChiTietSanPham(id); }; panel.Controls.Add(Lgia); // gia gach giữa // VIEW COUNT Lview.Location = lbViewMau.Location; Lview.Font = lbViewMau.Font; Lview.ForeColor = lbViewMau.ForeColor; Lview.Text = view; Lview.Click += (object s, EventArgs e) => { //OpenChiTietSanPham(id); }; panel.Controls.Add(Lview); panelSP.Controls.Add(panel); }
private void addRow(DataRow item) { Panel panel = new Panel(); Panel line = new Panel(); PictureBox pictureBox = new PictureBox(); Label lbTen = new Label(); Label lbDonGia = new Label(); Label lbThanhTienTitle = new Label(); Label lbThanhTien = new Label(); Button btnGiamSL = new Button(); Button btnTangSL = new Button(); Button btnDelete = new Button(); TextBox txtsL = new TextBox(); // panel panel.BackColor = Color.FromArgb(24, 30, 54); panel.Dock = DockStyle.Top; panel.Font = label1.Font; panel.Size = new Size(658, 144); panelParent.Controls.Add(panel); // panel line line.Size = new Size(658, 12); line.Dock = DockStyle.Bottom; line.BackColor = Color.White; panel.Controls.Add(line); // btn xoa btnDelete.Text = "Xóa"; if (FindId != 0) { btnDelete.Enabled = false; } btnDelete.Font = label1.Font; btnDelete.Location = new Point(9, 10); btnDelete.ForeColor = Color.Red; btnDelete.Size = new Size(64, 116); btnDelete.Click += (object sender, EventArgs e) => { Delete(Int32.Parse(item[4].ToString())); }; panel.Controls.Add(btnDelete); // anh sach pictureBox.Size = new Size(115, 121); pictureBox.Location = new Point(79, 6); pictureBox.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox.Image = HamChung.GetImageFromString(item[3].ToString()); panel.Controls.Add(pictureBox); // lb tên lbTen.Text = item[0].ToString(); lbTen.Location = new Point(235, 24); lbTen.AutoSize = false; lbTen.Size = new Size(260, 60); lbTen.Font = label1.Font; lbTen.ForeColor = Color.White; panel.Controls.Add(lbTen); // lb dongia giá //lbDonGia.Font = new Font(Font.FontFamily, 12); lbDonGia.Text = (item[1].ToString() + " đồng"); lbDonGia.Location = new Point(235, 87); lbDonGia.ForeColor = Color.White; panel.Controls.Add(lbDonGia); // btn giam btnGiamSL.Text = "-"; btnGiamSL.Font = label1.Font; btnGiamSL.Size = new Size(33, 25); if (FindId != 0) { btnGiamSL.Enabled = false; } btnGiamSL.Location = new Point(545, 22); btnGiamSL.BackColor = Color.White; btnGiamSL.ForeColor = Color.Black; btnGiamSL.Click += (object sender, EventArgs e) => { GiamSoSach(item[4].ToString(), Int32.Parse(item[4].ToString()), Int32.Parse(item[1].ToString())); }; panel.Controls.Add(btnGiamSL); // txt số lượng txtsL.Text = item[2].ToString(); txtsL.Name = "txt" + item[4].ToString(); txtsL.Location = new Point(584, 22); txtsL.ForeColor = Color.Black; txtsL.Size = new Size(46, 25); if (FindId != 0) { txtsL.ReadOnly = true; } txtsL.TextAlign = HorizontalAlignment.Center; txtsL.Font = label1.Font; txtsL.TextChanged += (object sender, EventArgs e) => { EditSL(item[4].ToString(), Int32.Parse(item[4].ToString()), Int32.Parse(item[1].ToString())); }; panel.Controls.Add(txtsL); // btn tang btnTangSL.Text = "+"; btnTangSL.Size = new Size(33, 25); btnTangSL.ForeColor = Color.Black; btnTangSL.Location = new Point(640, 22); btnTangSL.Font = label1.Font; if (FindId != 0) { btnTangSL.Enabled = false; } btnTangSL.BackColor = Color.White; btnTangSL.Click += (object sender, EventArgs e) => { TangSlSach(item[4].ToString(), Int32.Parse(item[4].ToString()), Int32.Parse(item[1].ToString())); }; panel.Controls.Add(btnTangSL); // lb thanh tiền tilte lbThanhTienTitle.Text = "Thành tiền"; lbThanhTienTitle.Location = new Point(570, 59); lbThanhTienTitle.ForeColor = Color.White; lbThanhTienTitle.Font = label1.Font; panel.Controls.Add(lbThanhTienTitle); // lb thanh tiền lbThanhTien.Text = (Int32.Parse(item[1].ToString()) * Int32.Parse(item[2].ToString())).ToString(); lbThanhTien.Name = "txttien" + Int32.Parse(item[4].ToString()); lbThanhTien.Location = new Point(580, 100); lbThanhTien.Font = label1.Font; lbThanhTien.ForeColor = Color.White; panel.Controls.Add(lbThanhTien); }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0 && e.RowIndex != -1) { ma = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); } else if (e.RowIndex != -1) { ma = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); string kho, ncc, nxb, loai; string anh = null; kho = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString(); ncc = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString(); loai = dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString(); var dt = cn.getDataTable("select anh from sanpham where id = " + ma); if (dt.Rows.Count > 0) { anh = dt.Rows[0][0].ToString(); } //AUTO KHO if (String.IsNullOrEmpty(kho)) { cbKho.SelectedIndex = 0; } else { cbKho.SelectedItem = kho; } //AUTO NCC if (String.IsNullOrEmpty(ncc)) { cbNCC.SelectedIndex = 0; } else { cbNCC.SelectedItem = ncc; } //AUTO LOAI if (String.IsNullOrEmpty(loai)) { cbLoaiSanPham.SelectedIndex = 0; } else { cbLoaiSanPham.SelectedItem = loai; } //AUTO anh if (String.IsNullOrEmpty(anh)) { ptbAnh.Image = null; } else { ptbAnh.Image = HamChung.GetImageFromString(anh); } GetAllRow(); } }