public Session createSessionFromDataReader(MySqlDataReader dr) { Session session; String userLogin; int code = 0; DateTime date; String dateString; Video video; String mode; String comment; float evaluetion; if (dr.Equals(DBNull.Value)) return null; if (!dr["comment"].Equals(DBNull.Value)) comment = dr.GetString("comment"); else comment = ""; if (dr["code"].Equals(DBNull.Value)) return null; code = dr.GetInt32("code"); if (dr["userLogin"].Equals(DBNull.Value)) return null; userLogin = dr.GetString("userLogin"); if (!dr["evaluetion"].Equals(DBNull.Value)) evaluetion = (float)Convert.ToDouble(dr.GetDecimal("evaluetion")); else evaluetion = 0; DaoVideo daoVideo = new DaoVideo(); daoVideo.openConnection(); video = daoVideo.getVideoByCode(dr.GetInt32("videoCode")); date = dr.GetDateTime("date"); dateString = date.Day + "/" + date.Month + "/" + date.Year; if (!dr["modeCode"].Equals(DBNull.Value)) mode = getModeByCode(dr.GetInt32("modeCode")); else mode = ""; session = new Session(userLogin, video, dateString, evaluetion, mode, comment); session.setCode(code); return session; }
public Boolean insertSession(Session session, Type type, String errorMethod) { int modeCode; modeCode = getModeCode(session.getMode()); String[] dateStrings = new String[2]; String[] videoCodeStrings = new String[2]; String[] userLoginStrings = new String[2]; String[] evaluetionStrings = new String[2]; String[] modeStrings = new String[2]; String[] commentStrings = new String[2]; if (session.getDate() != null) { dateStrings[0] = "date"; dateStrings[1] = "'" + session.getDate() + "'"; } else return false; if (session.getVideoCode() != -1) { videoCodeStrings[0] = ", videoCode"; videoCodeStrings[1] = ", " + session.getVideoCode(); } else return false; if (!session.getUserLogin().Equals("")) { userLoginStrings[0] = ", userLogin"; userLoginStrings[1] = ", '" + session.getUserLogin() + "'"; } else return false; if (session.getEvaluetion() != -1) { evaluetionStrings[0] = ", evaluetion"; evaluetionStrings[1] = ", " + session.getEvaluetion().ToString().Replace(",",".") + ""; } if (modeCode != 0) { modeStrings[0] = ", modeCode"; modeStrings[1] = ", " + modeCode; } if (!session.getComment().Equals("")) { commentStrings[0] = ", comment"; commentStrings[1] = ", '" + session.getComment() + "'"; } String insertSessionString = "INSERT INTO SESSION (" + dateStrings[0] + videoCodeStrings[0] + userLoginStrings[0] + evaluetionStrings[0] + modeStrings[0] + commentStrings[0] + ") VALUES (" + dateStrings[1] + videoCodeStrings[1] + userLoginStrings[1] + evaluetionStrings[1] + modeStrings[1] + commentStrings[1] + ")"; // MessageBox.Show(insertSessionString); Boolean insertionResult = executeNonQuery(insertSessionString, type, errorMethod, "Insert session failed."); session.setCode(getLastVideoCode()); return insertionResult; }