Beispiel #1
0
        private void createDatabaseCToolStripMenuItem_Click(object sender, EventArgs e)
        {
            formDatabaseSet frmDatabaseSet = new formDatabaseSet();

            frmDatabaseSet.intMode = 1;//

            if (frmDatabaseSet.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                strConn = frmDatabaseSet.strConn;
                if (strConn == "") //连接错误
                {
                    return;
                }

                //初始化窗口
                sqlConn.ConnectionString = strConn;
                sqlComm.Connection       = sqlConn;
                sqlDA.SelectCommand      = sqlComm;
            }
        }
Beispiel #2
0
        private void MDIiManage_Load(object sender, EventArgs e)
        {
            //日期显示
            toolStripStatusLabelDate.Text = "Today is " + System.DateTime.Now.ToShortDateString() + ", Week " + ClassIm.GetWeek(System.DateTime.Now).ToString();

            string dFileName = "";

            dFileName           = Directory.GetCurrentDirectory() + "\\appcon.xml";
            sqlComm.Connection  = sqlConn;
            sqlDA.SelectCommand = sqlComm;

            if (File.Exists(dFileName)) //存在文件
            {
                dSet.ReadXml(dFileName);
                strConn = "workstation id=CY;packet size=4096;user id=" + dSet.Tables["DataBaseInfo"].Rows[0][1].ToString() + ";password="******"DataBaseInfo"].Rows[0][2].ToString() + ";data source=\"" + dSet.Tables["DataBaseInfo"].Rows[0][0].ToString() + "\";;initial catalog=" + dSet.Tables["DataBaseInfo"].Rows[0][3].ToString();

                strDataBaseAddr = dSet.Tables["DataBaseInfo"].Rows[0][0].ToString();
                strDataBaseUser = dSet.Tables["DataBaseInfo"].Rows[0][1].ToString();
                strDataBasePass = dSet.Tables["DataBaseInfo"].Rows[0][2].ToString();
                strDataBaseName = dSet.Tables["DataBaseInfo"].Rows[0][3].ToString();

                if (strDataBaseAddr == "0.0.0.0")
                {
                    strConn = "";

                    //option
                    string dFileNameOption = Directory.GetCurrentDirectory() + "\\options.xml";
                    if (File.Exists(dFileNameOption)) //存在文件
                    {
                        dSetOption.ReadXml(dFileNameOption);

                        iNumofWeek = int.Parse(dSetOption.Tables["parameters"].Rows[0][0].ToString());
                        iNumofPass = int.Parse(dSetOption.Tables["parameters"].Rows[0][1].ToString());
                        //iRange = int.Parse(dSetOption.Tables["parameters"].Rows[0][2].ToString());
                    }
                    return;
                }

                sqlConn.ConnectionString = strConn;
                try
                {
                    sqlConn.Open();
                    sqlDA.SelectCommand = sqlComm;

                    sqlComm.CommandText = "SELECT   ID, [num of week], [num of pass], range, [string TAG], [SAP Control Number], [SAP order], [Sales plan], [CW IMEI], [Master data] FROM parameters";
                    sqldr = sqlComm.ExecuteReader();
                    if (sqldr.HasRows)
                    {
                        sqldr.Read();
                        iNumofWeek = int.Parse(sqldr.GetValue(1).ToString());
                        iNumofPass = int.Parse(sqldr.GetValue(2).ToString());
                        iRange     = int.Parse(sqldr.GetValue(3).ToString());

                        sTAG = sqldr.GetValue(4).ToString();;
                        iSAPControlNumber = int.Parse(sqldr.GetValue(5).ToString());;
                        sSAPorder         = sqldr.GetValue(6).ToString();
                        sSalesplan        = sqldr.GetValue(7).ToString();
                        sCWIMEI           = sqldr.GetValue(8).ToString();
                        sMaster           = sqldr.GetValue(9).ToString();
                        sqldr.Close();
                    }
                }
                catch (System.Data.SqlClient.SqlException err)
                {
                    bool isCreateDatabase = true;
                    if (MessageBox.Show("connect database fail, create it?" + err.Message.ToString(), "Infomation", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
                    {
                        isCreateDatabase = false;
                    }

                    strConn = "";
                    formDatabaseSet frmDatabaseSet = new formDatabaseSet();
                    if (isCreateDatabase)
                    {
                        frmDatabaseSet.intMode = 1;
                    }

                    frmDatabaseSet.ShowDialog(this);
                    if (frmDatabaseSet.strConn != "")
                    {
                        strConn = frmDatabaseSet.strConn;
                        //初始化窗口
                        sqlConn.ConnectionString = strConn;


                        sqlComm.CommandText = "SELECT   ID, [num of week], [num of pass], range, [string TAG], [SAP Control Number], [SAP order], [Sales plan], [CW IMEI], [Master data] FROM parameters";
                        sqlConn.Open();
                        sqldr = sqlComm.ExecuteReader();
                        if (sqldr.HasRows)
                        {
                            sqldr.Read();
                            iNumofWeek = int.Parse(sqldr.GetValue(1).ToString());
                            iNumofPass = int.Parse(sqldr.GetValue(2).ToString());
                            iRange     = int.Parse(sqldr.GetValue(3).ToString());

                            sTAG = sqldr.GetValue(4).ToString();;
                            iSAPControlNumber = int.Parse(sqldr.GetValue(5).ToString());;
                            sSAPorder         = sqldr.GetValue(6).ToString();
                            sSalesplan        = sqldr.GetValue(7).ToString();
                            sCWIMEI           = sqldr.GetValue(8).ToString();
                            sMaster           = sqldr.GetValue(9).ToString();

                            sqldr.Close();
                        }
                        sqlConn.Close();
                    }
                    else
                    {
                        //this.Close();
                        return;
                    }
                }
                finally
                {
                    sqlConn.Close();
                }
            }
            else  //不存在文件
            {
                /*
                 * formDatabaseSet frmDatabaseSet = new formDatabaseSet();
                 * frmDatabaseSet.ShowDialog(this);
                 * if (frmDatabaseSet.strConn != "")
                 * {
                 *  strConn = frmDatabaseSet.strConn;
                 *  //初始化窗口
                 *  sqlConn.ConnectionString = strConn;
                 *
                 *  sqlComm.CommandText = "SELECT   ID, [num of week], [num of pass], range, [string TAG], [SAP Control Number], [SAP order], [Sales plan], [CW IMEI], [Master data] FROM parameters";
                 *  sqlConn.Open();
                 *  sqldr = sqlComm.ExecuteReader();
                 *  if (sqldr.HasRows)
                 *  {
                 *      sqldr.Read();
                 *      iNumofWeek = int.Parse(sqldr.GetValue(1).ToString());
                 *      iNumofPass = int.Parse(sqldr.GetValue(2).ToString());
                 *      iRange = int.Parse(sqldr.GetValue(3).ToString());
                 *
                 *      sTAG = sqldr.GetValue(4).ToString(); ;
                 *      iSAPControlNumber = int.Parse(sqldr.GetValue(5).ToString()); ;
                 *      sSAPorder = sqldr.GetValue(6).ToString();
                 *      sSalesplan = sqldr.GetValue(7).ToString();
                 *      sCWIMEI = sqldr.GetValue(8).ToString();
                 *      sMaster = sqldr.GetValue(9).ToString();
                 *      sqldr.Close();
                 *
                 *  }
                 *  sqlConn.Close();
                 * }
                 * else
                 * {
                 *  //this.Close();
                 *  return;
                 * }
                 */

                strConn = "";
                return;
            }
        }