private string GetID(string agr) { string id = agr.TrimEnd('S'); int IDtemp; if (int.TryParse(id.Split('.')[0], out IDtemp)) { id = IDtemp.ToString(); if (id.Length < 3) { id = IDtemp.ToString("000"); } } return(id); }
protected void Page_Load(object sender, EventArgs e) { Session["ErrIsertForm"] = "";//משתנה שיציג הודעה ללקוח אם סיסמה או שם משתמש קיימים if (Session["userNameT"] == null) { Response.Redirect("loginT.aspx"); } string subject = "", answ = "", diff = "", path, location, sqldo; // חייב תיקון דחוף! // יגריל וייצור טבלאת תלמיד וישים תרגיגילים מהמאגר בנושא if (Request.Form["btnUpload"] != null) { subject = Request.Form["subject"]; answ = Request.Form["answ"]; diff = Request.Form["diff"]; Session["ErrIsertForm"] = diff + " " + answ + " " + subject; path = "~/t/" + subject + "/"; if (subject == "0" || answ == "" || diff == "0") { Session["ErrIsertForm"] = "נתונים לא מולאו כשורה"; // Response.Redirect("form.aspx"); } else { if (!IsPostBack) { path = "~/t/" + subject + "/"; string[] filePaths = Directory.GetFiles(Server.MapPath(path)); List <ListItem> files = new List <ListItem>(); foreach (string filePath in filePaths) { string fileName = Path.GetFileName(filePath); files.Add(new ListItem(fileName, path + fileName)); } } else { path = "~/t/" + subject + "/"; } string fileName7 = "db1.mdb"; //SQLSTUF START string sql = "select * from TAT" + subject; DataTable dtat; dtat = MyAdoHelper.ExecuteDataTable(fileName7, sql); string sql2 = "select * from users "; DataTable dt1; dt1 = MyAdoHelper.ExecuteDataTable(fileName7, sql2); int IDtemp; string ID; if (dtat.Rows.Count == 0) { ID = subject + "0"; } else { string lastID = dtat.Rows[dtat.Rows.Count - 1][0].ToString(); IDtemp = Int32.Parse(lastID); IDtemp++; ID = IDtemp.ToString(); } // SQL STUF END string uploadFolder = Request.PhysicalApplicationPath + "t/" + subject + "/"; if (FileUpload1.HasFile) { string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName); string extension = Path.GetExtension(FileUpload1.PostedFile.FileName); FileUpload1.SaveAs(uploadFolder + ID + extension); location = "t/" + subject + "/" + ID + extension; sqldo = "insert into TAT" + subject + "(ID, location, answ, diff)values('" + ID + "','" + location + "','" + answ + "','" + diff + "');"; MyAdoHelper.DoQuery(fileName7, sqldo); Response.Redirect(Request.Url.AbsoluteUri); } } } }