Пример #1
0
	public int SaveTable(string TableName, DataGridView SourceTable)
	{
		if ((OpenTable(TableName))) {
			DialogResult Result = MessageBox.Show("Вы хотите заменить таблицу?", 
												  "Таблица с таким именем существует", 
												  MessageBoxButtons.OKCancel, 
												  MessageBoxIcon.Question);
			if (Result == DialogResult.OK) {
					DeleteTable(TableName);
			}
			else {
				return 0;
			}
		}
		int CreateResult = CreateDataBaseTemplate(TableName);
		if (CreateResult == 0) {
			DialogResult Result = MessageBox.Show("Невозможно сохранить таблицу с таким именем!",
												  "Продолжить сохранение?",
												   MessageBoxButtons.YesNo,
												   MessageBoxIcon.Exclamation);
			if (Result == DialogResult.Yes) {
				save_form MDISaveForm = new save_form(null, null);
				object[] Args = new object[2];
				Args[0] = (BankLab)SourceTable.Parent;
				Args[1] = SourceTable;
				((BankLab)SourceTable.Parent).MDI.ShowMDIForm(MDISaveForm, Args);
				return -1;
			}
		}
		string Query;
		OleDbCommand command;
		I_OleConnection.Open();
		string Fields = " (years";
		for (int i = 1; i < SourceTable.ColumnCount; i++) {
			Fields += " , X" + i.ToString();
		}
		Fields += ")";
		for (int i = 0; i < SourceTable.RowCount; i++) {
			Query = "INSERT INTO " + TableName +
						Fields + " VALUES (";
			for (int j = 0; j < SourceTable.ColumnCount; j++) {
				if (SourceTable.Rows[i].Cells[j].Value == null) {
					Query += "'" + "'" + ",";
				}
				else {
					Query += "'" + SourceTable.Rows[i].Cells[j].Value.ToString() + "'" + ",";
				}
			}
			Query = Query.Remove(Query.Length - 1);
			Query += ")";
			command = new OleDbCommand(Query, I_OleConnection);
			command.ExecuteNonQuery();
		}
		I_OleConnection.Close();
		OpenTable(TableName);
		((BankLab)SourceTable.Parent).CurrentDataTable.LinkDataTableToDataSet();
		return 1;
	}
Пример #2
0
	private void сохранитьToolStripMenuItem_Click(object sender, EventArgs e)
	{
		if ((((ToolStripMenuItem)sender).Text == "Сохранить как")&&(сохранитьToolStripMenuItem.Enabled)) {
			save_form MdiSaveForm = new save_form(null, null);
			object[] Args = new object[2];
			Args[0] = this;
			Args[1] = CurrentDataTable.GetDataTable();
			MDI.ShowMDIForm(MdiSaveForm, Args);
		}
		else {
			if (сохранитьToolStripMenuItem.Enabled) {
				if ((CurrentDataBase.GetTableName() == String.Empty)&&(CurrentDataBase.GetDatabasePath() == String.Empty)&&(CurrentDataBase.GetCurrentDataBase() == null)) { 
					save_form MdiSaveForm = new save_form(null,null);
					object[] Args = new object[2];
					Args[0] = this;
					Args[1] = CurrentDataTable.GetDataTable();
					MDI.ShowMDIForm(MdiSaveForm, Args);
				}
				else {
					CurrentDataBase.GetCurrentDataBase().UpdateTableData(CurrentDataBase.GetCurrentDataBase().GetDataSet(),CurrentDataBase.GetTableName());
				}
			}
		}
	}