Inheritance: System.MarshalByRefObject, ITableMapping, ICloneable
Ejemplo n.º 1
0
 public Base_HoiDapSanPham()
 {
     dtColMapping = new DataColumnMapping[]
                        {
                            new DataColumnMapping("HoiDapID", "HoiDapID")
                            ,
                            new DataColumnMapping("SanPhamID", "SanPhamID")
                            ,
                            new DataColumnMapping("NguoiDungID", "NguoiDungID")
                            ,
                            new DataColumnMapping("NguoiHoi", "NguoiHoi")
                            ,
                            new DataColumnMapping("CauHoi", "CauHoi")
                            ,
                            new DataColumnMapping("TraLoi", "TraLoi")
                            ,
                            new DataColumnMapping("NgayHoi", "NgayHoi")
                            ,
                            new DataColumnMapping("NgayTraLoi", "NgayTraLoi")
                            ,
                            new DataColumnMapping("bak", "bak")
                            ,
                            new DataColumnMapping("bak1", "bak1")
                            ,
                            new DataColumnMapping("ChiTietCauHoi", "ChiTietCauHoi")
                        };
     dtTblMapping = new DataTableMapping("Table", "HoiDapSanPham", dtColMapping);
 }
Ejemplo n.º 2
0
 public Base_DauGia()
 {
     dtColMapping = new DataColumnMapping[]
                        {
                            new DataColumnMapping("DauGiaID", "DauGiaID")
                            ,
                            new DataColumnMapping("SanPhamID", "SanPhamID")
                            ,
                            new DataColumnMapping("GiaBanNgay", "GiaBanNgay")
                            ,
                            new DataColumnMapping("GiaKhoiDiem", "GiaKhoiDiem")
                            ,
                            new DataColumnMapping("BuocGia", "BuocGia")
                            ,
                            new DataColumnMapping("BatDau", "BatDau")
                            ,
                            new DataColumnMapping("KetThuc", "KetThuc")
                            ,
                            new DataColumnMapping("TraGiaID", "TraGiaID")
                            ,
                            new DataColumnMapping("Bak1", "Bak1")
                            ,
                            new DataColumnMapping("Bak2", "Bak2")
                            ,
                            new DataColumnMapping("Bak3", "Bak3")
                            ,
                            new DataColumnMapping("Bak4", "Bak4")
                        };
     dtTblMapping = new DataTableMapping("Table", "DauGia", dtColMapping);
 }
Ejemplo n.º 3
0
 public Base_NhomSanPham()
 {
     dtColMapping = new DataColumnMapping[]
                        {
                            new DataColumnMapping("NhomSanPhamID", "NhomSanPhamID")
                            ,
                            new DataColumnMapping("TenNhomSanPham", "TenNhomSanPham")
                            ,
                            new DataColumnMapping("MoTaNhomSanPham", "MoTaNhomSanPham")
                            ,
                            new DataColumnMapping("NhomChaID", "NhomChaID")
                            ,
                            new DataColumnMapping("Show", "Show")
                            ,
                            new DataColumnMapping("SapXep", "SapXep")
                            ,
                            new DataColumnMapping("Bak1", "Bak1")
                            ,
                            new DataColumnMapping("Bak2", "Bak2")
                            ,
                            new DataColumnMapping("Bak3", "Bak3")
                            ,
                            new DataColumnMapping("Bak4", "Bak4")
                            ,
                            new DataColumnMapping("Bak5", "Bak5")
                            ,
                            new DataColumnMapping("KhuVucShow", "KhuVucShow")
                        };
     dtTblMapping = new DataTableMapping("Table", "NhomSanPham", dtColMapping);
 }
Ejemplo n.º 4
0
 public Base_QuangCao()
 {
     dtColMapping = new DataColumnMapping[]
                        {
                            new DataColumnMapping("QuangCaoID", "QuangCaoID")
                            ,
                            new DataColumnMapping("DuongDan", "DuongDan")
                            ,
                            new DataColumnMapping("NoiDungQuangCao", "NoiDungQuangCao")
                            ,
                            new DataColumnMapping("DuongDanAnh", "DuongDanAnh")
                            ,
                            new DataColumnMapping("NguoiDungID", "NguoiDungID")
                            ,
                            new DataColumnMapping("GhiChu", "GhiChu")
                            ,
                            new DataColumnMapping("LoaiAnh", "LoaiAnh")
                            ,
                            new DataColumnMapping("SapXep", "SapXep")
                            ,
                            new DataColumnMapping("Bak1", "Bak1")
                            ,
                            new DataColumnMapping("Bak2", "Bak2")
                            ,
                            new DataColumnMapping("Bak3", "Bak3")
                            ,
                            new DataColumnMapping("Bak4", "Bak4")
                        };
     dtTblMapping = new DataTableMapping("Table", "QuangCao", dtColMapping);
 }
Ejemplo n.º 5
0
 public static DataTableMapping CreateDataTableMapping(string sourceTable, string dataSetTable, DataColumnMappingCollection dataColumnMappings)
 {
     DataTableMapping dataTableMapping = new DataTableMapping(sourceTable, dataSetTable);
     foreach (DataColumnMapping dataColumnMapping in dataColumnMappings)
         dataTableMapping.ColumnMappings.Add(dataColumnMapping);
     return dataTableMapping;
 }
