private void cbDataBase_DropDown(object sender, EventArgs e) { cbDataBase.Items.Clear(); SqlConnection con = new SqlConnection(ConnectionString("master")); try { con.Open(); SqlCommand com = con.CreateCommand(); com.CommandText = @"select name from sysdatabases"; SqlDataReader read = com.ExecuteReader(); while (read.Read()) { cbDataBase.Items.Add(read["name"]); } read.Close(); con.Close(); } catch (Exception ex) { I3MessageHelper.ShowError("无法以指定的信息连接到数据库,错误信息:\r\n" + ex.Message, ex); } }
private void button2_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(ConnectionString(cbDataBase.Text)); try { con.Open(); I3MessageHelper.ShowInfo("连接成功"); } catch (Exception ex) { I3MessageHelper.ShowError(ex.Message, ex); } }
/// <summary> /// 打印 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsbPrint_Click(object sender, EventArgs e) { try { int start = (int)startPage.Value; start = start < 1 ? 1 : start; start = start > reportDatas.PrintAreas.Dic.Count ? reportDatas.PrintAreas.Dic.Count : start; int end = (int)endPage.Value; end = end < 1 ? 1 : end; end = end > reportDatas.PrintAreas.Dic.Count ? reportDatas.PrintAreas.Dic.Count : end; end = end < start ? start : end; int count = (int)printCount.Value; I3ReportPrintController.PrintToPrinter(cbbPrinter.Text, documentName, reportDatas, start, end, count, rpc.PaintPageIndex2); } catch (Exception ex) { I3MessageHelper.ShowError("打印失败,原因:\r\n" + ex.Message); } }
private void TfrmGetSymbol_Load(object sender, EventArgs e) { busy = true; try { nameList = new ArrayList(); textList = new ArrayList(); #region 读取数据,并检查数据正确性 try { dataSet.ReadXml(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Symbol.set")); } catch (Exception ex) { I3MessageHelper.ShowError(ex.Message, ex); return; } if (dataSet.Tables.Count == 0) { return; } if (dataSet.Tables[0].Columns.Count == 0) { return; } if (dataSet.Tables[0].Rows.Count == 0) { return; } #endregion #region 写入默认数据 /*dataSet.Tables[0].Columns[0].ColumnName = "数学序号"; * dataSet.Tables[0].Columns[1].ColumnName = "数学符号"; * dataSet.Tables[0].Columns[2].ColumnName = "单位符号"; * dataSet.Tables[0].Columns[3].ColumnName = "特殊符号"; * dataSet.Tables[0].Rows[0][0] = "①②③④⑤⑥⑦⑧⑨⑩ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ"; * dataSet.Tables[0].Rows[0][1] = "×÷≠≤≥≮≯±∽≈≌⊕⊙∈∏∑∝∞∫∮"; * dataSet.Tables[0].Rows[0][2] = "℃℉﹪‰¥№㎡23㎝㎞㏎㎎㎏㏄"; * dataSet.Tables[0].Rows[0][3] = "Ф★☆○☉◎●▲△▼▽■□♀♂《》「」『』〖〗【】"; * dataSet.WriteXml(AppDomain.CurrentDomain.BaseDirectory + @"\Symbol.set");*/ #endregion #region 将数据保存到动态数组中 for (int i = 0; i < dataSet.Tables[0].Columns.Count; i++) { nameList.Add(dataSet.Tables[0].Columns[i].ColumnName); textList.Add(dataSet.Tables[0].Rows[0][i].ToString()); } cbbSymbolStyle.DataSource = nameList; #endregion #region 增加20列 for (int i = 0; i < 20; i++) { DataColumn newColumn = new DataColumn("col" + (i + 1).ToString(), typeof(string)); newDataTable.Columns.Add(newColumn); I3TextColumn textColumn = new I3TextColumn(); textColumn.Width = Convert.ToInt32(this.i3Table.Width / 20); textColumn.Sortable = false; textColumn.Editable = false; this.i3ColumnModel.Columns.Add(textColumn); } #endregion #region 得到完全字符串 string s = ""; for (int i = 0; i < textList.Count; i++) { s = s + textList[i].ToString(); } #endregion #region 得到行数,并生成DataRow int rowcount = s.Length / 20; if (s.Length % 20 > 0) { rowcount++; } for (int i = 0; i < rowcount; i++) { DataRow newRow = newDataTable.NewRow(); newDataTable.Rows.Add(newRow); } #endregion #region 给每行每列赋值 int row, col; for (int i = 0; i < s.Length; i++) { row = (i + 1) / 20; //整除 col = (i + 1) % 20; //求余 if (col == 0) { row--; col += 20; } col--; newDataTable.Rows[row].BeginEdit(); newDataTable.Rows[row][col] = I3StringUtil.SubString(s, i, 1); newDataTable.Rows[row].EndEdit(); } foreach (DataRow dataRow in newDataTable.Rows) { I3Row i3Row = new I3Row(); this.i3TableModel.Rows.Add(i3Row); foreach (DataColumn column in newDataTable.Columns) { I3Cell i3Cell = new I3Cell(dataRow[column].ToString()); i3Row.Cells.Add(i3Cell); } } #endregion this.i3TableModel.Selections.SelectCell(0, 0); } finally { busy = false; } }