public void CommitPagosServiciosGastos(string IdInsCaja, int SignoParent) { _dataValoresEx.Clear(); for (int i = 1; i <= MisValores.Count; i++) { if (MisValores[i - 1] != null) { Valor valor = (Valor)MisValores[i - 1]; valor.IdInstanciaCaja = IdInsCaja; valor.Signo = SignoParent; if (valor.State.ToUpper().Equals("NEW") || valor.Agrupado) { valor.Commit((tfi_ValoresExDataset)_dataValoresEx); } else { if (valor.State.ToUpper().Equals("EDIT")) { if ((valor.SignoDB + SignoParent) == 0) { valor.Signo = 0; valor.IdInstanciaCaja = string.Empty; /*Ver el estado en el q deberia quedar el cheque*/ /*Por ahora NO INDICA, ver si depende del tipo de Cheque*/ /*Ver documentacion de Vivi*/ valor.IdEstado = "4"; } valor.Update((tfi_ValoresExDataset)_dataValoresEx); } } } } }
//======================================================= //Глобальные процедуры и функции ======================== public void TreeInitialize() { //Подключение локальной базы данных (список серверов) try{ OleDb_Connection.ConnectionString = ClassConfig.ConnectLineBegin + ClassConfig.Rapid_FileListBase + ClassConfig.ConnectLineEnd + ClassConfig.ConnectPass; OleDb_Connection.Open(); //соединение с базой //Создание таблицы DataTable DataTable_ListBase.Clear(); DataTable_ListBase.CaseSensitive = false; DataTable_ListBase.Columns.Add("Name", Type.GetType("System.String")); DataTable_ListBase.Columns.Add("Server", Type.GetType("System.String")); DataTable_ListBase.Columns.Add("DataBase", Type.GetType("System.String")); DataTable_ListBase.Columns.Add("Uid", Type.GetType("System.String")); DataTable_ListBase.Columns.Add("Pwd", Type.GetType("System.String")); DataTable_ListBase.Columns.Add("Admin", Type.GetType("System.String")); DataTable_ListBase.Columns.Add("Client", Type.GetType("System.String")); //Вставка таблицы в DataSet DataSet_ListBase.Clear(); DataSet_ListBase.Tables.Add(DataTable_ListBase); DataSet_ListBase.DataSetName = "ListBase"; OleDb_CommandSelect = new OleDbCommand("SELECT * FROM ListBase", OleDb_Connection); OleDb_CommandDelete = new OleDbCommand("DELETE FROM ListBase WHERE ([ID_ListBase] = ?) AND (Name = ? OR ? IS NULL AND Name IS NULL) AND (Server = ? OR ? IS NULL AND Server IS NULL) AND (DataBase = ? OR ? IS NULL AND DataBase IS NULL) AND (Uid = ? OR ? IS NULL AND Uid IS NULL) AND (Pwd = ? OR ? IS NULL AND Pwd IS NULL) AND (Admin = ? OR ? IS NULL AND Admin IS NULL) AND (Client = ? OR ? IS NULL AND Client IS NULL)", OleDb_Connection); OleDb_CommandUpdate = new OleDbCommand("UPDATE ListBase SET [Name] = ?, [Server] = ?, [DataBase] = ?, [Uid] = ?, [Pwd] = ?, [Admin] = ?, [Client] = ? WHERE ([ID_ListBase] = ?) AND (Name = ? OR ? IS NULL AND Name IS NULL) AND (Server = ? OR ? IS NULL AND Server IS NULL) AND (DataBase = ? OR ? IS NULL AND DataBase IS NULL) AND (Uid = ? OR ? IS NULL AND Uid IS NULL) AND (Pwd = ? OR ? IS NULL AND Pwd IS NULL) AND (Admin = ? OR ? IS NULL AND Admin IS NULL) AND (Client = ? OR ? IS NULL AND Client IS NULL)", OleDb_Connection); OleDb_CommandInsert = new OleDbCommand("INSERT INTO ListBase ([Name], [Server], [DataBase], [Uid], [Pwd], [Admin], [Client]) VALUES (?, ?, ?, ?, ?, ?, ?)", OleDb_Connection); OleDb_DataAdapter1.SelectCommand = OleDb_CommandSelect; OleDb_DataAdapter1.DeleteCommand = OleDb_CommandDelete; OleDb_DataAdapter1.UpdateCommand = OleDb_CommandUpdate; OleDb_DataAdapter1.InsertCommand = OleDb_CommandInsert; OleDb_DataAdapter1.Fill(DataSet_ListBase, "ListBase"); OleDb_Connection.Close(); //отключение соединения // Выгрузка данных treeView1.Nodes.Clear(); treeView1.Nodes.Add("Конфигурации").ImageKey = "folder_close.png"; treeView1.Nodes[0].SelectedImageKey = "folder_close.png"; foreach (System.Data.DataTable table in DataSet_ListBase.Tables) { foreach (System.Data.DataRow row in table.Rows) { treeView1.Nodes[0].Nodes.Add(row[1].ToString()).Tag = row[0].ToString(); } } }catch (Exception ex) { MessageBox.Show(ex.ToString()); //Сообщение об ошибке OleDb_Connection.Close(); Application.Exit(); } }
private void check_CheckedChanged(object sender, System.EventArgs e) { adapter.SelectCommand.CommandText = "Select ID,FIO,Dat,Name From Diagn "; if((dateCheck.Text!="") || nameCheck.Checked || repCheck.Checked) adapter.SelectCommand.CommandText += "Where "; if(dateCheck.SelectedIndex>0) { adapter.SelectCommand.CommandText += "Dat"+dateCheck.Text + TextManager.DateToSQL(dateFilter.Value.ToShortDateString())+" "; if(nameCheck.Checked || repCheck.Checked) adapter.SelectCommand.CommandText += "and "; } if(nameCheck.Checked) { adapter.SelectCommand.CommandText += "FIO Like \"%"+nameFilter.Text+"%\" "; if(repCheck.Checked) adapter.SelectCommand.CommandText += "and "; } if(repCheck.Checked) { adapter.SelectCommand.CommandText += "Name Like \"%"+repFilter.Text+"%\""; } adapter.SelectCommand.CommandText += " "; dataGrid1.DataSource = null; dataSet1.Clear(); this.LoadDialog_Load(this,null); }
/// <summary> /// Full data set /// </summary> /// <param name="Dset"></param> /// <param name="strsql"></param> /// <param name="strTqbleName"></param> /// <returns></returns> public static bool Fuller(System.Data.DataSet Dset, string strsql, string strTableName) { bool retValue = true; Dset.Clear(); System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(); System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(); con.ConnectionString = strProv; da.SelectCommand = new System.Data.SqlClient.SqlCommand(); da.SelectCommand.Connection = con; da.SelectCommand.CommandText = strsql; try { con.Open(); da.Fill(Dset, strTableName); } catch (Exception) { retValue = false; } finally { con.Close(); } return(retValue); }
public System.Data.DataTable Query(string psSQL) { System.Data.DataTable loDataReturn = null; System.Data.DataSet loDS = new System.Data.DataSet(); SQLiteConnection loSql_con; SQLiteDataAdapter loSQLAdapter; loSql_con = getConnection(); loSQLAdapter = new SQLiteDataAdapter(psSQL, loSql_con); loDS.Reset(); loSQLAdapter.Fill(loDS); loDataReturn = loDS.Tables[0]; loDS.Tables.Remove(loDataReturn); loDS.Clear(); loDS.Dispose(); loSql_con.Close(); loSql_con.Dispose(); loSQLAdapter.Dispose(); return(loDataReturn); }
private void btClear_Click(object sender, System.EventArgs e) { dataSet.Clear(); writeStatus1 = ""; OnWriteStatus(); }
public void PreencheTabelaVenda(System.Windows.Forms.DataGridView dataGridView) { Abrir(); MySqlDataAdapter meuAdapter = new MySqlDataAdapter("Select * from TabVenda", minhaConexao); System.Data.DataSet dataSet = new System.Data.DataSet(); dataSet.Clear(); meuAdapter.Fill(dataSet, tabela); dataGridView.DataSource = dataSet; dataGridView.DataMember = tabela; Fechar(); }
public void PreencheTabela(System.Windows.Forms.DataGridView dataGridView) { Abrir(); MySqlDataAdapter meuAdapter = new MySqlDataAdapter("Select Nome_Cli, Cnpj, DDD, Estado from " + tabela, minhaConexao); System.Data.DataSet dataSet = new System.Data.DataSet(); dataSet.Clear(); meuAdapter.Fill(dataSet, tabela); dataGridView.DataSource = dataSet; dataGridView.DataMember = tabela; Fechar(); }
void loadData() { //Подключение локальной базы данных (список серверов) try{ oleDbConnection.ConnectionString = DataConfig.oledbConnectLineBegin + DataConfig.configFile + DataConfig.oledbConnectLineEnd + DataConfig.oledbConnectPass; oleDbConnection.Open(); //соединение с базой //Создание таблицы DataTable oleDbDataTable.Clear(); oleDbDataTable.CaseSensitive = false; oleDbDataTable.Columns.Add("Name", Type.GetType("System.String")); oleDbDataTable.Columns.Add("Pass", Type.GetType("System.String")); oleDbDataTable.Columns.Add("Permissions", Type.GetType("System.String")); //Вставка таблицы в DataSet oleDbDataSet.Clear(); oleDbDataSet.Tables.Add(oleDbDataTable); oleDbDataSet.DataSetName = "ListUsers"; oleDbCommandSelect = new OleDbCommand("SELECT * FROM Users", oleDbConnection); oleDbCommandDelete = new OleDbCommand("DELETE FROM Users WHERE ([ID] = ?) " + "AND (Name = ? OR ? IS NULL AND Name IS NULL) " + "AND (Pass = ? OR ? IS NULL AND Pass IS NULL) " + "AND (Permissions = ? OR ? IS NULL AND Permissions IS NULL)", oleDbConnection); oleDbCommandUpdate = new OleDbCommand("UPDATE Users SET [Name] = ?, [Pass] = ?, [Permissions] = ? WHERE ([ID] = ?) " + "AND (Name = ? OR ? IS NULL AND Name IS NULL) " + "AND (Pass = ? OR ? IS NULL AND Pass IS NULL) " + "AND (Permissions = ? OR ? IS NULL AND Permissions IS NULL)", oleDbConnection); oleDbCommandInsert = new OleDbCommand("INSERT INTO Users ([Name], [Pass], [Permissions]) VALUES (?, ?, ?)", oleDbConnection); oleDbDataAdapter1.SelectCommand = oleDbCommandSelect; oleDbDataAdapter1.DeleteCommand = oleDbCommandDelete; oleDbDataAdapter1.UpdateCommand = oleDbCommandUpdate; oleDbDataAdapter1.InsertCommand = oleDbCommandInsert; oleDbDataAdapter1.Fill(oleDbDataSet, "Users"); oleDbConnection.Close(); //отключение соединения }catch (Exception ex) { MessageBox.Show(ex.ToString()); oleDbConnection.Close(); Application.Exit(); } readData(); }
private void Update(string address) { ObjectBE[] copy = updateList.ToArray(); updateList.Clear(); foreach (ObjectBE obe in copy) { try { obe.BeforeUpdate(); } catch (Exception x1) { throw new AtriumException("Update stopped on " + obe.myDT.TableName + ". Reject changes will restore Datatables consistency with database.\r\n", x1); } if (obe.myDT.HasErrors) { throw new AtriumException("Update stopped on " + obe.myDT.TableName + ". Reject changes will restore Datatables consistency with database.\r\n" + obe.ErrorsForTable(obe.myDT)); } } string tableNm = ""; System.Data.DataSet dsDown = null; try { System.Data.DataSet dsUp = new System.Data.DataSet(); List <string> tables = new List <string>(); foreach (ObjectBE obe in copy) { System.Data.DataTable dt = obe.myDT.GetChanges(); if (dt != null) { dt.ExtendedProperties.Remove("BE"); if (!obe.IsVirtual) { //extend this scheme to include the obe.MyMNg.CurrentFileid //this way we can put the returned datatable into the right obe object //we will need to rename the datatables in the server code to include this info if (obe.DALName == "") { tables.Add(dt.TableName); } else { tables.Add(dt.TableName + "." + obe.DALName); } } if (!dsUp.Tables.Contains(dt.TableName)) { //TFS#51279 CJW 2013-8-30 - Deal with time zone off sets set by web service foreach (System.Data.DataColumn column in dt.Columns) { if (column.DataType == typeof(DateTime)) { //column.DateTimeMode = System.Data.DataSetDateTime.Unspecified; } } //End TFS #51279 dsUp.Tables.Add(dt); } } } if (myMng.AppMan.Compression) //compression on { byte[] byteUp = BEManager.CompressData(dsUp); //dsUp.Dispose(); //dsUp = null; dsUp.Clear(); dsUp.AcceptChanges(); if (!myMng.AppMan.UseService) { byteUp = this.myMng.DAL.Update(tables, byteUp); } else { byteUp = myMng.AppMan.AtriumX().UpdateComp(myMng.AppMan.Connect, myMng.AppMan.myPwd, myMng.AppMan.myUser, tables.ToArray(), byteUp); } dsDown = BEManager.DecompressDataSet(byteUp, dsUp); } else //compression ffn { if (!myMng.AppMan.UseService) { dsDown = this.myMng.DAL.Update(tables, dsUp); } else { dsUp.RemotingFormat = System.Data.SerializationFormat.Binary; dsDown = myMng.AppMan.AtriumX().Update(myMng.AppMan.Connect, myMng.AppMan.myPwd, myMng.AppMan.myUser, tables.ToArray(), dsUp); } } } catch (Exception x) { if (x.InnerException != null) { if (x.InnerException.GetType() == typeof(System.Data.SqlClient.SqlException)) { System.Data.SqlClient.SqlException sqle = (System.Data.SqlClient.SqlException)x.InnerException; switch (sqle.Number) { case 2601: throw new Exception(Properties.Resources.DuplicateValueInAUniqueColumn, sqle); case 50000: throw new AtriumException(sqle.Message); default: throw sqle; } } else if (x.InnerException.GetType() == typeof(System.Data.DBConcurrencyException)) { System.Data.DBConcurrencyException dbce = (System.Data.DBConcurrencyException)x.InnerException; throw new ConcurrencyException(String.Format(Properties.Resources.ConcurrencyError, ""), x); } else { throw x; } } else { throw new UpdateFailedException("Update failed on " + tableNm + ". Datatables need to be reloaded as acceptchanges/merge has been called on them.\r\n", x); } } //TFS#51508 CJW 2013-09-19 //all updates have succeeded //merge data back into client datasets //and accept changes bool isError = false; Exception x5 = null; foreach (ObjectBE obe in copy) { tableNm = obe.myDT.TableName; if (dsDown.Tables.Count > 0 && dsDown.Tables.Contains(tableNm)) { try { //hack required because we remove the Contents column on the server to speed up the download //if we leave it in it gets blanked if (tableNm.ToLower() == "doccontent") { dsDown.Tables[tableNm].Columns.Remove("Contents"); }//end of hack if (!obe.IsVirtual) { obe.Fill(dsDown.Tables[tableNm]); } obe.AfterUpdate(); } catch (System.InvalidOperationException x) { //trap for Corrupt datatable index '5' isError = true; x5 = x; } //acceptchanges must be called last so that afterupdate knows which rows o process obe.myDT.AcceptChanges(); } } if (isError) { throw new AtriumException("An unexpected error has occurred. Please close and restart Atrium.", x5); } }