/// <summary> /// 获取一个连接配置 /// </summary> /// <param name="id"></param> /// <returns></returns> public static Entity.Connection GetConnectionModel(string id) { Entity.Connection connModel = null; if (string.IsNullOrEmpty(id)) { return(connModel); } XmlDocument doc = new XmlDocument(); doc.Load(DatabaseconfigPath); XmlNode xmlNode = doc.SelectSingleNode("servers/server[@id='" + id.ToString() + "']"); if (null != xmlNode) { connModel = new SharpTools.Entity.Connection(); connModel.ID = new Guid(xmlNode.Attributes["id"].Value); connModel.Name = xmlNode.Attributes["name"].Value; connModel.Database = xmlNode.Attributes["database"].Value; connModel.ConnectionString = xmlNode.FirstChild.InnerText; connModel.DbType = xmlNode.Attributes["dbtype"].Value.ConvertTo <DataBaseType>(); } return(connModel); }
//public bool Connect(Entity.Connection cn) private bool Connect(Entity.Connection cn) { bool isConnected = false; if (cn.IP.Trim() == "" || cn.Port.Trim() == "") { Util.LogHelper.WriteLog("IP and Port cannot be null."); return(false); } int idwErrorCode = 0; isConnected = this.device.Connect_Net(cn.IP.Trim(), Convert.ToInt32(cn.Port.Trim())); if (isConnected) { //if (this.device.RegEvent(cn.MachineNumber, 65535))//Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all) //{ // this.device.OnConnected += new zkemkeeper._IZKEMEvents_OnConnectedEventHandler(OnConnected); //} } else { device.GetLastError(ref idwErrorCode); Util.LogHelper.WriteLog(string.Format("Unable to connect the device, ErrorCode={0}", idwErrorCode.ToString())); } return(isConnected); }
/// <summary> /// 确认 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { button1_Click(null, null); if (!isConnection) { return; } Entity.Connection connectionModel = new Entity.Connection(); connectionModel.Database = cbbServer.Text; connectionModel.ID = Guid.NewGuid(); connectionModel.Name = cbbServer.Text + "(Oracle)"; connectionModel.ConnectionString = connstr; connectionModel.DbType = DataBaseType.Oracle; Utils.AddConnection(connectionModel); this.DialogResult = DialogResult.OK; this.Close(); }
/// <summary> /// 添加 /// </summary> /// <param name="conection"></param> public static void AddConnection(Entity.Connection conection) { XmlDocument doc = getXmlDocument(); XmlNode root = doc.SelectSingleNode("servers"); XmlElement xe = doc.CreateElement("server"); xe.SetAttribute("id", conection.ID.ToString()); xe.SetAttribute("name", conection.Name); xe.SetAttribute("database", conection.Database); xe.SetAttribute("dbtype", conection.DbType.ToString()); XmlElement xe1 = doc.CreateElement("connectionstring"); XmlCDataSection cdata = doc.CreateCDataSection(conection.ConnectionString); xe1.AppendChild(cdata); xe.AppendChild(xe1); root.AppendChild(xe); doc.Save(DatabaseconfigPath); }