コード例 #1
0
ファイル: survey.aspx.cs プロジェクト: kDuffy93/drwSurvey
        protected void btnUpload_Click1(object sender, EventArgs e)
        {
            var date = DateTime.Now.AddMinutes(-240).ToString();

            Session["surveySubmitTime"] = date;
            if (fuMain.HasFile)
            {
                using (DefaultConnectionEF conn = new DefaultConnectionEF())
                {
                    IList<HttpPostedFile> collection = fuMain.PostedFiles;

                    foreach (HttpPostedFile ia in collection)
                    {
                        Picture p = new Picture();

                        string imgName = ia.FileName.ToString();
                        int imageLength = ia.ContentLength;
                        string imageType = ia.ContentType;

                        var binaryImagedata = new byte[imageLength];
                        ia.InputStream.Read(binaryImagedata, 0, imageLength);

                        var date1 = Convert.ToDateTime(Session["surveySubmitTime"]);
                        var date1String = date1.ToString("MM.dd.yyyy.HH.mm.ss");

                        string imgPath = ("surveyImages/mainPics/" +
                            "eqid&" + Convert.ToInt32(Request.QueryString["selectedEquipment"].ToString()) + "dc_" + date1String + "image" +  ".jpg");

                       ia.SaveAs(Server.MapPath(("/admin/surveyImages/mainPics/" +
                             "eqid&" + Convert.ToInt32(Request.QueryString["selectedEquipment"].ToString()) + "dc_" + date1String + "image" + ".jpg")));

                        p.URL= imgPath;
                        p.DateSubmited = date1;
                        p.equipment_ID = Convert.ToInt32(Request.QueryString["selectedEquipment"].ToString());

                        p.name = imgName;

                        imgMain.ImageUrl = imgPath;
                        conn.Pictures.Add(p);

                    }

                    imgMain.Visible = true;
                    btnUpload.Visible = false;
                    fuMain.Visible = false;

                    tblSurvey.Visible = true;

                    input2.Visible = true;
                    hidenPic.Visible = true;
                    conn.SaveChanges();

                }
            }
        }