Ejemplo n.º 6
0
 protected override RowUpdatingEventArgs CreateRowUpdatingEvent(
 DataRow dataRow,
 IDbCommand command,
 StatementType statementType,
 DataTableMapping tableMapping)
 {
     return null;
 }
Ejemplo n.º 7
0
		public FbRowUpdatedEventArgs(
			DataRow				row, 
			IDbCommand			command, 
			StatementType		statementType, 
			DataTableMapping		tableMapping)
			: base(row, command, statementType, tableMapping) 
		{
		}
Ejemplo n.º 8
0
		protected override RowUpdatedEventArgs CreateRowUpdatedEvent(
			DataRow dataRow,
			IDbCommand command,
			StatementType statementType,
			DataTableMapping tableMapping)
		{
			return new NpgsqlRowUpdatedEventArgs(dataRow, command, statementType, tableMapping);
		}
Ejemplo n.º 9
0
		RowUpdatedEventArgs (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
		{
			this.dataRow = dataRow;
			this.command = command;
			this.statementType = statementType;
			this.tableMapping = tableMapping;
			this.status = UpdateStatus.Continue;
		}
Ejemplo n.º 10
0
		/// <summary>
		/// 获取映射表
		/// </summary>
		public DataTableMapping GetTableMapping(DataTable dt)
		{
			if (TableMapping.ColumnMappings.Count == 0 && dt.Columns.Count > 0)
			{
				TableMapping = Apq.Data.DataTable.CreateDefaultTableMapping(dt);
			}

			return TableMapping;
		}
Ejemplo n.º 11
0
		/// <summary>
		/// 生成默认映射表
		/// </summary>
		/// <param name="dt">表</param>
		/// <returns></returns>
		public static DataTableMapping CreateDefaultTableMapping(System.Data.DataTable dt)
		{
			DataTableMapping rtn = new DataTableMapping();
			rtn.SourceTable = rtn.DataSetTable = dt.TableName;
			foreach (DataColumn dc in dt.Columns)
			{
				rtn.ColumnMappings.Add(dc.ColumnName, dc.ColumnName);
			}
			return rtn;
		}
Ejemplo n.º 12
0
 public Base_DongSanPham()
 {
     dtColMapping = new DataColumnMapping[]
                        {
                            new DataColumnMapping("DongSanPhamID", "DongSanPhamID")
                            ,
                            new DataColumnMapping("TenDongSanPham", "TenDongSanPham")
                        };
     dtTblMapping = new DataTableMapping("Table", "DongSanPham", dtColMapping);
 }
		protected RowUpdatedEventArgs (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
		{
			this.dataRow = dataRow;
			this.command = command;
			this.statementType = statementType;
			this.tableMapping = tableMapping;
			this.errors = null;
			this.status = UpdateStatus.Continue;
			this.recordsAffected = 0; // FIXME
		}
		public void GetReady()
		{
			tabs=new DataTableMapping[5];
			tabs[0]=new DataTableMapping("sourceCustomers", "dataSetCustomers");
			tabs[1]=new DataTableMapping("sourceEmployees", "dataSetEmployees");
			tabs[2]=new DataTableMapping("sourceBooks", "dataSetBooks");
			tabs[3]=new DataTableMapping("sourceStore", "dataSetStore");
			tabs[4]=new DataTableMapping("sourceInventory", "dataSetInventory");
			tableMapCollection=new DataTableMappingCollection();
		}
Ejemplo n.º 15
0
 public Base_CauHinhHeThong()
 {
     dtColMapping = new DataColumnMapping[]
                        {
                            new DataColumnMapping("Khoa", "Khoa")
                            ,
                            new DataColumnMapping("NoiDung", "NoiDung")
                        };
     dtTblMapping = new DataTableMapping("Table", "CauHinhHeThong", dtColMapping);
 }
Ejemplo n.º 16
0
 public Base_LichSuTruyCap()
 {
     dtColMapping = new DataColumnMapping[]
                        {
                            new DataColumnMapping("LichSuTruyCapID", "LichSuTruyCapID")
                            ,
                            new DataColumnMapping("LuotTruyCap", "LuotTruyCap")
                            ,
                            new DataColumnMapping("CuaHangID", "CuaHangID")
                        };
     dtTblMapping = new DataTableMapping("Table", "LichSuTruyCap", dtColMapping);
 }
Ejemplo n.º 17
0
 public Base_CuaHangNhomSanPham()
 {
     dtColMapping = new DataColumnMapping[]
                        {
                            new DataColumnMapping("CuaHangNhomSanPhamID", "CuaHangNhomSanPhamID")
                            ,
                            new DataColumnMapping("CuaHangID", "CuaHangID")
                            ,
                            new DataColumnMapping("NhomSanPhamID", "NhomSanPhamID")
                        };
     dtTblMapping = new DataTableMapping("Table", "CuaHangNhomSanPham", dtColMapping);
 }
        protected override RowUpdatedEventArgs CreateRowUpdatedEvent(
            DataRow dataRow,
            IDbCommand command,
            StatementType statementType,
            DataTableMapping tableMapping
        )
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "CreateRowUpdatedEvent");
            return new NpgsqlRowUpdatedEventArgs(dataRow, command, statementType, tableMapping);



        }
