CGlobalInstance() { DbAdaHelper = new CDataAdaHelper(); DbAdaHelper.OnErrorEvent += new OleDbOperate.OnErrorEventHandler(Db_OnErrorEvent); dtBillState = new DataTable("dtState"); dtBillState.Columns.Add("Name", System.Type.GetType("System.String")); dtBillState.Columns.Add("Value", System.Type.GetType("System.Int32")); DataRow dr2 = dtBillState.NewRow(); dr2["Name"] = "未送厨"; dr2["Value"] = 0; dtBillState.Rows.Add(dr2); dr2 = dtBillState.NewRow(); dr2["Name"] = "已送厨"; dr2["Value"] = 1; dtBillState.Rows.Add(dr2); dr2 = dtBillState.NewRow(); dr2["Name"] = "等上菜"; dr2["Value"] = 2; dtBillState.Rows.Add(dr2); dr2 = dtBillState.NewRow(); dr2["Name"] = "已上菜"; dr2["Value"] = 3; dtBillState.Rows.Add(dr2); dtBillType = new DataTable("Type");//点单,退单,赠单,退赠 dtBillType.Columns.Add("Name", System.Type.GetType("System.String")); dtBillType.Columns.Add("Value", System.Type.GetType("System.Int32")); DataRow dr = dtBillType.NewRow(); dr["Name"] = "点单"; dr["Value"] = 0; dtBillType.Rows.Add(dr); dr = dtBillType.NewRow(); dr["Name"] = "退单"; dr["Value"] = 1; dtBillType.Rows.Add(dr); dr = dtBillType.NewRow(); dr["Name"] = "赠单"; dr["Value"] = 2; dtBillType.Rows.Add(dr); dr = dtBillType.NewRow(); dr["Name"] = "退赠"; dr["Value"] = 3; dtBillType.Rows.Add(dr); }
private void toolStripButtonConnect_Click(object sender, EventArgs e) { MSDASC.DataLinks mydlg = new MSDASC.DataLinks(); CDataAdaHelper OleCon = new CDataAdaHelper(); ADODB._Connection ADOcon; bool bEdit = false; //OleCon.ConnectString = CAppOption.m_sDbConnectString; if (CAppOption.m_sDbConnectString == String.Empty) { try { //Cast the generic object that PromptNew returns to an ADODB._Connection. ADOcon = (ADODB._Connection)mydlg.PromptNew(); OleCon.ConnectString = ADOcon.ConnectionString; bEdit = true; } catch (Exception ex) { CGlobalInstance.Instance.WriteErrorLog(YyLogger.LogSeverity.error, "设置数据库连接", ex); } } else { ADOcon = new ADODB.ConnectionClass(); ADOcon.ConnectionString = CAppOption.m_sDbConnectString; //set local COM compatible data type object oConnection = ADOcon; try { //prompt user to edit the given connect string if ((bool)mydlg.PromptEdit(ref oConnection)) { //处理 } OleCon.ConnectString = ADOcon.ConnectionString; bEdit = true; } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("服务连接不成功,请重新设置连接!"); CGlobalInstance.Instance.WriteErrorLog(YyLogger.LogSeverity.error, "设置数据库连接", ex); } } if (bEdit == true) { try { //OleCon.Db.Open(); OleCon.Open(); if (OleCon.IsOpen) { CAppOption.m_sDbConnectString = OleCon.ConnectString; //OleCon.Db.Close(); OleCon.Close(); CGlobalInstance.Instance.DbAdaHelper.ConnectString = CAppOption.m_sDbConnectString; CAppOption.SaveData(); } else { MessageBox.Show("连接无效,无法连接数据库"); } } catch (Exception ex) { MessageBox.Show("连接无效,无法连接数据库(注意请选择允许保存密码)!"); CGlobalInstance.Instance.WriteErrorLog(YyLogger.LogSeverity.error, "设置数据库连接", ex); } } }