コード例 #2
0
ファイル: survey.aspx.cs プロジェクト: kDuffy93/drwSurvey
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Button button = (Button)sender;
            TableCell cell = button.Parent as TableCell;
            TableRow row = cell.Parent as TableRow;
            Table table = row.Parent as Table;
            DateTime dateAndTime = Convert.ToDateTime(Session["surveySubmitTime"]);
            foreach (TableRow workingRow in table.Rows)
            {
                if (workingRow.GetType() == typeof(TableHeaderRow))
                {
                    using (DefaultConnectionEF conn = new DefaultConnectionEF())
                    {
                        string currentHeading = "";
                        int currentHeadingId = 0;
                        foreach (TableCell currentCell in workingRow.Cells)
                        {
                            if (currentCell == workingRow.Cells[0])
                            {
                                TableHeaderCell c = (TableHeaderCell)currentCell;
                                currentHeading = c.Text;
                                currentHeadingId = (from h in conn.Headings
                                                    where h.Heading1 == currentHeading
                                                    select h.Heading_ID).FirstOrDefault();

                            }

                            foreach (Control control in currentCell.Controls)
                            {
                                if (control.GetType() == typeof(FileUpload))
                                {
                                    FileUpload fu = (FileUpload)control;
                                    if (fu.HasFile == true)
                                    {
                                        IList<HttpPostedFile> collection = fu.PostedFiles;
                                        int picNumber = 1;
                                        var count = fu.PostedFiles.Count();
                                        if(count >= 2)
                                        {

                                        }
                                        foreach (HttpPostedFile ia in collection)
                                        {

                                            Picture p = new Picture();
                                            var date = Session["surveySubmitTime"].ToString();
                                            string imgName = ia.FileName.ToString();
                                            int imageLength = ia.ContentLength;
                                            string imageType = ia.ContentType;

                                            var binaryImagedata = new byte[imageLength];
                                            ia.InputStream.Read(binaryImagedata, 0, imageLength);

                                            var date1 = Convert.ToDateTime(Session["surveySubmitTime"]);
                                            var date1String = date1.ToString("MM.dd.yyyy.HH.mm.ss");

                                            string imgPath = ("surveyImages/surveyPics/" + "heading-" + currentHeadingId + "eqid&" + Convert.ToInt32(Request.QueryString["selectedEquipment"].ToString()) + "dc_" + date1String + "image" + picNumber + ".jpg");
                                            ia.SaveAs(Server.MapPath(("/admin/surveyImages/surveyPics/" + "heading-" + currentHeadingId + "eqid&" + Convert.ToInt32(Request.QueryString["selectedEquipment"].ToString()) + "dc_" + date1String + "image" + picNumber + ".jpg")));
                                            p.URL = imgPath;
                                            p.DateSubmited = date1;
                                            p.equipment_ID = Convert.ToInt32(Request.QueryString["selectedEquipment"].ToString());
                                            p.heading_ID = currentHeadingId;

                                            p.name = imgName;

                                            imgMain.ImageUrl = imgPath;
                                            conn.Pictures.Add(p);
                                            picNumber++;

                                        }

                                    }

                                }// fu

                            }

                        }
                        conn.SaveChanges();
                    }
                }
                else
                {
                    using (DefaultConnectionEF conn = new DefaultConnectionEF())
                    {
                        var currentHeadingID = 0;
                        var currentQuestionID = 0;

                        Result r = new Result();

                        // set date completed
                        r.Date_Completed = dateAndTime;
                        //save white equipment it is

                        r.Equipment_ID = Convert.ToInt32(Request.QueryString["selectedEquipment"].ToString());
                        foreach (TableCell currentCell in workingRow.Cells)
                        {
                            if (currentCell == workingRow.Cells[0])
                            {
                                TableCell t = (TableCell)currentCell;
                                int indexOfUnderscore;
                                try
                                {
                                    indexOfUnderscore = t.ID.IndexOf("_");
                                    if (indexOfUnderscore == -1)
                                    {

                                    }
                                }
                                catch (NullReferenceException)
                                {
                                    continue;
                                }
                                int indexOfNumSign = t.ID.IndexOf("=") + 1;
                                // set question ID
                                r.Question_ID = Convert.ToInt32(t.ID.Substring(0, indexOfUnderscore));
                                currentQuestionID = Convert.ToInt32(t.ID.Substring(0, indexOfUnderscore));
                                //set heading id
                                r.heading_ID = Convert.ToInt32(t.ID.Substring(indexOfNumSign));
                                currentHeadingID = Convert.ToInt32(t.ID.Substring(indexOfNumSign));

                            }
                            foreach (Control control in currentCell.Controls)
                            {
                                if (control.GetType() == typeof(RadioButtonList))
                                {
                                    RadioButtonList rbl = (RadioButtonList)control;
                                    if (rbl.SelectedValue == "true")
                                    {
                                        r.Response = true;
                                    }
                                    else if (rbl.SelectedValue == "false")
                                    {
                                        r.Response = false;
                                    }
                                } // check control to see if its a rbl
                                if (control.GetType() == typeof(TextBox))
                                {
                                    TextBox txt = (TextBox)control;
                                    if (txt.ID == (r.Question_ID + "_Deficency_H=" + r.heading_ID))
                                    {
                                        r.deficiency_defect = txt.Text;
                                    } // checks if txt box is a defect
                                    else if (txt.ID == (r.Question_ID + "_ActionPlan_H=" + r.heading_ID))
                                    {
                                        r.Action_plan = txt.Text;
                                    } //checks if txtbox is action plan
                                }//checks for txtbox

                                if (control.GetType() == typeof(FileUpload))
                                {
                                    FileUpload fu = (FileUpload)control;
                                    if (fu.HasFile == true)
                                    {
                                        IList<HttpPostedFile> collection = fu.PostedFiles;
                                        int picNumber = 1;
                                        var count = fu.PostedFiles.Count();
                                        if (count >= 2)
                                        {

                                        }
                                        foreach (HttpPostedFile ia in collection)
                                        {
                                            Picture p = new Picture();
                                            var date = Session["surveySubmitTime"].ToString();
                                            string imgName = ia.FileName.ToString();
                                            int imageLength = ia.ContentLength;
                                            string imageType = ia.ContentType;

                                            var binaryImagedata = new byte[imageLength];
                                            ia.InputStream.Read(binaryImagedata, 0, imageLength);
                                            var date1 = Convert.ToDateTime(Session["surveySubmitTime"]);
                                            var date1String = date1.ToString("MM.dd.yyyy.HH.mm.ss");

                                            string imgPath = ("surveyImages/surveyPics/" + "qid~" + r.Question_ID + "heading-" + r.heading_ID + "eqid&" + r.Equipment_ID + "dc_" + date1String + "image" + picNumber + ".jpg");

                                            ia.SaveAs(Server.MapPath(("/admin/surveyImages/surveyPics/" + "qid~" + r.Question_ID + "heading-" + r.heading_ID + "eqid&" + r.Equipment_ID + "dc_" + date1String + "image" + picNumber + ".jpg")));

                                            p.URL = imgPath;
                                            p.DateSubmited = date1;
                                            p.equipment_ID = Convert.ToInt32(Request.QueryString["selectedEquipment"].ToString());
                                            p.heading_ID = currentHeadingID;
                                            p.question_ID = currentQuestionID;

                                            p.name = imgName;
                                            imgMain.ImageUrl = imgPath;

                                            conn.Pictures.Add(p);

                                            picNumber++;

                                        }

                                    }
                                }// if file upload = true

                            } //foreach control

                        } // checks to see if workign row is not a header row
                        conn.Results.Add(r);
                        conn.SaveChanges();
                    } //default conn
                } //for each table row
                btnNewSurvey.Visible = true;
            }
        }