コード例 #1
0
 public bool UpdateRow(PhieuNhapSachDTO obj)
 {
     try
     {
         if (_connection.State != ConnectionState.Open)
         {
             _connection.Open();
         }
         string sql = "UPDATE [dbo].[PhieuNhapSach]\n"
                      + "   SET [NgayNhap] = @NgayNhap\n"
                      + "      ,[MaNhanVien] = @MaNhanVien\n"
                      + " WHERE [MaPhieuNhapSach] = @MaPhieuNhapSach";
         var cmd = new SqlCommand(sql, _connection);
         cmd.Parameters.Add("@MaPhieuNhapSach", SqlDbType.Char).Value = obj.MaPhieuNhapSach;
         cmd.Parameters.Add("@NgayNhap", SqlDbType.Date).Value        = obj.NgayNhap;
         cmd.Parameters.Add("@MaNhanVien", SqlDbType.Char).Value      = obj.MaNhanVien;
         cmd.ExecuteNonQuery();
         _connection.Close();
         return(true);
     }
     catch (Exception ex)
     {
         _connection.Close();
         Console.WriteLine(ex.Message);
     }
     return(false);
 }
コード例 #2
0
        public PhieuNhapSachDTO GetRow(string maPhieuNhapSach)
        {
            try
            {
                var obj = new PhieuNhapSachDTO();
                if (_connection.State != ConnectionState.Open)
                {
                    _connection.Open();
                }

                SqlCommand command = new SqlCommand("SELECT * FROM PhieuNhapSach WHERE MaPhieuNhapSach = @maphieunhapsach", _connection);
                command.Parameters.Add("@maphieunhapsach", SqlDbType.Char).Value = maPhieuNhapSach;

                SqlDataReader reader = command.ExecuteReader();
                if (reader.Read())
                {
                    obj.MaPhieuNhapSach = reader["MaPhieuNhapSach"].ToString();
                    obj.MaNhanVien      = reader["MaNhanVien"].ToString();
                    obj.NgayNhap        = (DateTime)reader["NgayNhap"];
                    reader.Close();
                }
                return(obj);
            }
            catch (Exception ex)
            {
                _connection.Close();
                Console.WriteLine(ex.Message);
            }
            return(null);
        }
コード例 #3
0
        private void btnXoaPhieu_Click(object sender, EventArgs e)
        {
            int currentRowIndex = this.dgvDanhSachPhieuNhap.CurrentCellAddress.Y; //'current row selected

            //Verify that indexing OK
            if (-1 < currentRowIndex && currentRowIndex < dgvDanhSachPhieuNhap.RowCount)
            {
                PhieuNhapSachDTO obj = (PhieuNhapSachDTO)dgvDanhSachPhieuNhap.Rows[currentRowIndex].DataBoundItem;
                this.txtMaPhieuNhap.Text = obj.MaPN;
                this.dtpNgayNhap.Text    = obj.NgayNhap;
                string result = this.bus.delete(obj);
                if (result == "0")
                {
                    MessageBox.Show("Xóa phiếu nhập thành công", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    this.buildDanhSach();
                    return;
                }
                else
                {
                    MessageBox.Show("Xóa phiếu nhập thất bại.\n" + result, "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show("Chưa chọn phiếu nhập trên lưới.", "THÔNG BÁO", MessageBoxButtons.OK);
            }
        }
コード例 #4
0
 public bool AddRow(PhieuNhapSachDTO obj)
 {
     try
     {
         if (_connection.State != ConnectionState.Open)
         {
             _connection.Open();
         }
         string sql = "INSERT INTO [dbo].[PhieuNhapSach]\n"
                      + "           ([MaPhieuNhapSach]\n"
                      + "           ,[NgayNhap]\n"
                      + "           ,[MaNhanVien])\n"
                      + "     VALUES\n"
                      + "           (@MaPhieuNhapSach\n"
                      + "           ,@NgayNhap\n"
                      + "           ,@MaNhanVien)";
         SqlCommand cmd = new SqlCommand(sql, _connection);
         cmd.Parameters.Add("@MaPhieuNhapSach", SqlDbType.Char).Value = obj.MaPhieuNhapSach;
         cmd.Parameters.Add("@NgayNhap", SqlDbType.Date).Value        = obj.NgayNhap;
         cmd.Parameters.Add("@MaNhanVien", SqlDbType.Char).Value      = obj.MaNhanVien;
         cmd.ExecuteNonQuery();
         _connection.Close();
         return(true);
     }
     catch (Exception ex)
     {
         _connection.Close();
         Console.WriteLine(ex.Message);
     }
     return(false);
 }
コード例 #5
0
        public string delete(PhieuNhapSachDTO obj)
        {
            string query = string.Empty;

            query += " DELETE FROM [PHIEUNHAP] ";
            query += " WHERE ";
            query += " [MaPhieuNhap] = @MaPhieuNhap ";

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand comm = new SqlCommand())
                {
                    comm.Connection  = conn;
                    comm.CommandType = CommandType.Text;
                    comm.CommandText = query;
                    comm.Parameters.AddWithValue("@MaPhieuNhap", obj.MaPN);
                    try
                    {
                        conn.Open();
                        comm.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        conn.Close();
                        //' xóa that bai!!!
                        return("Xóa phiếu nhập thất bại\n" + ex.Message + "\n" + ex.StackTrace);
                    }
                }
            }
            return("0");
        }
コード例 #6
0
        public string insert(PhieuNhapSachDTO obj)
        {
            string query = string.Empty;

            query += "INSERT INTO [PHIEUNHAP] ([MaPhieuNhap], [NgayNhap])";
            query += "VALUES (@MaPhieuNhap,@NgayNhap)";

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand comm = new SqlCommand())
                {
                    comm.Connection  = conn;
                    comm.CommandType = CommandType.Text;
                    comm.CommandText = query;
                    comm.Parameters.AddWithValue("@MaPhieuNhap", obj.MaPN);
                    comm.Parameters.AddWithValue("@NgayNhap", obj.NgayNhap);
                    try
                    {
                        conn.Open();
                        comm.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        conn.Close();
                        // them that bai!!!
                        return("Thêm ngày nhập phiếu thất bại\n" + ex.Message + "\n" + ex.StackTrace);
                    }
                }
            }
            return("0");
        }
