ChangeMaster.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using UAS_LabelMachine.Entity;
  10. namespace UAS_LabelMachine
  11. {
  12. public partial class ChangeMaster : Form
  13. {
  14. DataHelper dh = SystemInf.dh;
  15. SqliteDBHelper sdh;
  16. DataTable Masterdt;
  17. public ChangeMaster()
  18. {
  19. InitializeComponent();
  20. }
  21. private void ChangeMaster_Load(object sender, EventArgs e)
  22. {
  23. Masterdt = (DataTable)dh.ExecuteSql("select ma_function,ms_pwd,ma_user from master ", "select");
  24. MasterCombox.DisplayMember = "ma_function";
  25. MasterCombox.ValueMember = "ma_user";
  26. MasterCombox.DataSource = Masterdt;
  27. }
  28. private void button1_Click(object sender, EventArgs e)
  29. {
  30. string Ms_Pwd = "";
  31. for (int i = 0; i < Masterdt.Rows.Count; i++)
  32. {
  33. if (MasterCombox.SelectedValue == Masterdt.Rows[i]["ma_user"])
  34. Ms_Pwd = Masterdt.Rows[i]["ms_pwd"].ToString();
  35. }
  36. //切换至用户选择的数据源
  37. string ConnectionString = "Connection Timeout=0;Pooling=false;Password=" + Ms_Pwd + ";User ID=" + MasterCombox.SelectedValue.ToString() + ";Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" + SystemInf.IP + ")(PORT=" + DataHelper.OraclePort + ")))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
  38. DataHelper.DBConnectionString = ConnectionString;
  39. //设置当前账套
  40. SystemInf.Master = MasterCombox.SelectedValue.ToString();
  41. SystemInf.sdh = sdh = new SqliteDBHelper(SystemInf.Master + ".db3");
  42. SystemInf.MasterName = MasterCombox.Text;
  43. //设置了Connection,重新执行构造函数,重置数据库连接
  44. dh = new DataHelper();
  45. Close();
  46. }
  47. }
  48. }