private void dgvList_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } DataGridViewRow dataGridViewRow = this.dgvList.Rows[e.RowIndex]; string text = dataGridViewRow.Cells[2].Value.ToString(); this.dataSource = formMain.ledsys.GetDataSource(text); this.Binding(this.dataSource); dataGridViewRow.Cells[3].Value = this.dataSource.GetConnectionString(); if (e.ColumnIndex == 4) { formReName formReName = new formReName(); formReName.name_text_str = text; formReName.Set_Text_Name(); formReName.ShowDialog(); if (formReName.rename_result) { string name_text_str = formReName.name_text_str; if (text == name_text_str) { return; } formMain.Ledsys.RenameDataSource(text, name_text_str); dataGridViewRow.Cells[2].Value = name_text_str; } } }
private void formDataSource_Load(object sender, EventArgs e) { if (Program.IsforeignTradeMode) { base.Icon = Resources.AppIconV5; } else { base.Icon = Resources.AppIcon; } this.dgvList.Rows.Clear(); this.InitControl(); int num = 0; foreach (LedDataSource current in formMain.Ledsys.DataSources) { DataGridViewRow dataGridViewRow = new DataGridViewRow(); dataGridViewRow.CreateCells(this.dgvList); dataGridViewRow.Cells[2].Value = current.Name; dataGridViewRow.Cells[3].Value = current.GetConnectionString(); this.dgvList.Rows.Add(dataGridViewRow); if (num == 0) { this.dataSource = current; this.Binding(current); } num++; } }
private void tsbtnDelete_Click(object sender, EventArgs e) { if (MessageBox.Show(this, "是否删除所选数据源?", formMain.ML.GetStr("UpdateButton_Delete"), MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK && this.dgvList.Rows.Count > 0) { try { foreach (DataGridViewRow dataGridViewRow in this.dgvList.SelectedRows) { formMain.Ledsys.RemoveDataSource(dataGridViewRow.Cells[2].Value.ToString()); this.dataSource = null; this.dgvList.Rows.Remove(dataGridViewRow); } if (this.dgvList.Rows.Count > 0) { DataGridViewRow dataGridViewRow2 = this.dgvList.Rows[this.dgvList.Rows.Count - 1]; dataGridViewRow2.Selected = true; this.dataSource = formMain.ledsys.GetDataSource(dataGridViewRow2.Cells[2].Value.ToString()); this.Binding(this.dataSource); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void Save(LedDataSource dataSource) { if (dataSource != null) { dataSource.Server = this.txtServer.Text; dataSource.Port = this.txtPort.Text; dataSource.Database = this.txtDatabase.Text; dataSource.Username = this.txtUserName.Text; dataSource.Password = this.txtPassword.Text; } }
private void InitControl() { this.dataSource = null; this.pnlSetting.Enabled = false; this.rdoMySQL.Checked = false; this.rdoSQLServer.Checked = false; this.rdoOracle.Checked = false; this.txtServer.Text = string.Empty; this.txtPort.Text = string.Empty; this.txtDatabase.Text = string.Empty; this.txtUserName.Text = string.Empty; this.txtPassword.Text = string.Empty; }
private void btnOK_Click(object sender, EventArgs e) { this.dataSourceSetting.Enabled = this.chkEnabled.Checked; LedDataSource dataSource = formMain.ledsys.GetDataSource(this.cmbDataSource.SelectedValue.ToString()); if (dataSource == null) { if (this.dataSourceSetting.DataSource != null) { this.dataSourceSetting.DataSource.Dispose(); this.dataSourceSetting.DataSource = null; } } else { this.dataSourceSetting.DataSource = dataSource; } if (this.dataSourceSetting.Enabled) { if (dataSource == null) { MessageBox.Show(this, "请选择数据源!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.cmbDataSource.Focus(); return; } if (string.IsNullOrEmpty(this.txtCommandText.Text)) { MessageBox.Show(this, "请输入SQL命令行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.txtCommandText.Focus(); return; } if (string.IsNullOrEmpty(this.txtInterval.Text)) { MessageBox.Show(this, "请输入间隔时间!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.txtInterval.Focus(); return; } } this.dataSourceSetting.CommandText = this.txtCommandText.Text; int interval; bool flag = int.TryParse(this.txtInterval.Text, out interval); if (flag) { this.dataSourceSetting.Interval = interval; } this.btnCancel.PerformClick(); }
private void tsbtnAdd_Click(object sender, EventArgs e) { this.Save(this.dataSource); DataGridViewRow dataGridViewRow = new DataGridViewRow(); dataGridViewRow.CreateCells(this.dgvList); for (int i = 1; i < 9999; i++) { string text = "数据源" + i.ToString(); LedDataSource ledDataSource = formMain.Ledsys.AddDataSource(text); if (ledDataSource != null) { dataGridViewRow.Cells[2].Value = text; this.dataSource = ledDataSource; this.Binding(ledDataSource); break; } } this.dgvList.Rows.Add(dataGridViewRow); dataGridViewRow.Selected = true; }
private void Binding(LedDataSource dataSource) { this.pnlSetting.Enabled = true; switch (dataSource.DataSourceType) { case LedDataSourceType.MySQL: this.rdoMySQL.Checked = true; this.rdoSQLServer.Checked = false; this.rdoOracle.Checked = false; break; case LedDataSourceType.SQLServer: this.rdoMySQL.Checked = false; this.rdoSQLServer.Checked = true; this.rdoOracle.Checked = false; break; case LedDataSourceType.Oracle: this.rdoMySQL.Checked = false; this.rdoSQLServer.Checked = false; this.rdoOracle.Checked = true; break; default: this.rdoMySQL.Checked = false; this.rdoSQLServer.Checked = false; this.rdoOracle.Checked = false; break; } this.txtServer.Text = dataSource.Server; this.txtPort.Text = dataSource.Port; this.txtDatabase.Text = dataSource.Database; this.txtUserName.Text = dataSource.Username; this.txtPassword.Text = dataSource.Password; this.txtServer.Focus(); }