protected void DoAddSubmitPromotion() { Promotion p = new Promotion(); // validate data p._promotionName = Request["promotion_name"]; p._promotionDesc = Request["promotion_desc"]; p._cost = Int32.Parse(Request["cost"]); p._isActive = Request["is_active"] != null ? true : false; // read selected course ArrayList idList = new ArrayList(); for (int i = 0; i < Request.Form.AllKeys.Length; i++) { if (Request.Form.AllKeys[i].StartsWith("course")) { string s = Request.Form.AllKeys[i].Substring(6); idList.Add(s); } } p._courses = new Course[idList.Count]; int n = 0; foreach (string id in idList) { try { Course c = new Course(); c._courseID = Int32.Parse(id); p._courses[n++] = c; } catch (Exception e) { Console.WriteLine(e.StackTrace); } } // Save to DB DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); p.AddToDB(db); db.Close(); }