Ejemplo n.º 19
0
 public Base_ThuocTinhSanPham()
 {
     dtColMapping = new DataColumnMapping[]
                        {
                            new DataColumnMapping("ThuocTinhSanPhamID", "ThuocTinhSanPhamID")
                            ,
                            new DataColumnMapping("SanPhamID", "SanPhamID")
                            ,
                            new DataColumnMapping("ThuocTinhID", "ThuocTinhID")
                            ,
                            new DataColumnMapping("SanPhamMauID", "SanPhamMauID")
                        };
     dtTblMapping = new DataTableMapping("Table", "ThuocTinhSanPham", dtColMapping);
 }
Ejemplo n.º 20
0
        public Base_LoaiCuaHang()
        {
            dtColMapping = new DataColumnMapping[]{

                new DataColumnMapping("LoaiCuaHangID","LoaiCuaHangID")
                    ,

                new DataColumnMapping("TenLoaiCuaHang","TenLoaiCuaHang")
                    ,

                new DataColumnMapping("Mota","Mota")
                    };
            dtTblMapping = new DataTableMapping("Table", "LoaiCuaHang", dtColMapping);
        }
Ejemplo n.º 21
0
 public Base_ViTriCuaHang()
 {
     dtColMapping = new DataColumnMapping[]
                        {
                            new DataColumnMapping("ViTriCuaHangID", "ViTriCuaHangID")
                            ,
                            new DataColumnMapping("CuaHangID", "CuaHangID")
                            ,
                            new DataColumnMapping("ViTriCuaHang", "ViTriCuaHang")
                            ,
                            new DataColumnMapping("NguoiDungID", "NguoiDungID")
                            ,
                            new DataColumnMapping("KhuVucID", "KhuVucID")
                        };
     dtTblMapping = new DataTableMapping("Table", "ViTriCuaHang", dtColMapping);
 }
 public RowUpdatedEventArgs(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) {
     switch(statementType) {
     case StatementType.Select:
     case StatementType.Insert:
     case StatementType.Update:
     case StatementType.Delete:
     case StatementType.Batch:
         break;
     default:
         throw ADP.InvalidStatementType(statementType);
     }
     _dataRow = dataRow;
     _command = command;
     _statementType = statementType;
     _tableMapping = tableMapping;
 }
Ejemplo n.º 23
0
 public Base_NhaCungCap()
 {
     dtColMapping = new DataColumnMapping[]
                        {
                            new DataColumnMapping("NhaCungCapID", "NhaCungCapID")
                            ,
                            new DataColumnMapping("TenNhaCungCap", "TenNhaCungCap")
                            ,
                            new DataColumnMapping("DiaChi", "DiaChi")
                            ,
                            new DataColumnMapping("SoDienThoaiDiDong", "SoDienThoaiDiDong")
                            ,
                            new DataColumnMapping("SoDienThoaiCoDinh", "SoDienThoaiCoDinh")
                        };
     dtTblMapping = new DataTableMapping("Table", "NhaCungCap", dtColMapping);
 }
Ejemplo n.º 24
0
 public Base_ViTriSanPham()
 {
     dtColMapping = new DataColumnMapping[]
                        {
                            new DataColumnMapping("ViTriSanPhamID", "ViTriSanPhamID")
                            ,
                            new DataColumnMapping("SanPhamID", "SanPhamID")
                            ,
                            new DataColumnMapping("ViTriSanPham", "ViTriSanPham")
                            ,
                            new DataColumnMapping("CuaHangID", "CuaHangID")
                            ,
                            new DataColumnMapping("KhuVucID", "KhuVucID")
                        };
     dtTblMapping = new DataTableMapping("Table", "ViTriSanPham", dtColMapping);
 }
Ejemplo n.º 25
0
 public Base_NhanXetSanPham()
 {
     dtColMapping = new DataColumnMapping[]
                        {
                            new DataColumnMapping("NhanXetID", "NhanXetID")
                            ,
                            new DataColumnMapping("SanPhamID", "SanPhamID")
                            ,
                            new DataColumnMapping("NguoiDungID", "NguoiDungID")
                            ,
                            new DataColumnMapping("NguoiNhanXet", "NguoiNhanXet")
                            ,
                            new DataColumnMapping("NoiDung", "NoiDung")
                        };
     dtTblMapping = new DataTableMapping("Table", "NhanXetSanPham", dtColMapping);
 }
