public int AddBlankCertType(BlankCertTypeModel blankCertTypeModel)
 {
     using (conn = JBCertConnection.Instance)
     {
         string queryString = @"INSERT INTO [dbo].[tblLoai]
                                    ([Name]
                                    ,[Note]
                                    ,[IsDeleted])
                              VALUES(@Name, @Note, 0) ";
         conn.Open();
         SqlCommand sqlCommand = new SqlCommand(queryString, conn);
         sqlCommand.CommandType = CommandType.Text;
         sqlCommand.Parameters.AddWithValue("@Name", blankCertTypeModel.Name);
         sqlCommand.Parameters.AddWithValue("@Note", blankCertTypeModel.Note);
         try
         {
             int rowEffected = sqlCommand.ExecuteNonQuery();
             return(rowEffected);
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             conn.Close();
         }
     }
 }
        public List <BlankCertTypeModel> GetAll()
        {
            List <BlankCertTypeModel> blankCertTypeModels = new List <BlankCertTypeModel>();

            using (conn = JBCertConnection.Instance)
            {
                string queryString = "Select * From [dbo].[tblLoai] where [IsDeleted] = 0";
                conn.Open();
                SqlCommand sqlCommand = new SqlCommand(queryString, conn);
                sqlCommand.CommandType = CommandType.Text;
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                try
                {
                    while (sqlDataReader.Read())
                    {
                        BlankCertTypeModel blankCertTypeModel = new BlankCertTypeModel();
                        blankCertTypeModel.Id   = int.Parse(sqlDataReader["Id"].ToString());
                        blankCertTypeModel.Name = sqlDataReader["Name"].ToString();
                        blankCertTypeModel.Note = sqlDataReader["Note"].ToString();
                        blankCertTypeModels.Add(blankCertTypeModel);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    sqlDataReader.Close();
                    conn.Close();
                }
            }
            return(blankCertTypeModels);
        }
 public int UpdateBlanCertType(BlankCertTypeModel blankCertTypeModel)
 {
     using (conn = JBCertConnection.Instance)
     {
         string queryString = @"Update [dbo].[tblLoai] 
                                 Set [Name] = @Name, [Note] = @Note
                                 Where [Id] = @Id";
         conn.Open();
         SqlCommand sqlCommand = new SqlCommand(queryString, conn);
         sqlCommand.CommandType = CommandType.Text;
         sqlCommand.Parameters.AddWithValue("@Name", blankCertTypeModel.Name);
         sqlCommand.Parameters.AddWithValue("@Note", blankCertTypeModel.Note);
         sqlCommand.Parameters.AddWithValue("@Id", blankCertTypeModel.Id);
         try
         {
             int rowEffected = sqlCommand.ExecuteNonQuery();
             return(rowEffected);
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             conn.Close();
         }
     }
 }
        private void EditBlankCertTypeForm_Load(object sender, EventArgs e)
        {
            BlankCertTypeModel blankCertTypeModel = managingBlankCertTypeService.GetSingleBlankCertTypeById(_blankCertTypeId);

            BlankCertTypeTextBox.Text = blankCertTypeModel.Name;
            NoteRichTextBox.Text      = blankCertTypeModel.Note;
        }
 public int UpdateBlanCertType(BlankCertTypeModel blankCertTypeModel)
 {
     try
     {
         return(blankCertTypeRepository.UpdateBlanCertType(blankCertTypeModel));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        private void SaveButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(BlankCertTypeTextBox.Text))
            {
                MessageBox.Show("Điền tên kiểu phôi", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                NotificationForm notificationForm = new NotificationForm("Điền tên kiểu phôi", "Cảnh báo", MessageBoxIcon.Warning);
                notificationForm.ShowDialog();
                return;
            }

            try
            {
                BlankCertTypeModel blankCertTypeModel = new BlankCertTypeModel();
                blankCertTypeModel.Id   = _blankCertTypeId;
                blankCertTypeModel.Name = BlankCertTypeTextBox.Text;
                blankCertTypeModel.Note = NoteRichTextBox.Text;

                int result = managingBlankCertTypeService.UpdateBlanCertType(blankCertTypeModel);
                if (result > 0)
                {
                    OnBlankCertTypeUpdated();
                    //MessageBox.Show("Cập nhật thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    NotificationForm notificationForm = new NotificationForm("Cập nhật thành công", "Thông báo", MessageBoxIcon.Information);
                    notificationForm.ShowDialog();
                    this.Close();
                }
                else
                {
                    //MessageBox.Show("Thêm không thành công", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    NotificationForm notificationForm = new NotificationForm("Cập nhật không thành công", "Cảnh báo", MessageBoxIcon.Warning);
                    notificationForm.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                NotificationForm notificationForm = new NotificationForm(Common.Common.COMMON_ERORR, "Lỗi", MessageBoxIcon.Error);
                notificationForm.ShowDialog();
            }
        }
        public BlankCertTypeModel GetSingleBlankCertTypeById(int blankCertTypeId)
        {
            BlankCertTypeModel blankCertTypeModel = null;

            using (conn = JBCertConnection.Instance)
            {
                string queryString = "Select * From [dbo].[tblLoai] where [Id] = @Id";
                conn.Open();
                SqlCommand sqlCommand = new SqlCommand(queryString, conn);
                sqlCommand.CommandType = CommandType.Text;
                sqlCommand.Parameters.AddWithValue("@Id", blankCertTypeId);
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                try
                {
                    if (sqlDataReader.Read())
                    {
                        blankCertTypeModel           = new BlankCertTypeModel();
                        blankCertTypeModel.Id        = int.Parse(sqlDataReader["Id"].ToString());
                        blankCertTypeModel.Name      = sqlDataReader["Name"].ToString();
                        blankCertTypeModel.Note      = sqlDataReader["Note"].ToString();
                        blankCertTypeModel.IsDeleted = bool.Parse(sqlDataReader["IsDeleted"].ToString());
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    sqlDataReader.Close();
                    conn.Close();
                }
            }

            return(blankCertTypeModel);
        }