/// <summary> /// 写入LOG /// </summary> /// <param name="userempid">用户id</param> /// <param name="ip">ip地址</param> /// <param name="model">事件类型</param> /// <param name="logmessage">事件详情</param> /// <param name="webinfo">用户手机版本</param> public static void WriteUserLog(string userempid, string ip, string model, string logmessage, string webinfo) { SqlCommand cmd = PmConnections.CtrlCmd(); string empname = PublicFunc.GetEmpName(Convert.ToInt32(userempid)); cmd.CommandText = "INSERT INTO wapUserlog (empid,empname,ipAddress,model,logTime,logMessage,webinfomation) VALUES ('" + userempid + "','" + empname + "','" + ip + "','" + model + "','" + DateTime.Now + "','" + logmessage + "','" + webinfo + "')"; cmd.ExecuteNonQuery(); cmd.Connection.Close(); }
/// <summary> /// 获取当前表的最大ID,适用于表格不具有自增长字段 /// </summary> /// <param name="serverdb">S:schedule数据库;M:modeler数据库;C:Control数据库</param> /// <param name="tablename">数据库名称</param> /// <param name="key">数据库的KEY字段</param> /// <returns></returns> public static int GetMaxUID(string serverdb, string tablename, string key) { SqlCommand cmd = null; if (serverdb.ToUpper() == "S") { cmd = PmConnections.SchCmd(); } else if (serverdb.ToUpper() == "M") { cmd = PmConnections.ModCmd(); } else if (serverdb.ToUpper() == "C") { cmd = PmConnections.CtrlCmd(); } //判断数据库是否为空 cmd.CommandText = "SELECT COUNT(" + key + ") as R FROM " + tablename; SqlDataReader rd = cmd.ExecuteReader(); rd.Read(); int R = Convert.ToInt32(rd[0]); rd.Close(); if (R == 0) { return(1); } else { cmd.CommandText = "SELECT MAX(" + key + ") AS maxid FROM " + tablename; rd = cmd.ExecuteReader(); int maxid; if (rd.Read()) { maxid = Convert.ToInt32(rd[0]) + 1; } else { maxid = 1; } rd.Read(); return(maxid); } }