Ejemplo n.º 26
0
 public Base_ThuocTinh()
 {
     dtColMapping = new DataColumnMapping[]
                        {
                            new DataColumnMapping("ThuocTinhID", "ThuocTinhID")
                            ,
                            new DataColumnMapping("NhomSanPhamID", "NhomSanPhamID")
                            ,
                            new DataColumnMapping("TenThuocTinh", "TenThuocTinh")
                            ,
                            new DataColumnMapping("ThuocTinhChaID", "ThuocTinhChaID")
                            ,
                            new DataColumnMapping("thutu", "thutu")
                        };
     dtTblMapping = new DataTableMapping("Table", "ThuocTinh", dtColMapping);
 }
 public RowUpdatedEventArgs(DataRow dataRow, IDbCommand command, System.Data.StatementType statementType, DataTableMapping tableMapping)
 {
     switch (statementType)
     {
         case System.Data.StatementType.Select:
         case System.Data.StatementType.Insert:
         case System.Data.StatementType.Update:
         case System.Data.StatementType.Delete:
         case System.Data.StatementType.Batch:
             this._dataRow = dataRow;
             this._command = command;
             this._statementType = statementType;
             this._tableMapping = tableMapping;
             return;
     }
     throw ADP.InvalidStatementType(statementType);
 }
Ejemplo n.º 28
0
 /// <summary>
 /// 获取Dataset
 /// </summary>
 /// <param name="command"></param>
 /// <param name="mapping"></param>
 /// <param name="result"></param>
 /// <returns></returns>
 public override int ExecuteDataSet(DbCommand command, DataTableMapping mapping, ref DataSet result)
 {
     int r = 0;
     SqlCommand comm = command as SqlCommand;
     comm.CommandTimeout = 3600;
     if (comm != null)
     {
         SqlDataAdapter adapter = new SqlDataAdapter(comm);
         if (mapping != null)
         {
             adapter.TableMappings.Add(mapping);
         }
         r = adapter.Fill(result);
     }
     comm.Dispose();
     return r;
 }
Ejemplo n.º 29
0
 public Base_NguoiDung()
 {
     dtColMapping = new DataColumnMapping[]
                        {
                            new DataColumnMapping("NguoiDungID", "NguoiDungID")
                            ,
                            new DataColumnMapping("HoVaTen", "HoVaTen")
                            ,
                            new DataColumnMapping("TaiKhoan", "TaiKhoan")
                            ,
                            new DataColumnMapping("MatKhau", "MatKhau")
                            ,
                            new DataColumnMapping("NgaySinh", "NgaySinh")
                            ,
                            new DataColumnMapping("GioiTinh", "GioiTinh")
                            ,
                            new DataColumnMapping("email", "email")
                            ,
                            new DataColumnMapping("MaSoKichHoat", "MaSoKichHoat")
                            ,
                            new DataColumnMapping("KichHoat", "KichHoat")
                            ,
                            new DataColumnMapping("DienThoaiDiDong", "DienThoaiDiDong")
                            ,
                            new DataColumnMapping("DienThoaiCoDinh", "DienThoaiCoDinh")
                            ,
                            new DataColumnMapping("LoaiNguoiDungID", "LoaiNguoiDungID")
                            ,
                            new DataColumnMapping("DiaChi", "DiaChi")
                            ,
                            new DataColumnMapping("YM", "YM")
                            ,
                            new DataColumnMapping("SoChungMinhThu", "SoChungMinhThu")
                            ,
                            new DataColumnMapping("SapXep", "SapXep")
                            ,
                            new DataColumnMapping("Bak1", "Bak1")
                            ,
                            new DataColumnMapping("Bak3", "Bak3")
                            ,
                            new DataColumnMapping("Bak4", "Bak4")
                            ,
                            new DataColumnMapping("Bak5", "Bak5")
                        };
     dtTblMapping = new DataTableMapping("Table", "NguoiDung", dtColMapping);
 }
Ejemplo n.º 30
0
 /// <summary>
 /// 获取Dataset
 /// </summary>
 /// <param name="command"></param>
 /// <param name="mapping"></param>
 /// <param name="result"></param>
 /// <returns></returns>
 public override int ExecuteDataSet(DbCommand command, DataTableMapping mapping, ref DataSet result)
 {
     int r = 0;
     OracleCommand comm = command as OracleCommand;
     if (comm != null)
     {
         comm.CommandText = comm.CommandText.Replace("[", "").Replace("]", "");
         OracleDataAdapter adapter = new OracleDataAdapter(comm);
         if (mapping != null)
         {
             adapter.TableMappings.Add(mapping);
         }
         r = adapter.Fill(result);
     }
     comm.Dispose();
     return r;
 }
 private void AddWithoutEvents(DataTableMapping value)
 {
     Validate(-1, value);
     value.Parent = this;
     ArrayList().Add(value);
 }
 private DataTableMapping Add(DataTableMapping value)
 {
     AddWithoutEvents(value);
     return(value);
 }
