public static void DeleteUserResLock(string userempid) { string empname = GetEmpName(Convert.ToInt32(userempid)); SqlCommand cmd = PmConnections.SchCmd(); cmd.CommandText = "DELETE FROM wapResLockState WHERE LockedPerson = '" + empname + "'"; 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); } }
/// <summary> /// 获取当前设备的DayShift /// </summary> /// <param name="resName"></param> /// <returns></returns> public static int GetDayShift(string resName) { SqlCommand cmd = PmConnections.SchCmd(); cmd.CommandText = "SELECT pmResName,shiftStartEndTime,dayShift FROM User_MesDailyData where sysID = " + PmUser.UserSysID + " and pmResName = '" + resName + "' and mesdailydate ='" + GetDailyDate(resName).Date + "' order by dayShift"; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dtshift = new DataTable(); da.Fill(dtshift); dtshift = dtshift.DefaultView.ToTable(true); cmd.Connection.Close(); if (dtshift.Rows.Count > 0) { if (dtshift.Rows.Count == 1) { return(Convert.ToInt32(dtshift.Rows[0]["dayShift"])); } else { DataTable dtstarthours = new DataTable(); dtstarthours.Columns.Add("WorkShift"); dtstarthours.Columns.Add("StartHour"); dtstarthours.Columns.Add("EndHour"); for (int i = 0; i < dtshift.Rows.Count; i++) { DataRow dr = dtstarthours.NewRow(); if (i < dtshift.Rows.Count - 1) { dr[0] = dtshift.Rows[i]["dayShift"]; dr[1] = dtshift.Rows[i]["shiftStartEndTime"].ToString().Split(',')[0].Split(':')[0]; dr[2] = dtshift.Rows[i + 1]["shiftStartEndTime"].ToString().Split(',')[0].Split(':')[0]; } else { dr[0] = dtshift.Rows[i]["dayShift"]; dr[1] = dtshift.Rows[i]["shiftStartEndTime"].ToString().Split(',')[0].Split(':')[0]; dr[2] = dtshift.Rows[0]["shiftStartEndTime"].ToString().Split(',')[0].Split(':')[0]; } dtstarthours.Rows.Add(dr); } int nowhour = DateTime.Now.Hour; int dayshift = -1; for (int i = 0; i < dtstarthours.Rows.Count; i++) { int calstart = Convert.ToInt32(dtstarthours.Rows[i][1]); int calend = Convert.ToInt32(dtstarthours.Rows[i][2]); if (calstart < calend) { if (calstart <= nowhour && calend > nowhour) { dayshift = Convert.ToInt32(dtstarthours.Rows[i][0]); break; } else { continue; } } else { if (calstart <= nowhour || calend > nowhour) { dayshift = Convert.ToInt32(dtstarthours.Rows[i][0]); break; } else { continue; } } } return(dayshift); } } else { return(-1); } }