/// <summary> /// 获取这个设备当前时间的Dailydate /// </summary> /// <param name="resname"></param> /// <returns></returns> public static DateTime GetDailyDate(string resname) { if (string.IsNullOrWhiteSpace(resname)) { return(DateTime.MinValue); } else { string realResname; if (resname.Contains(":")) { realResname = resname.Split(':')[0]; } else { realResname = resname; } SqlCommand cmd = PmConnections.ModCmd(); cmd.CommandText = "SELECT a.resourceName,b.shiftStartTime,c.fromHour,c.toHour,c.workdayInWeek,c.workshift " + "FROM objResource a,objCalendar b,objCalendarWorking c " + "WHERE a.calendarUID = c.calendarUID and b.calendarUID = c.calendarUID and a.resourceName = '" + realResname + "' and a.sysID = '" + PmUser.UserSysID + "'" + "ORDER by c.workdayInWeek,c.workShift"; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dtshift = new DataTable(); da.Fill(dtshift); cmd.Connection.Close(); if (dtshift.Rows.Count > 0) { int calstarthour = Convert.ToInt32(dtshift.Rows[0]["shiftStartTime"].ToString().Split(',')[0].Split(':')[0]); int nowhour = DateTime.Now.Hour; int[] Day = new int[] { 0, 1, 2, 3, 4, 5, 6 }; int week = Day[Convert.ToInt32(DateTime.Now.DayOfWeek.ToString("d"))]; DataRow[] drselect = dtshift.Select("workdayInWeek = '" + week + "' and workshift = 1"); int realstarthour = calstarthour + Convert.ToInt32(drselect[0]["fromHour"]); if (nowhour < realstarthour) { return(DateTime.Now.AddDays(-1)); } else { return(DateTime.Now); } } else { return(DateTime.MinValue); } } }
/// <summary> /// 获取用户名称 /// </summary> /// <param name="empID">用户ID</param> /// <returns>用户名称</returns> public static string GetEmpName(int empID) { SqlCommand cmd = PmConnections.ModCmd(); cmd.CommandText = "SELECT empName FROM wapEmpList WHERE empID = '" + empID + "'"; SqlDataReader rd = cmd.ExecuteReader(); string empname = string.Empty; if (rd.Read()) { empname = rd[0].ToString(); } rd.Close(); cmd.Connection.Close(); return(empname); }
/// <summary> /// 获取当前sysid的显示名称 /// </summary> /// <param name="sysID"></param> /// <returns></returns> public static string GetSysName(int sysID) { SqlCommand cmd = PmConnections.ModCmd(); cmd.CommandText = "SELECT " + PmSettings.SysNameColName + " FROM pmSysList WHERE sysID = '" + sysID + "'"; SqlDataReader rd = cmd.ExecuteReader(); string sysname = string.Empty; if (rd.Read()) { sysname = rd[0].ToString(); } rd.Close(); cmd.Connection.Close(); return(sysname); }
/// <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); } }