Ejemplo n.º 33
0
        protected virtual int Update(DataRow[] dataRows, DataTableMapping tableMapping)
        {
            int updateCount = 0;

            foreach (DataRow row in dataRows)
            {
                StatementType statementType = StatementType.Update;
                IDbCommand    command       = null;
                string        commandName   = String.Empty;

                switch (row.RowState)
                {
                case DataRowState.Added:
                    statementType = StatementType.Insert;
                    command       = ((IDbDataAdapter)this).InsertCommand;
                    commandName   = "Insert";
                    break;

                case DataRowState.Deleted:
                    statementType = StatementType.Delete;
                    command       = ((IDbDataAdapter)this).DeleteCommand;
                    commandName   = "Delete";
                    break;

                case DataRowState.Modified:
                    statementType = StatementType.Update;
                    command       = ((IDbDataAdapter)this).UpdateCommand;
                    commandName   = "Update";
                    break;

                case DataRowState.Unchanged:
                case DataRowState.Detached:
                    continue;
                }

                RowUpdatingEventArgs argsUpdating = CreateRowUpdatingEvent(row, command, statementType, tableMapping);
                row.RowError = null;
                OnRowUpdating(argsUpdating);
                switch (argsUpdating.Status)
                {
                case UpdateStatus.Continue:
                    //continue in update operation
                    break;

                case UpdateStatus.ErrorsOccurred:
                    if (argsUpdating.Errors == null)
                    {
                        argsUpdating.Errors = ExceptionHelper.RowUpdatedError();
                    }
                    row.RowError += argsUpdating.Errors.Message;
                    if (!ContinueUpdateOnError)
                    {
                        throw argsUpdating.Errors;
                    }
                    continue;

                case UpdateStatus.SkipAllRemainingRows:
                    return(updateCount);

                case UpdateStatus.SkipCurrentRow:
                    updateCount++;
                    continue;

                default:
                    throw ExceptionHelper.InvalidUpdateStatus(argsUpdating.Status);
                }
                command = argsUpdating.Command;
                try {
                    if (command != null)
                    {
                        DataColumnMappingCollection columnMappings = tableMapping.ColumnMappings;
                        IDataParameter nullCheckParam = null;
                        foreach (IDataParameter parameter in command.Parameters)
                        {
                            if ((parameter.Direction & ParameterDirection.Input) != 0)
                            {
                                string dsColumnName = parameter.SourceColumn;
                                if (columnMappings.Contains(parameter.SourceColumn))
                                {
                                    dsColumnName = columnMappings [parameter.SourceColumn].DataSetColumn;
                                }
                                if (dsColumnName == null || dsColumnName.Length <= 0)
                                {
                                    nullCheckParam = parameter;
                                    continue;
                                }

                                DataRowVersion rowVersion = parameter.SourceVersion;
                                // Parameter version is ignored for non-update commands
                                if (statementType == StatementType.Delete)
                                {
                                    rowVersion = DataRowVersion.Original;
                                }

                                parameter.Value = row [dsColumnName, rowVersion];
                                if (nullCheckParam != null && (parameter.Value != null &&
                                                               parameter.Value != DBNull.Value))
                                {
                                    nullCheckParam.Value = 0;
                                    nullCheckParam       = null;
                                }
                            }
                        }
                    }
                }
                catch (Exception e) {
                    argsUpdating.Errors = e;
                    argsUpdating.Status = UpdateStatus.ErrorsOccurred;
                }


                IDataReader reader = null;
                try {
                    if (command == null)
                    {
                        throw ExceptionHelper.UpdateRequiresCommand(commandName);
                    }

                    CommandBehavior commandBehavior = CommandBehavior.Default;
                    if (command.Connection.State == ConnectionState.Closed)
                    {
                        command.Connection.Open();
                        commandBehavior |= CommandBehavior.CloseConnection;
                    }

                    // use ExecuteReader because we want to use the commandbehavior parameter.
                    // so the connection will be closed if needed.
                    reader = command.ExecuteReader(commandBehavior);

                    // update the current row, if the update command returns any resultset
                    // ignore other than the first record.
                    DataColumnMappingCollection columnMappings = tableMapping.ColumnMappings;

                    if (command.UpdatedRowSource == UpdateRowSource.Both ||
                        command.UpdatedRowSource == UpdateRowSource.FirstReturnedRecord)
                    {
                        if (reader.Read())
                        {
                            DataTable retSchema = reader.GetSchemaTable();
                            foreach (DataRow dr in retSchema.Rows)
                            {
                                string columnName    = dr ["ColumnName"].ToString();
                                string dstColumnName = columnName;
                                if (columnMappings != null &&
                                    columnMappings.Contains(columnName))
                                {
                                    dstColumnName = columnMappings [dstColumnName].DataSetColumn;
                                }
                                DataColumn dstColumn = row.Table.Columns [dstColumnName];
                                if (dstColumn == null
#if NOT_PFX
                                    || (dstColumn.Expression != null &&
                                        dstColumn.Expression.Length > 0)
#endif
                                    )
                                {
                                    continue;
                                }
                                // info from : http://www.error-bank.com/microsoft.public.dotnet.framework.windowsforms.databinding/
                                // [email protected]_Thread.aspx
                                // disable readonly for non-expression columns.
                                bool readOnlyState = dstColumn.ReadOnly;
                                dstColumn.ReadOnly = false;
                                try {
                                    row [dstColumnName] = reader [columnName];
                                } finally {
                                    dstColumn.ReadOnly = readOnlyState;
                                }
                            }
                        }
                    }
                    reader.Close();

                    int tmp = reader.RecordsAffected;                     // records affected is valid only after closing reader
                    // if the execute does not effect any rows we throw an exception.
                    if (tmp == 0)
                    {
                        throw new DBConcurrencyException("Concurrency violation: the " +
                                                         commandName + "Command affected 0 records.");
                    }
                    updateCount += tmp;

                    if (command.UpdatedRowSource == UpdateRowSource.Both ||
                        command.UpdatedRowSource == UpdateRowSource.OutputParameters)
                    {
                        // Update output parameters to row values
                        foreach (IDataParameter parameter in command.Parameters)
                        {
                            if (parameter.Direction != ParameterDirection.InputOutput &&
                                parameter.Direction != ParameterDirection.Output &&
                                parameter.Direction != ParameterDirection.ReturnValue)
                            {
                                continue;
                            }

                            string dsColumnName = parameter.SourceColumn;
                            if (columnMappings != null &&
                                columnMappings.Contains(parameter.SourceColumn))
                            {
                                dsColumnName = columnMappings [parameter.SourceColumn].DataSetColumn;
                            }
                            DataColumn dstColumn = row.Table.Columns [dsColumnName];
                            if (dstColumn == null
#if NOT_PFX
                                || (dstColumn.Expression != null &&
                                    dstColumn.Expression.Length > 0)
#endif
                                )
                            {
                                continue;
                            }
                            bool readOnlyState = dstColumn.ReadOnly;
                            dstColumn.ReadOnly = false;
                            try {
                                row [dsColumnName] = parameter.Value;
                            } finally {
                                dstColumn.ReadOnly = readOnlyState;
                            }
                        }
                    }

                    RowUpdatedEventArgs updatedArgs = CreateRowUpdatedEvent(row, command, statementType, tableMapping);
                    OnRowUpdated(updatedArgs);
                    switch (updatedArgs.Status)
                    {
                    case UpdateStatus.Continue:
                        break;

                    case UpdateStatus.ErrorsOccurred:
                        if (updatedArgs.Errors == null)
                        {
                            updatedArgs.Errors = ExceptionHelper.RowUpdatedError();
                        }
                        row.RowError += updatedArgs.Errors.Message;
                        if (!ContinueUpdateOnError)
                        {
                            throw updatedArgs.Errors;
                        }
                        break;

                    case UpdateStatus.SkipCurrentRow:
                        continue;

                    case UpdateStatus.SkipAllRemainingRows:
                        return(updateCount);
                    }
#if NET_2_0
                    if (!AcceptChangesDuringUpdate)
                    {
                        continue;
                    }
#endif
                    row.AcceptChanges();
                } catch (Exception e) {
                    row.RowError = e.Message;
                    if (!ContinueUpdateOnError)
                    {
                        throw e;
                    }
                } finally {
                    if (reader != null && !reader.IsClosed)
                    {
                        reader.Close();
                    }
                }
            }
            return(updateCount);
        }
