예제 #1
0
        public void luuDanhSachSanh(DataTable dt)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    foreach (DataRow dRow in dt.Rows)
                    {
                        switch (dRow.RowState)
                        {
                        case DataRowState.Added:
                            dtoDSSanh dtoDSSanh = new dtoDSSanh()
                            {
                                MA_SANH           = dRow["MA_SANH"].ToString(),
                                TENSANH           = dRow["TENSANH"].ToString(),
                                SLBANTOIDA        = dRow["SLBANTOIDA"].ToString(),
                                DONGIABANTOITHIEU = dRow["DONGIABANTOITHIEU"].ToString(),
                                GHICHU            = dRow["GHICHU"].ToString()
                            };
                            dalDSSanh.themDanhSachSanh(dtoDSSanh);
                            break;

                        case DataRowState.Modified:
                            dtoDSSanh dtoDSSanh1 = new dtoDSSanh()
                            {
                                MA_SANH           = dRow["MA_SANH"].ToString(),
                                TENSANH           = dRow["TENSANH"].ToString(),
                                SLBANTOIDA        = dRow["SLBANTOIDA"].ToString(),
                                DONGIABANTOITHIEU = dRow["DONGIABANTOITHIEU"].ToString(),
                                GHICHU            = dRow["GHICHU"].ToString()
                            };
                            dalDSSanh.suaDanhSachSanh(dtoDSSanh1);
                            break;

                        case DataRowState.Deleted:
                            string MA_SANH = dRow["MA_SANH", DataRowVersion.Original].ToString();
                            dalDSSanh.xoaSanh(MA_SANH);
                            break;
                        }
                    }
                    dt.AcceptChanges();
                    scope.Complete();
                }
            }
            catch (ArgumentException ex)
            {
                throw ex;
            }
            catch (TransactionAbortedException)
            {
                throw new ArgumentException(Constants.MsgExceptionLuuLoi);
            }
            catch (ApplicationException)
            {
                throw new ArgumentException(Constants.MsgExceptionLoiChung);
            }
        }
예제 #2
0
 public int themDanhSachSanh(dtoDSSanh dtoDSSanh)
 {
     try
     {
         SqlParameter[] parameters =
         {
             new SqlParameter("@MA_SANH",           dtoDSSanh.MA_SANH),
             new SqlParameter("@TENSANH",           dtoDSSanh.TENSANH),
             new SqlParameter("@SLBANTOIDA",        dtoDSSanh.SLBANTOIDA),
             new SqlParameter("@DONGIABANTOITHIEU", dtoDSSanh.DONGIABANTOITHIEU),
             new SqlParameter("@GHICHU",            dtoDSSanh.GHICHU)
         };
         return(Convert.ToInt32(SqlHelper.ExecuteNonQuery(Constants.ConnectionString, "themDanhSachSanh", parameters)));
     }
     catch (SqlException)
     {
         throw new ArgumentException(Constants.MsgExceptionTonTaiMauTin);
     }
     catch (Exception)
     {
         throw new ArgumentException(Constants.MsgExceptionTruyCapLoi);
     }
 }