private void btnSave_Click(object sender, EventArgs e) { try { txtID.Text = txtID.Text.ToUpper(); if (ValidData()) switch (vAction) { case action.Insert: var obj = new LObjectType(); obj.SName = Utility.sDbnull(txtName.Text); obj.SDesc = Utility.sDbnull(txtDesc.Text); obj.IsNew = true; obj.Save(); drList = dtList.NewRow(); drList[LObjectType.Columns.Id] = LObjectType.CreateQuery().GetMax(LObjectType.Columns.Id); ApplyData2Datarow(); dtList.Rows.InsertAt(drList, 0); dtList.AcceptChanges(); txtID.Text = Utility.sDbnull(drList[LObjectType.Columns.Id]); vAction = action.Update; break; case action.Update: new Update(LObjectType.Schema.Name).Set(LObjectType.Columns.SName).EqualTo(txtName.Text). Set(LObjectType.Columns.SDesc).EqualTo(txtDesc.Text). Where(LObjectType.Columns.Id).IsEqualTo(Utility.Int32Dbnull(txtID.Text)). Execute(); ApplyData2Datarow(); drList.AcceptChanges(); break; } } catch (Exception ex) { Utility.ShowMsg(ex.Message); } }
/// <summary> /// Applies the rule /// </summary> public override void ApplyRule(DataRow row) { // This method seems inefficient, but it's necessary to handle it in this manner so that the order of // variable assignments is maintained across different types of created variables. bool assigned = false; row.AcceptChanges(); foreach (DataRowView assignRowView in dvAssign) { DataRow assignRow = assignRowView.Row; if (assignRow == row) { assignRow[destinationColumnName] = assignValue; assigned = true; break; } } if (elseValue != null && !assigned) { row[destinationColumnName] = elseValue; } }
private void cmdSave_Click(object sender, EventArgs e) { try { txtID.Text = txtID.Text.ToUpper(); if (ValidData()) switch (vAction) { case action.Insert: var obj = new DDataControl(); obj.DataName = ""; obj.DeviceId = Utility.Int32Dbnull(cboDevice.SelectedValue, -1); obj.DataTypeId = 0; obj.ControlType = true; obj.AliasName = Utility.sDbnull(txtAlias.Text); obj.Description = Utility.sDbnull(txtDesc.Text); obj.IsNew = true; obj.Save(); drData = dtDataControl.NewRow(); drData[DDataControl.Columns.DataControlId] = DDataControl.CreateQuery().WHERE(DDataControl.Columns.DeviceId,Utility.Int32Dbnull(cboDevice.SelectedValue, -1)). WHERE(DDataControl.Columns.AliasName, txtAlias.Text).GetMax(DDataControl.Columns.DataControlId); txtID.Text = drData[DDataControl.Columns.DataControlId].ToString(); ApplyData2Datarow(); dtDataControl.Rows.InsertAt(drData, 0); dtDataControl.AcceptChanges(); vAction=action.Update; break; case action.Update: new Update(DDataControl.Schema.Name).Set(DDataControl.Columns.AliasName).EqualTo(txtAlias.Text). Set(DDataControl.Columns.Description).EqualTo(txtDesc.Text). Set(DDataControl.Columns.DeviceId).EqualTo(Utility.Int32Dbnull(cboDevice.SelectedValue,-1)). Where(DDataControl.Columns.DataControlId).IsEqualTo(Utility.Int32Dbnull(txtID.Text,-1)).Execute(); ApplyData2Datarow(); drData.AcceptChanges(); break; } } catch (Exception ex) { Utility.ShowMsg(ex.Message); } }
public void newRow(DataRow r) { int isHuge = Convert.ToInt32(r["is_huge"]); int air = Convert.ToInt32(r["appears_in_radar"]); int type = int.Parse(r["type"].ToString()); String name = r["name"].ToString().Replace("'", "''"); Console.Out.WriteLine(r["sound_effect_id"].ToString()); String sectorObQuery = "INSERT INTO sector_objects SET base_asset_id='" + r["base_asset_id"].ToString() + "', " + "h='" + r["h"].ToString() + "', s='" + r["s"].ToString() + "' ,v='" + r["v"].ToString() + "', " + "type='" + r["type"].ToString() + "', scale='" + r["scale"].ToString() + "', position_x='" + r["position_x"].ToString() + "', " + "position_y='" + r["position_y"].ToString() + "', position_z='" + r["position_z"].ToString() + "', " + "orientation_u='" + r["orientation_u"].ToString() + "', orientation_v='" + r["orientation_v"].ToString() + "', " + "orientation_w='" + r["orientation_w"].ToString() + "', orientation_z='" + r["orientation_z"].ToString() + "', " + "name='" + name + "', appears_in_radar='" + air + "', sector_id='"+r["sector_id"].ToString()+"', " + "radar_range='" + r["radar_range"].ToString() + "', gate_to='" + r["gate_to"].ToString() + "', "+ "sound_effect_id='" + r["sound_effect_id"].ToString() + "', sound_effect_range='" + r["sound_effect_range"].ToString() + "';"; int lastInsertID = 0; try { Database.executeQuery(Database.DatabaseName.net7, sectorObQuery); DataTable tmp = Database.executeQuery(Database.DatabaseName.net7, "SELECT LAST_INSERT_ID()"); foreach (DataRow z in tmp.Rows) { lastInsertID = int.Parse(z["LAST_INSERT_ID()"].ToString()); } } catch (Exception) { throw; } String navPointQuery = "INSERT INTO sector_nav_points SET sector_object_id='" + lastInsertID + "', nav_type='" + r["nav_type"].ToString() + "', " + "signature='" + r["signature"].ToString() + "', is_huge='" + isHuge + "', sector_id='" + r["sector_id"].ToString() + "', " + "base_xp='" + r["base_xp"].ToString() + "', exploration_range='" + r["exploration_range"].ToString() + "';"; try { Database.executeQuery(Database.DatabaseName.net7, navPointQuery); String specialQuery = ""; switch (type) { case 0: int delayed_spawn = Convert.ToInt32(r["delayed_spawn"]); specialQuery = "INSERT INTO sector_objects_mob SET mob_id='" + lastInsertID + "', " + "mob_count='" + r["mob_count"].ToString() + "', " + "mob_spawn_radius='" + r["mob_spawn_radius"].ToString() + "', " + "respawn_time='" + r["respawn_time"].ToString() + "', " + "delayed_spawn='" + delayed_spawn + "';"; break; case 3: int isLandable = Convert.ToInt32(r["is_landable"]); specialQuery = "INSERT INTO sector_objects_planets SET planet_id='" + lastInsertID + "', orbit_id='" + r["orbit_id"].ToString() + "', orbit_dist='" + r["orbit_dist"].ToString() + "', " + "orbit_angle='" + r["orbit_angle"].ToString() + "', orbit_rate='" + r["orbit_rate"].ToString() + "', rotate_angle='" + r["rotate_angle"].ToString() + "', " + "rotate_rate='" + r["rotate_rate"].ToString() + "', tilt_angle='" + r["tilt_angle"].ToString() + "', is_landable='" + isLandable + "';"; break; case 11: //stargate int isClassSpecific = Convert.ToInt32(r["classSpecific"]); specialQuery = "INSERT INTO sector_objects_stargates SET stargate_id='" + lastInsertID + "', classSpecific='" + isClassSpecific + "', " + "faction_id='" + r["faction_id"].ToString() + "';"; break; case 12: //starbase int isCapShip = Convert.ToInt32(r["capShip"]); int isDockable = Convert.ToInt32(r["dockable"]); specialQuery = "INSERT INTO sector_objects_starbases SET starbase_id='" + lastInsertID + "', capShip='" + isCapShip + "', " + "dockable='" + isDockable + "';"; break; case 38: specialQuery = "INSERT INTO sector_objects_harvestable SET resource_id='" + lastInsertID + "', level='" + r["level"].ToString() + "', " + "field='" + r["field"].ToString() + "', res_count='" + r["res_count"].ToString() + "', " + "spawn_radius='" + r["spawn_radius"].ToString() + "', pop_rock_chance='" + r["pop_rock_chance"].ToString() + "', " + "max_field_radius='" + r["max_field_radius"].ToString() + "';"; break; } if (type != 37) { Database.executeQuery(Database.DatabaseName.net7, specialQuery); } r["sector_object_id"] = lastInsertID; r.AcceptChanges(); } catch (Exception) { throw; } }
protected void ConvertNullToEmptyString(DataRow Row) { bool bUnChanged = Row.RowState == DataRowState.Unchanged; DataTable Tbl = Row.Table; for(int I=0;I<Tbl.Columns.Count;I++) { if(Tbl.Columns[I].DataType == typeof(string) && Row[I] is DBNull) { Row[I] = ""; } } if(bUnChanged) Row.AcceptChanges(); }
private void UpdateLocalSummaryData(DataRow row, string AFieldName, string ADataValue) { try { //DataRow row = gridViewSummary.GetDataRow(ARowHandle); row.BeginEdit(); row[AFieldName] = ADataValue; row.AcceptChanges(); row.EndEdit(); } catch (Exception ex) { throw new Exception("An error occurred while attempting to update the: " + AFieldName + " field" + Environment.NewLine + "of the local Summary Grid with a data value of: " + ADataValue + "." + Environment.NewLine + "Error CNF-067 in " + FORM_NAME + ".UpdateLocalSummaryData(): " + ex.Message); } }
public void InsertRow(DataRow row) { List<string> columns = new List<string>(); List<object> values = new List<object>(); List<SqlExpr> where = new List<SqlExpr>(); var _columns = TableName.GetTableSchema().Columns; foreach (DataColumn column in table.Columns) { object value = row[column]; string name = column.ColumnName; IColumn _column = _columns[column.ColumnName]; if (column == colRowID) continue; if (value != DBNull.Value) { columns.Add(name); values.Add(value); where.Add(name.Equal(value)); } else if (!_column.Nullable) //add default value to COLUMN NOT NULL { Type type = _column.CType.ToType(); value = GetDefault(type); columns.Add(name); values.Add(value); where.Add(name.Equal(value)); } } var builder = new SqlBuilder().INSERT(TableName, columns.ToArray()).VALUES(values.ToArray()); new SqlCmd(builder).ExecuteNonQuery(); builder = new SqlBuilder().SELECT.COLUMNS(SqlExpr.PHYSLOC).FROM(TableName).WHERE(where.AND()); var loc = new SqlCmd(builder).FillObject<byte[]>(); LOC.Add(loc); row[colRowID] = table.Rows.Count - 1; //this will trigger events ColumnChanged or RowChanged row.AcceptChanges(); }
/// <summary> /// Copy giá trị từ Datarow nguồn chứa dữ liệu SourceRow sang Datarow đích DesTable. /// </summary> /// <param name="SourceRow">Datarow nguồn chứa dữ liệu</param> /// <param name="DesRow">Datarow đích nơi dữ liệu được chép sang</param> public static void CopyData(DataRow SourceRow, ref DataRow DesRow) { try { if (SourceRow == null || DesRow == null) { Utility.ShowMsg("Bạn chưa khởi tạo Datarow nguồn và Datarow đích! Một trong 2 Datarow này đang có giá trị null."); } foreach (DataColumn col in SourceRow.Table.Columns) { if (DesRow.Table.Columns.Contains(col.ColumnName) && DesRow.Table.Columns[col.ColumnName].GetType().Equals(SourceRow.Table.Columns[col.ColumnName].GetType())) DesRow[col.ColumnName] = SourceRow[col.ColumnName]; } DesRow.AcceptChanges(); } catch { } }
/// <summary> /// Returns a <see cref="T:System.Data.DataTable"/> that describes the column metadata of the <see cref="T:System.Data.IDataReader"/>. /// </summary> /// <returns> /// A <see cref="T:System.Data.DataTable"/> that describes the column metadata. /// </returns> /// <exception cref="T:System.InvalidOperationException">The <see cref="T:System.Data.IDataReader"/> is closed. </exception> public virtual System.Data.DataTable GetSchemaTable() { System.Data.DataTable schemaTable = new System.Data.DataTable(); schemaTable.Columns.Add("ColumnName", typeof(String)); schemaTable.Columns.Add("ColumnOrdinal", typeof(Int32)); schemaTable.Columns.Add("ColumnSize", typeof(Int32)); schemaTable.Columns.Add("NumericPrecision", typeof(Int32)); schemaTable.Columns.Add("NumericScale", typeof(Int32)); schemaTable.Columns.Add("IsUnique", typeof(Boolean)); schemaTable.Columns.Add("IsKey", typeof(Boolean)); schemaTable.Columns.Add("BaseCatalogName", typeof(String)); schemaTable.Columns.Add("BaseColumnName", typeof(String)); schemaTable.Columns.Add("BaseSchemaName", typeof(String)); schemaTable.Columns.Add("BaseTableName", typeof(String)); schemaTable.Columns.Add("DataType", typeof(Type)); schemaTable.Columns.Add("AllowDBNull", typeof(Boolean)); schemaTable.Columns.Add("ProviderType", typeof(Int32)); schemaTable.Columns.Add("IsAliased", typeof(Boolean)); schemaTable.Columns.Add("IsExpression", typeof(Boolean)); schemaTable.Columns.Add("IsIdentity", typeof(Boolean)); schemaTable.Columns.Add("IsAutoIncrement", typeof(Boolean)); schemaTable.Columns.Add("IsRowVersion", typeof(Boolean)); schemaTable.Columns.Add("IsHidden", typeof(Boolean)); schemaTable.Columns.Add("IsLong", typeof(Boolean)); schemaTable.Columns.Add("IsReadOnly", typeof(Boolean)); schemaTable.BeginLoadData(); for (int i = 0; i < this.FieldCount; i++) { System.Data.DataRow schemaRow = schemaTable.NewRow(); schemaRow["ColumnName"] = GetName(i); schemaRow["ColumnOrdinal"] = i; schemaRow["ColumnSize"] = -1; schemaRow["NumericPrecision"] = 0; schemaRow["NumericScale"] = 0; schemaRow["IsUnique"] = false; schemaRow["IsKey"] = false; schemaRow["BaseCatalogName"] = ""; schemaRow["BaseColumnName"] = GetName(i); schemaRow["BaseSchemaName"] = ""; schemaRow["BaseTableName"] = ""; schemaRow["DataType"] = GetFieldType(i); schemaRow["AllowDBNull"] = true; schemaRow["ProviderType"] = 0; schemaRow["IsAliased"] = false; schemaRow["IsExpression"] = false; schemaRow["IsIdentity"] = false; schemaRow["IsAutoIncrement"] = false; schemaRow["IsRowVersion"] = false; schemaRow["IsHidden"] = false; schemaRow["IsLong"] = false; schemaRow["IsReadOnly"] = false; schemaTable.Rows.Add(schemaRow); schemaRow.AcceptChanges(); } schemaTable.EndLoadData(); return(schemaTable); }
/// <summary> /// 由资料行的FileType(文件类型)字段创建图标 /// </summary> /// <param name="sourceRow">资料行</param> /// <param name="large">返回的大图标</param> /// <param name="small">返回的小图标</param> /// <param name="writeRow"></param> public static void CreateFileIcon(DataRow sourceRow, out Icon large, out Icon small, bool writeRow) { string fileType = sourceRow[tb_sys_AttachFile.FFileType].ToString(); CreateFileIcon(fileType, out large, out small); if (writeRow) { DataRowState state = sourceRow.RowState; MemoryStream ms1 = new MemoryStream(); large.ToBitmap().Save(ms1, ImageFormat.Bmp); //sourceRow[tb_sys_AttachF] = ms1.ToArray(); ms1.Close(); MemoryStream ms2 = new MemoryStream(); small.ToBitmap().Save(ms2, ImageFormat.Bmp); sourceRow[tb_sys_AttachFile.IconSmall] = ms2.ToArray(); ms2.Close(); if (state == DataRowState.Unchanged) sourceRow.AcceptChanges(); } }
public static bool UpdateDbRow(string dbPath, DataRow row) { using (var connection = GetConnection(dbPath)) { try { CheckOpenConnection(connection); var command = GetUpdateCommand(row, connection); command.ExecuteNonQuery(); row.AcceptChanges(); return true; } catch (OleDbException ex) { Debug.WriteLine(ex.Message); throw; } } }
private void btnSave_Click(object sender, EventArgs e) { try { txtID.Text = txtID.Text.ToUpper(); if (ValidData()) switch (vAction) { case action.Insert: var obj = new DDeviceList(); obj.DeviceName = Utility.sDbnull(txtName.Text); obj.TestTypeId = Utility.Int32Dbnull(cboTestType.SelectedValue); obj.ManufactureId = Utility.ByteDbnull(cboManufacturer.SelectedValue); obj.Description = Utility.sDbnull(txtDesc.Text); obj.Valid = ckbValid.Checked; obj.IsNew = true; obj.Save(); drList = dtList.NewRow(); drList[DDeviceList.Columns.DeviceId] = DDeviceList.CreateQuery().GetMax(DDeviceList.Columns.DeviceId); ApplyData2Datarow(); dtList.Rows.InsertAt(drList, 0); dtList.AcceptChanges(); txtID.Text = Utility.sDbnull(drList[DDeviceList.Columns.DeviceId]); vAction = action.Update; break; case action.Update: new Update(DDeviceList.Schema.Name).Set(DDeviceList.Columns.DeviceName).EqualTo(txtName.Text). Set(DDeviceList.Columns.TestTypeId).EqualTo(Utility.Int32Dbnull(cboTestType.SelectedValue)). Set(DDeviceList.Columns.ManufactureId).EqualTo(Utility.Int32Dbnull(cboManufacturer.SelectedValue)). Set(DDeviceList.Columns.Description).EqualTo(txtDesc.Text). Set(DDeviceList.Columns.Valid).EqualTo(ckbValid.Checked). Where(DDeviceList.Columns.DeviceId).IsEqualTo(Utility.Int32Dbnull(txtID.Text)). Execute(); ApplyData2Datarow(); drList.AcceptChanges(); break; } } catch (Exception ex) { Utility.ShowMsg(ex.Message); } }
protected override void UpdateData(DataRow row) { if (row == null) { data.system.projCommentTA.Update(myDataSet.projComment); myDataSet.projects.AcceptChanges(); } else { data.system.projCommentTA.Update(row); row.AcceptChanges(); } }
private void changeRowStateToModified(DataRow dataRow, changedRows changedRow, DataTable dt) { //verificar se é possivel forçar a mudança de estado (tabelas intermedias que so sejam compostas por chaves primarias não são permitidas edições) if (allowRowStateChanges(dt)) { //forçar a mudança de estado para modified da linha marcada como added dataRow.AcceptChanges(); bool isReadOnly = false; isReadOnly = dataRow.Table.Columns[0].ReadOnly; dataRow.Table.Columns[0].ReadOnly = false; dataRow[0] = dataRow[0]; dataRow.Table.Columns[0].ReadOnly = isReadOnly; changedRow.rowsMod.Add(dataRow); RowsChangedToModified.Add(dataRow, dataRow); } else { dataRow.AcceptChanges(); } //como a linha já existe na BD esta deve ser removida da lista das added changedRow.rowsAdd.Remove(dataRow); }
public void UpdateCell(DataRow row, DataColumn column, object value) { if (column == colRowID) return; string col = column.ColumnName; int rowId = RowId(row); var builder = UpdateClause(col, rowId, value); new SqlCmd(builder).ExecuteNonQuery(); row.AcceptChanges(); }
//刷新缓存记录的数据 protected void UpdateSummaryRowState(DataRow dataRow) { dataRow.AcceptChanges(); if (_UpdateType == UpdateType.Modify) dataRow.SetModified(); if (_UpdateType == UpdateType.Add) dataRow.SetAdded(); }
///<summary> /// Update <see cref="System.Data.DataRow">row</see>'s fields into the current opened database. /// <param name="row">a <see cref="System.Data.DataRow">row</see> </param> /// <param name="schema"> a <see cref="SharpQuery.SchemaClass.ISchema">schema</see> </param> /// <remarks> it use a transaction for each row, so it's a very long process /// if you should update something like 10 000 lines ;o). It's used only by the DataView. /// If you need a better way write a "BatchUpdate" function /// </remarks> ///</summary> public void UpDateRow(ISchemaClass schema, DataRow row) { if (schema == null) { throw new System.ArgumentNullException("schema"); } if (row == null) { throw new System.ArgumentNullException("row"); } string SQLUpdate = this.UPDATE + " "; string SQLWhere = this.WHERE + " "; string SQLValues = this.SET + " "; SQLUpdate += schema.Name; SQLUpdate += " "; foreach (DataColumn column in row.Table.Columns) { if (column.ReadOnly == false && column.AutoIncrement == false ) { SQLValues += schema.Name + "." + AbstractSharpQuerySchemaClass.CheckWhiteSpace(column.ColumnName); SQLValues += "="; if (column.DataType.Equals(System.Type.GetType("System.String")) || column.DataType.Equals(System.Type.GetType("System.Char")) ) { SQLValues += "'"; } SQLValues += row[column.ColumnName]; if (column.DataType.Equals(System.Type.GetType("System.String")) || column.DataType.Equals(System.Type.GetType("System.Char")) ) { SQLValues += "'"; } SQLValues += ","; } SQLWhere += SharpQuery.SchemaClass.AbstractSharpQuerySchemaClass.CheckWhiteSpace(column.ColumnName); SQLWhere += "="; if (column.DataType.Equals(System.Type.GetType("System.String")) || column.DataType.Equals(System.Type.GetType("System.Char")) ) { SQLWhere += "'"; } SQLWhere += row[column.ColumnName, DataRowVersion.Original]; if (column.DataType.Equals(System.Type.GetType("System.String")) || column.DataType.Equals(System.Type.GetType("System.Char")) ) { SQLWhere += "'"; } if (row.Table.Columns.IndexOf(column) != (row.Table.Columns.Count - 1)) { SQLWhere += " " + this.AND + " "; } } SQLValues = SQLValues.TrimEnd(new Char[] { ',' }); this.ExecuteSQL(SQLUpdate + SQLValues + SQLWhere, 0); row.AcceptChanges(); }
protected void ConvertEmptyStringToNull(DataRow Row) { bool bUnChanged = Row.RowState == DataRowState.Unchanged; DataTable Tbl = Row.Table; for(int I=0;I<Tbl.Columns.Count;I++) { if(Tbl.Columns[I].AllowDBNull && Row[I] is string && ((string)Row[I]).Trim().Length == 0) { Row[I] = null; } } if(bUnChanged) Row.AcceptChanges(); }
///<summary> /// Delete <see cref="System.Data.DataRow">row</see> into the current opened database. /// <param name="row">a <see cref="System.Data.DataRow">row</see> </param> /// <param name="schema"> a <see cref="SharpQuery.SchemaClass.ISchema">schema</see> </param> /// <remarks> it use a transaction for each row, so it's a very long process /// if you should update something like 10 000 lines ;o). It's used only by the DataView. /// If you need a better way write a "BatchUpdate" function /// </remarks> ///</summary> public void DeleteRow(ISchemaClass schema, DataRow row) { if (schema == null) { throw new System.ArgumentNullException("schema"); } if (row == null) { throw new System.ArgumentNullException("row"); } string SQLDelete = this.DELETE + " "; string SQLWhere = this.WHERE + " "; string SQLFrom = this.FROM + " "; SQLFrom += schema.Name; SQLFrom += " "; foreach (DataColumn column in row.Table.Columns) { //SQLDelete += schema.Name + "." + column.ColumnName; SQLWhere += SharpQuery.SchemaClass.AbstractSharpQuerySchemaClass.CheckWhiteSpace(column.ColumnName); SQLWhere += "="; if (column.DataType.Equals(System.Type.GetType("System.String")) || column.DataType.Equals(System.Type.GetType("System.Char")) ) { SQLWhere += "'"; } SQLWhere += row[column.ColumnName, DataRowVersion.Original]; if (column.DataType.Equals(System.Type.GetType("System.String")) || column.DataType.Equals(System.Type.GetType("System.Char")) ) { SQLWhere += "'"; } if (row.Table.Columns.IndexOf(column) != (row.Table.Columns.Count - 1)) { //SQLDelete += ","; SQLWhere += " " + this.AND + " "; } else { //SQLDelete += " "; } } this.ExecuteSQL(SQLDelete + SQLFrom + SQLWhere, 0); row.AcceptChanges(); }
/// <summary> /// Removes the specified DataRow from the collection. /// </summary> public void Remove (DataRow row) { if (IndexOf (row) < 0) throw new IndexOutOfRangeException ("The given datarow is not in the current DataRowCollection."); DataRowState state = row.RowState; if (state != DataRowState.Deleted && state != DataRowState.Detached) { row.Delete (); // if the row was in added state it will be in Detached state after the // delete operation, so we have to check it. if (row.RowState != DataRowState.Detached) row.AcceptChanges (); } }
///<summary> /// Insert <see cref="System.Data.DataRow">row</see> into the current opened database. /// <param name="row">a <see cref="System.Data.DataRow">row</see> </param> /// <param name="schema"> a <see cref="SharpQuery.SchemaClass.ISchema">schema</see> </param> /// <remarks> it use a transaction for each row, so it's a very long process /// if you should update something like 10 000 lines ;o). It's used only by the DataView. /// If you need a better way write a "BatchUpdate" function /// </remarks> ///</summary> public void InsertRow(ISchemaClass schema, DataRow row) { if (schema == null) { throw new System.ArgumentNullException("schema"); } if (row == null) { throw new System.ArgumentNullException("row"); } string SQLInsert = this.INSERINTO + " "; string SQLValues = this.VALUES + " ("; SQLInsert += schema.Name; SQLInsert += " ("; foreach (DataColumn column in row.Table.Columns) { if (column.ReadOnly == false && column.AutoIncrement == false ) { SQLInsert += /*schema.Name + "." + //Full qualified name not supported by some provider*/ SharpQuery.SchemaClass.AbstractSharpQuerySchemaClass.CheckWhiteSpace(column.ColumnName); if (column.DataType.Equals(System.Type.GetType("System.String")) || column.DataType.Equals(System.Type.GetType("System.Char")) ) { SQLValues += "'"; } SQLValues += row[column.ColumnName, DataRowVersion.Current]; if (column.DataType.Equals(System.Type.GetType("System.String")) || column.DataType.Equals(System.Type.GetType("System.Char")) ) { SQLValues += "'"; } SQLValues += ","; SQLInsert += ","; } } SQLValues = SQLValues.TrimEnd(new Char[] { ',' }); SQLInsert = SQLInsert.TrimEnd(new Char[] { ',' }); SQLInsert += ") "; SQLValues += ")"; this.ExecuteSQL(SQLInsert + SQLValues, 0); row.AcceptChanges(); }
private void cmdSave_Click(object sender, EventArgs e) { try { txtID.Text = txtID.Text.ToUpper(); if (ValidData()) switch (vAction) { case action.Insert: var obj = new LStandardTest(); obj.TestDataId = Utility.sDbnull(txtID.Text, "NONE"); obj.DataName = Utility.sDbnull(txtName.Text, "NONE"); obj.DataSequence = Utility.Int32Dbnull(txtSequence.Value, 0); obj.TestTypeId = Utility.Int32Dbnull(cboTestType.SelectedValue, -1); obj.MeasureUnit = Utility.sDbnull(txtMeasureUnit.Text); obj.NormalLevel = Utility.sDbnull(txtNormalLevel.Text); obj.NormalLevelW = Utility.sDbnull(txtNormalLevelW.Text); obj.DataPoint = (short)Utility.Int32Dbnull(txtDataPoint.Value,0); obj.DataView = ckbDataView.Checked; obj.DataPrint = ckbDataPrint.Checked; obj.Description = Utility.sDbnull(txtDesc.Text); obj.IsNew = true; obj.Save(); drData = dtTestDataList.NewRow(); ApplyData2Datarow(); dtTestDataList.Rows.InsertAt(drData, 0); dtTestDataList.AcceptChanges(); txtID.Enabled = false; vAction=action.Update; break; case action.Update: new Update(LStandardTest.Schema.Name).Set(LStandardTest.Columns.TestDataId).EqualTo(txtID.Text). Set(LStandardTest.Columns.DataName).EqualTo(txtName.Text). Set(LStandardTest.Columns.DataSequence).EqualTo(txtSequence.Text). Set(LStandardTest.Columns.TestTypeId).EqualTo(Utility.Int32Dbnull(cboTestType.SelectedValue, -1)). Set(LStandardTest.Columns.MeasureUnit).EqualTo(txtMeasureUnit.Text). Set(LStandardTest.Columns.NormalLevel).EqualTo(txtNormalLevel.Text). Set(LStandardTest.Columns.NormalLevelW).EqualTo(txtNormalLevelW.Text). Set(LStandardTest.Columns.DataPoint).EqualTo(txtDataPoint.Text). Set(LStandardTest.Columns.DataView).EqualTo(ckbDataView.Checked). Set(LStandardTest.Columns.DataPrint).EqualTo(ckbDataPrint.Checked). Set(LStandardTest.Columns.Description).EqualTo(txtDesc.Text). Where(LStandardTest.Columns.TestDataId).IsEqualTo(txtID.Text).Execute(); ApplyData2Datarow(); drData.AcceptChanges(); break; } } catch (Exception ex) { Utility.ShowMsg(ex.Message); } }
private void btnSave_Click(object sender, EventArgs e) { try { txtID.Text = txtID.Text.ToUpper(); if (ValidData()) switch (vAction) { case action.Insert: var obj = new TTestTypeList(); obj.TestTypeName = Utility.sDbnull(txtName.Text); obj.IntOrder = Utility.ByteDbnull(txtSequence.Value); obj.Abbreviation = Utility.sDbnull(txtAbbreviation.Text); obj.Note = Utility.sDbnull(txtDesc.Text); obj.Price = Utility.DecimaltoDbnull(txtPrice.Value); obj.PrintDetail = Utility.ByteDbnull(ckbPrintDetail.Checked ? 1 : 0); obj.IsNew = true; obj.Save(); drList = dtList.NewRow(); drList[TTestTypeList.Columns.TestTypeId] = TTestTypeList.CreateQuery().GetMax(TTestTypeList.Columns.TestTypeId); ApplyData2Datarow(); dtList.Rows.InsertAt(drList, 0); dtList.AcceptChanges(); txtID.Text = Utility.sDbnull(drList[TTestTypeList.Columns.TestTypeId]); vAction = action.Update; break; case action.Update: new Update(TTestTypeList.Schema.Name).Set(TTestTypeList.Columns.TestTypeName).EqualTo( txtName.Text). Set(TTestTypeList.Columns.IntOrder).EqualTo(txtSequence.Value). Set(TTestTypeList.Columns.Abbreviation).EqualTo(txtAbbreviation.Text). Set(TTestTypeList.Columns.Note).EqualTo(txtDesc.Text). Set(TTestTypeList.Columns.Price).EqualTo(txtPrice.Value). Set(TTestTypeList.Columns.PrintDetail).EqualTo( Utility.ByteDbnull(ckbPrintDetail.Checked ? 1 : 0)). Where(TTestTypeList.Columns.TestTypeId).IsEqualTo(Utility.Int32Dbnull(txtID.Text)). Execute(); ApplyData2Datarow(); drList.AcceptChanges(); break; } } catch (Exception ex) { Utility.ShowMsg(ex.Message); } }