コード例 #7
0
 public IActionResult Post([FromBody] PhieuNhapSachDTO value)
 {
     if ((_dataRepository as PhieuNhapSachDM).CheckExist(value.MaPn))
     {
         return(Conflict());
     }
     (_dataRepository as PhieuNhapSachDM).Add(value);
     return(Ok());
 }
コード例 #8
0
        public string insert(PhieuNhapSachDTO obj)
        {
            if (obj.NgayNhap == null || obj.MaPN == string.Empty)
            {
                return("Ngày nhập hoặc mã phiếu nhập không hợp lệ");
            }

            return(dal.insert(obj));
        }
コード例 #9
0
 public bool AddPhieuNhap(PhieuNhapSachDTO pn)
 {
     if (!objPhieuNhap.IsRowExists(pn.MaPhieuNhapSach))
     {
         return(objPhieuNhap.AddRow(pn));
     }
     else
     {
         return(UpdatePhieuNhap(pn));
     }
 }
コード例 #10
0
        private void btnNhapChiTiet_Click(object sender, EventArgs e)
        {
            int currentRowIndex = this.dgvDanhSachPhieuNhap.CurrentCellAddress.Y; //'current row selected

            //Verify that indexing OK
            if (-1 < currentRowIndex && currentRowIndex < dgvDanhSachPhieuNhap.RowCount)
            {
                PhieuNhapSachDTO obj = (PhieuNhapSachDTO)dgvDanhSachPhieuNhap.Rows[currentRowIndex].DataBoundItem;
                this.txtMaPN.Text = obj.MaPN;
                //this.isThemMoi = 1;
                this.tcPhieuNhapSach.SelectedIndex = 1;
            }
            else
            {
                MessageBox.Show("Chưa chọn phiếu nhập trên lưới.", "THÔNG BÁO", MessageBoxButtons.OK);
            }
        }
コード例 #11
0
 public bool UpdatePhieuNhap(PhieuNhapSachDTO pn)
 {
     if (objPhieuNhap.IsRowExists(pn.MaPhieuNhapSach))
     {
         ChiTietPhieuNhapSachBus ctb = new ChiTietPhieuNhapSachBus();
         foreach (string ct in ctb.GetMaCTPNList(pn.MaPhieuNhapSach))
         {
             if (ctb.DeleteChiTietPN(ct))
             {
                 Console.WriteLine("Delete: {0}", ct);
             }
         }
         return(objPhieuNhap.UpdateRow(pn));
     }
     else
     {
         return(false);
     }
 }
コード例 #12
0
        private void btnLapPhieu_Click(object sender, EventArgs e)
        {
            PhieuNhapSachDTO obj = new PhieuNhapSachDTO();

            obj.MaPN = this.txtMaPhieuNhap.Text;
            //obj.NgayNhap = this.dtpNgayNhap.Text; //xem cách get ngày nhập trong c# .net nha bây
            obj.NgayNhap = this.dtpNgayNhap.Text;
            string result = this.bus.insert(obj);

            if (result == "0")
            {
                MessageBox.Show("Thêm mới phiếu nhập thành công", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            else
            {
                MessageBox.Show("Thêm mới phiếu nhập thất bại.\n" + result, "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
コード例 #13
0
        public string selectAll(List <PhieuNhapSachDTO> lsObj)
        {
            string query = string.Empty;

            query += " SELECT [MaPhieuNhap], [NgayNhap]";
            query += " FROM [PHIEUNHAP]";

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand comm = new SqlCommand())
                {
                    comm.Connection  = conn;
                    comm.CommandType = CommandType.Text;
                    comm.CommandText = query;

                    try
                    {
                        conn.Open();
                        SqlDataReader reader = comm.ExecuteReader();
                        if (reader.HasRows == true)
                        {
                            lsObj.Clear();
                            while (reader.Read())
                            {
                                PhieuNhapSachDTO obj = new PhieuNhapSachDTO();
                                obj.MaPN     = reader["MaPhieuNhap"].ToString();
                                obj.NgayNhap = reader["NgayNhap"].ToString();
                                lsObj.Add(obj);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        conn.Close();
                        //' lấy that bai!!!
                        return("Lấy phiếu nhập thất bại\n" + ex.Message + "\n" + ex.StackTrace);
                    }
                }
            }
            return("0");
        }
コード例 #14
0
 /*public string update(PhieuNhapSachDTO obj)
  * {
  *  return dal.update(obj);
  * }*/
 public string delete(PhieuNhapSachDTO obj)
 {
     return(dal.delete(obj));
 }