Ejemplo n.º 34
0
        public int Update(DataRow[] dataRows)
        {
            if (dataRows == null)
            {
                throw new ArgumentNullException("dataRows");
            }

            if (dataRows.Length == 0)
            {
                return(0);
            }

            if (dataRows[0] == null)
            {
                throw new ArgumentException("dataRows[0].");
            }

            DataTable table = dataRows[0].Table;

            if (table == null)
            {
                throw new ArgumentException("table is null reference.");
            }

            // all rows must be in the same table
            for (int i = 0; i < dataRows.Length; i++)
            {
                if (dataRows[i] == null)
                {
                    throw new ArgumentException("dataRows[" + i + "].");
                }
                if (dataRows[i].Table != table)
                {
                    throw new ArgumentException(
                              " DataRow["
                              + i
                              + "] is from a different DataTable than DataRow[0].");
                }
            }

            // get table mapping for this rows
            DataTableMapping tableMapping = TableMappings.GetByDataSetTable(table.TableName);

            if (tableMapping == null)
            {
                tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction(
                    TableMappings,
                    table.TableName,
                    table.TableName,
                    MissingMappingAction);
                if (tableMapping != null)
                {
                    foreach (DataColumn col in table.Columns)
                    {
                        if (tableMapping.ColumnMappings.IndexOf(col.ColumnName) >= 0)
                        {
                            continue;
                        }
                        DataColumnMapping columnMapping = DataColumnMappingCollection.GetColumnMappingBySchemaAction(tableMapping.ColumnMappings, col.ColumnName, MissingMappingAction);
                        if (columnMapping == null)
                        {
                            columnMapping = new DataColumnMapping(col.ColumnName, col.ColumnName);
                        }
                        tableMapping.ColumnMappings.Add(columnMapping);
                    }
                }
                else
                {
                    ArrayList cmc = new ArrayList();
                    foreach (DataColumn col in table.Columns)
                    {
                        cmc.Add(new DataColumnMapping(col.ColumnName, col.ColumnName));
                    }
                    tableMapping =
                        new DataTableMapping(
                            table.TableName,
                            table.TableName,
                            cmc.ToArray(typeof(DataColumnMapping)) as DataColumnMapping []);
                }
            }

            DataRow[] copy = table.NewRowArray(dataRows.Length);
            Array.Copy(dataRows, 0, copy, 0, dataRows.Length);
            return(Update(copy, tableMapping));
        }
