Ejemplo n.º 1
0
    protected void lnkAddAttachment_Click(object sender, EventArgs e)
    {
        lblMessage.Text = "";
        lblmsg1.Text    = "";
        lblmsg2.Text    = "";
        lblmsg3.Text    = "";
        string    AttachmentName = "";
        string    FileName       = "";
        int       AttachmentType;
        int       RetVal = 0;
        DataTable dt     = new DataTable();

        dt = objUploadFilesize.Get_Module_FileUpload("OPS_");
        int Sample_ID = UDFLib.ConvertToInteger(hdnSample_ID.Value);

        if (dt.Rows.Count > 0)
        {
            string datasize = dt.Rows[0]["Size_KB"].ToString();
            if (FileUpload_1.HasFile)
            {
                if (FileUpload_1.PostedFile.ContentLength < Int32.Parse(dt.Rows[0]["Size_KB"].ToString()) * 1024)
                {
                    AttachmentName = Path.GetFileName(FileUpload_1.FileName);
                    AttachmentType = UDFLib.ConvertToInteger(ddlType1.SelectedValue);
                    FileName       = "BNK_" + Guid.NewGuid().ToString() + Path.GetExtension(AttachmentName);

                    FileUpload_1.SaveAs(MapPath("~/Uploads/BunkerAnalysis/") + FileName);
                    if (AttachmentType == 1)
                    {
                        FileUpload_1.SaveAs(MapPath("~/Uploads/Technical/") + FileName);
                    }

                    RetVal = BLL_OPS_BunkerAnalysis.Insert_LO_SampleAttachment(Sample_ID, AttachmentType, AttachmentName.Replace(Path.GetExtension(AttachmentName), ""), FileName, GetSessionUserID());
                }
                else
                {
                    lblmsg1.Text = datasize + " KB File size exceeds max limit";
                }
            }
            if (FileUpload_2.HasFile)
            {
                if (FileUpload_2.PostedFile.ContentLength < Int32.Parse(dt.Rows[0]["Size_KB"].ToString()) * 1024)
                {
                    AttachmentName = Path.GetFileName(FileUpload_2.FileName);
                    AttachmentType = UDFLib.ConvertToInteger(ddlType2.SelectedValue);
                    FileName       = "BNK_" + Guid.NewGuid().ToString() + Path.GetExtension(AttachmentName);

                    FileUpload_2.SaveAs(MapPath("~/Uploads/BunkerAnalysis/") + FileName);
                    if (AttachmentType == 1)
                    {
                        FileUpload_2.SaveAs(MapPath("~/Uploads/Technical/") + FileName);
                    }

                    RetVal = BLL_OPS_BunkerAnalysis.Insert_LO_SampleAttachment(Sample_ID, AttachmentType, AttachmentName.Replace(Path.GetExtension(AttachmentName), ""), FileName, GetSessionUserID());
                }
                else
                {
                    lblmsg2.Text = datasize + " KB File size exceeds max limit";
                }
            }
            if (FileUpload_3.HasFile)
            {
                if (FileUpload_2.PostedFile.ContentLength < Int32.Parse(dt.Rows[0]["Size_KB"].ToString()) * 1024)
                {
                    AttachmentName = Path.GetFileName(FileUpload_3.FileName);
                    AttachmentType = UDFLib.ConvertToInteger(ddlType3.SelectedValue);
                    FileName       = "BNK_" + Guid.NewGuid().ToString() + Path.GetExtension(AttachmentName);

                    FileUpload_3.SaveAs(MapPath("~/Uploads/BunkerAnalysis/") + FileName);
                    if (AttachmentType == 1)
                    {
                        FileUpload_3.SaveAs(MapPath("~/Uploads/Technical/") + FileName);
                    }

                    RetVal = BLL_OPS_BunkerAnalysis.Insert_LO_SampleAttachment(Sample_ID, AttachmentType, AttachmentName.Replace(Path.GetExtension(AttachmentName), ""), FileName, GetSessionUserID());
                }
                else
                {
                    lblmsg3.Text = datasize + " KB File size exceeds max limit";
                    return;
                }
                //    }
                //        string js = "";
                //        if (RetVal > 0)
                //        {
                //            js = "alert('Attachment Uploaded!!');";
                //        }

                //        js += "window.parent.closeDiv('dvAttachments');";

                //        ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", js, true);
                //    }

                //}
            }
        }

        else
        {
            string js2 = "alert('Upload size not set!');";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "alert9", js2, true);
            //string js2 = "Upload size not set";
            //ScriptManager.RegisterStartupScript(this, this.GetType(), "msg2", js2, true);
        }
    }