MainForm.cs
上传用户:abcs8778
上传日期:2022-08-03
资源大小:2093k
文件大小:2k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

SQL

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Data.SqlClient;
  9. using Microsoft.AnalysisServices.AdomdClient;
  10. namespace BookSellPredict
  11. {
  12.     public partial class MainForm : Form
  13.     {
  14.         protected SqlConnection _connDatabase;
  15.         protected AdomdConnection _connAnalysis;
  16.         public MainForm()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.         private void MainForm_Load(object sender, EventArgs e)
  21.         {
  22.             _connDatabase = new SqlConnection("Data Source=(local); Initial Catalog=BookSell; Integrated Security=true");
  23.             _connAnalysis = new AdomdConnection("Data Source=(local); Initial Catalog=BookSellAnalysis;");
  24.             try
  25.             {
  26.                 _connDatabase.Open();
  27.                 _connAnalysis.Open();
  28.             }
  29.             catch (Exception exp)
  30.             {
  31.                 MessageBox.Show("数据连接错误:" + exp.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  32.                 this.Close();
  33.             }
  34.         }
  35.         private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
  36.         {
  37.             if (_connDatabase != null && _connDatabase.State != ConnectionState.Closed)
  38.                 _connDatabase.Close();
  39.             if (_connAnalysis != null && _connAnalysis.State != ConnectionState.Closed)
  40.                 _connAnalysis.Close();
  41.         }
  42.         private void button1_Click(object sender, EventArgs e)
  43.         {
  44.             CustomerAnalysisForm frm1 = new CustomerAnalysisForm(_connDatabase, _connAnalysis);
  45.             frm1.ShowDialog();
  46.         }
  47.         private void button2_Click(object sender, EventArgs e)
  48.         {
  49.             BookAnalysisForm frm1 = new BookAnalysisForm(_connDatabase, _connAnalysis);
  50.             frm1.ShowDialog();
  51.         }
  52.     }
  53. }