Ejemplo n.º 35
0
 protected override System.Data.Common.RowUpdatingEventArgs CreateRowUpdatingEvent(DataRow a, IDbCommand b, StatementType c, System.Data.Common.DataTableMapping d)
 {
     return (System.Data.Common.RowUpdatingEventArgs)new EventArgs();
 }
Ejemplo n.º 36
0
        private UpdateStatus status; // UpdateStatus.Continue; /*0*/

        /// <include file='doc\RowUpdatingEvent.uex' path='docs/doc[@for="RowUpdatingEventArgs.RowUpdatingEventArgs"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Initializes a new instance of the <see cref='System.Data.Common.RowUpdatingEventArgs'/> class.
        ///    </para>
        /// </devdoc>
        protected RowUpdatingEventArgs(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
        {
            this.dataRow       = dataRow;
            this.command       = command;
            this.statementType = statementType;
            this.tableMapping  = tableMapping;
        }
Ejemplo n.º 37
0
 public void Insert(int index, DataTableMapping value)
 {
     mappings.Insert(index, value);
     sourceTables [value.SourceTable]   = value;
     dataSetTables [value.DataSetTable] = value;
 }
Ejemplo n.º 38
0
 protected virtual RowUpdatingEventArgs CreateRowUpdatingEvent(DataRow dataRow, IDbCommand command,
                                                               StatementType statementType,
                                                               DataTableMapping tableMapping)
 {
     return(new RowUpdatingEventArgs(dataRow, command, statementType, tableMapping));
 }
Ejemplo n.º 39
0
 private int Update(DataTable dataTable, DataTableMapping tableMapping)
 {
     DataRow[] rows = dataTable.NewRowArray(dataTable.Rows.Count);
     dataTable.Rows.CopyTo(rows, 0);
     return(Update(rows, tableMapping));
 }
Ejemplo n.º 40
0
        /// <summary>
        ///     Creates or Modifies the schema of the given DataTable based on the schema of
        ///     the reader and the arguments passed.
        /// </summary>
        internal static int[] BuildSchema(IDataReader reader, DataTable table,
                                          SchemaType schemaType,
                                          MissingSchemaAction missingSchAction,
                                          MissingMappingAction missingMapAction,
                                          DataTableMappingCollection dtMapping
                                          )
        {
            int readerIndex = 0;

            // FIXME : this fails if query has fewer columns than a table
            int[] mapping = new int[table.Columns.Count];             // mapping the reader indexes to the datatable indexes

            for (int i = 0; i < mapping.Length; i++)
            {
                mapping[i] = -1;
            }

            ArrayList primaryKey       = new ArrayList();
            ArrayList sourceColumns    = new ArrayList();
            bool      createPrimaryKey = true;

            DataTable schemaTable = reader.GetSchemaTable();

            DataColumn ColumnNameCol      = schemaTable.Columns["ColumnName"];
            DataColumn DataTypeCol        = schemaTable.Columns["DataType"];
            DataColumn IsAutoIncrementCol = schemaTable.Columns["IsAutoIncrement"];
            DataColumn AllowDBNullCol     = schemaTable.Columns["AllowDBNull"];
            DataColumn IsReadOnlyCol      = schemaTable.Columns["IsReadOnly"];
            DataColumn IsKeyCol           = schemaTable.Columns["IsKey"];
            DataColumn IsUniqueCol        = schemaTable.Columns["IsUnique"];
            DataColumn ColumnSizeCol      = schemaTable.Columns["ColumnSize"];

            foreach (DataRow schemaRow in schemaTable.Rows)
            {
                // generate a unique column name in the source table.
                string sourceColumnName;
                string realSourceColumnName;
                if (ColumnNameCol == null || schemaRow.IsNull(ColumnNameCol) ||
                    (string)schemaRow [ColumnNameCol] == String.Empty)
                {
                    sourceColumnName     = DefaultSourceColumnName;
                    realSourceColumnName = DefaultSourceColumnName + "1";
                }
                else
                {
                    sourceColumnName     = (string)schemaRow [ColumnNameCol];
                    realSourceColumnName = sourceColumnName;
                }

                for (int i = 1; sourceColumns.Contains(realSourceColumnName); i += 1)
                {
                    realSourceColumnName = String.Format("{0}{1}", sourceColumnName, i);
                }
                sourceColumns.Add(realSourceColumnName);

                // generate DataSetColumnName from DataTableMapping, if any
                string           dsColumnName = realSourceColumnName;
                DataTableMapping tableMapping = null;

                //FIXME : The sourcetable name shud get passed as a parameter..
                int    index    = dtMapping.IndexOfDataSetTable(table.TableName);
                string srcTable = (index != -1 ? dtMapping[index].SourceTable : table.TableName);
                tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction(dtMapping, srcTable, table.TableName, missingMapAction);
                if (tableMapping != null)
                {
                    table.TableName = tableMapping.DataSetTable;
                    // check to see if the column mapping exists
                    DataColumnMapping columnMapping = DataColumnMappingCollection.GetColumnMappingBySchemaAction(tableMapping.ColumnMappings, realSourceColumnName, missingMapAction);
                    if (columnMapping != null)
                    {
                        Type       columnType = (Type)schemaRow[DataTypeCol];
                        DataColumn col        =
                            columnMapping.GetDataColumnBySchemaAction(
                                table,
                                columnType,
                                missingSchAction);

                        if (col != null)
                        {
                            // if the column is not in the table - add it.
                            if (table.Columns.IndexOf(col) == -1)
                            {
                                if (missingSchAction == MissingSchemaAction.Add ||
                                    missingSchAction == MissingSchemaAction.AddWithKey)
                                {
                                    table.Columns.Add(col);
                                }

                                int[] tmp = new int[mapping.Length + 1];
                                Array.Copy(mapping, 0, tmp, 0, col.Ordinal);
                                Array.Copy(mapping, col.Ordinal, tmp, col.Ordinal + 1, mapping.Length - col.Ordinal);
                                mapping = tmp;
                            }

                            if (missingSchAction == MissingSchemaAction.AddWithKey)
                            {
                                object value       = (AllowDBNullCol != null) ? schemaRow[AllowDBNullCol] : null;
                                bool   allowDBNull = value is bool?(bool)value : true;

                                value = (IsKeyCol != null) ? schemaRow[IsKeyCol] : null;
                                bool isKey = value is bool?(bool)value : false;

                                value = (IsAutoIncrementCol != null) ? schemaRow[IsAutoIncrementCol] : null;
                                bool isAutoIncrement = value is bool?(bool)value : false;

                                value = (IsReadOnlyCol != null) ? schemaRow[IsReadOnlyCol] : null;
                                bool isReadOnly = value is bool?(bool)value : false;

                                value = (IsUniqueCol != null) ? schemaRow[IsUniqueCol] : null;
                                bool isUnique = value is bool?(bool)value : false;

                                col.AllowDBNull = allowDBNull;
                                // fill woth key info
                                if (isAutoIncrement && DataColumn.CanAutoIncrement(columnType))
                                {
                                    col.AutoIncrement = true;
                                    if (!allowDBNull)
                                    {
                                        col.AllowDBNull = false;
                                    }
                                }

                                if (columnType == DbTypes.TypeOfString)
                                {
                                    col.MaxLength = (ColumnSizeCol != null) ? (int)schemaRow[ColumnSizeCol] : 0;
                                }

                                if (isReadOnly)
                                {
                                    col.ReadOnly = true;
                                }

                                if (!allowDBNull && (!isReadOnly || isKey))
                                {
                                    col.AllowDBNull = false;
                                }
                                if (isUnique && !isKey && !columnType.IsArray)
                                {
                                    col.Unique = true;
                                    if (!allowDBNull)
                                    {
                                        col.AllowDBNull = false;
                                    }
                                }

                                // This might not be set by all DataProviders
                                bool isHidden = false;
                                if (schemaTable.Columns.Contains("IsHidden"))
                                {
                                    value    = schemaRow["IsHidden"];
                                    isHidden = ((value is bool) ? (bool)value : false);
                                }

                                if (isKey && !isHidden)
                                {
                                    primaryKey.Add(col);
                                    if (allowDBNull)
                                    {
                                        createPrimaryKey = false;
                                    }
                                }
                            }
                            // add the ordinal of the column as a key and the index of the column in the datareader as a value.
                            mapping[col.Ordinal] = readerIndex++;
                        }
                    }
                }
            }
            if (primaryKey.Count > 0)
            {
                DataColumn[] colKey = (DataColumn[])(primaryKey.ToArray(typeof(DataColumn)));
                if (createPrimaryKey)
                {
                    table.PrimaryKey = colKey;
                }
                else
                {
                    UniqueConstraint uConstraint = new UniqueConstraint(colKey);
                    for (int i = 0; i < table.Constraints.Count; i++)
                    {
                        if (table.Constraints[i].Equals(uConstraint))
                        {
                            uConstraint = null;
                            break;
                        }
                    }

                    if (uConstraint != null)
                    {
                        table.Constraints.Add(uConstraint);
                    }
                }
            }
            return(mapping);
        }
Ejemplo n.º 41
0
 protected abstract RowUpdatingEventArgs CreateRowUpdatingEvent(DataRow dataRow, IDbCommand command,
                                                                StatementType statementType,
                                                                DataTableMapping tableMapping);
Ejemplo n.º 42
0
        public RowUpdatedEventArgs(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
        {
            switch (statementType)
            {
            case StatementType.Select:
            case StatementType.Insert:
            case StatementType.Update:
            case StatementType.Delete:
            case StatementType.Batch:
                break;

            default:
                throw ADP.InvalidStatementType(statementType);
            }
            _dataRow       = dataRow;
            _command       = command;
            _statementType = statementType;
            _tableMapping  = tableMapping;
        }