Пример #1
0
        private void button3_Borrow_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(textBox2_IDEmployee.Text))
            {
                MessageBox.Show("Xin hãy nhập mã nhân viên thực hiện giao dịch!");
                return;
            }

            SQL.Query.CommandText = "select MaNhanVien from NhanVien where MaNhanVien = N'" + textBox2_IDEmployee.Text + "'";
            object q = SQL.Query.ExecuteScalar();

            SQL.Query.CommandText = "select SoCMND from NguoiDung where SoCMND = N'" + sSoCMND + "'";
            object c = SQL.Query.ExecuteScalar();

            if (c == null)
            {
                MessageBox.Show("Nhân viên không thể thực hiện mượn sách!\n\nXin hãy tạo tài khoản dành cho người dùng để có thể mượn sách!");
                return;
            }
            if (q != null)
            {
                string sErrorMessage = "Thông báo:\n\n";
                SQL.Struct.MuonSach tt;

                if (string.IsNullOrWhiteSpace(sSoCMND))
                {
                    sErrorMessage += "\n- Bạn chưa cập nhật số CMND để có thể mượn sách!\nHãy cập nhật số CMND trước khi mượn!";
                }
                else
                {
                    for (int i = 0; i < lListBorrow.Count && dataGridView2_ListBorrow.Rows.Count > 0; i = 0)
                    {
                        tt            = new SQL.Struct.MuonSach();
                        tt.MaSach     = lListBorrow[i];
                        tt.NgayMuon   = DateTime.Now;
                        tt.SoCMND     = sSoCMND;
                        tt.MaNhanVien = textBox2_IDEmployee.Text;

                        if (SQL.ListData.GetDataFromSQL.MuonSach_CreateNewRecord(tt))
                        {
                            sErrorMessage += "\n- " + lListBorrow[i] + " đã được chuyển đến nhân viên thành công!";
                        }
                        else
                        {
                            sErrorMessage += "\n- Không thể thực hiện mượn " + lListBorrow[i] + "!";
                        }

                        lListBorrow.RemoveAt(0);
                        dataGridView2_ListBorrow.Rows.RemoveAt(0);
                    }
                }

                MessageBox.Show(sErrorMessage);
            }
            else
            {
                MessageBox.Show("\n- Không tồn tại mã nhân viên, xin hãy kiểm tra lại!");
                return;
            }
        }
Пример #2
0
        public static bool MuonSach_CreateNewRecord(SQL.Struct.MuonSach _value)
        {
            try
            {
                string t1 = "insert into MuonSach (MaSach, NgayMuon";
                string t2 = "(N'" + _value.MaSach + "', N'" + _value.NgayMuon.ToShortDateString() + "'";

                _value.NgayTra   = _value.NgayMuon.AddDays(150);
                _value.TinhTrang = false;

                t1 += ", NgayTra, TinhTrang";
                t2 += ", N'" + _value.NgayTra.ToShortDateString() + "', N'False'";

                if (_value.SoCMND != null)
                {
                    t1 += ", SoCMND";
                    t2 += ", N'" + _value.SoCMND + "'";
                }
                if (_value.MaNhanVien != null)
                {
                    t1 += ", MaNhanVien";
                    t2 += ", N'" + _value.MaNhanVien + "'";
                }
                t1 += ") values " + t2 + ")";

                commandSQL.CommandText = t1;
                commandSQL.Connection  = connSQL;
                connSQL.Open();
                commandSQL.ExecuteNonQuery();
                connSQL.Close();
                return(true);
            }
            catch
            {
                connSQL.Close();
                return(false);
            }
        }