Beispiel #1
0
    private int InsertDocument()
    {
        DocumentBL _objDocBL = new DocumentBL();
        int        res       = 0;

        if (fuDoc.HasFile)
        {
            HttpPostedFile file     = fuDoc.PostedFile;
            int            filesize = file.ContentLength;
            //if (filesize <= 1048576)
            //{
            List <HttpPostedFile> lst = fuDoc.PostedFiles.ToList();
            for (int i = 0; i < lst.Count; i++)
            {
                string inFilename = lst[i].FileName;
                string strfile    = Path.GetExtension(inFilename);
                string date       = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                var    folder     = Server.MapPath("~/ClientDocuments/" + Session["SAID"].ToString() + "/" + ViewState["FoldertName"].ToString() + "/" + txtSAID.Text.Trim());
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }
                string fileName = date + strfile;
                fuDoc.SaveAs(Path.Combine(folder, fileName));

                if (File.Exists(Path.Combine(folder, hfDocumentName.Value.ToString())))
                {
                    //delete file in folder
                    File.Delete(Path.Combine(folder, hfDocumentName.Value.ToString()));
                }
                int DocID = 0;
                if (Convert.ToInt32(hfID.Value) == 0)
                {
                    DocID = _objDocBL.InsertDocType(txtDocumentType.Text);
                }
                else
                {
                    DocID = Convert.ToInt32(hfID.Value);
                }
                DocumentBO DocumentEntity = new DocumentBO
                {
                    DocId         = Convert.ToInt32(hfDocID.Value),
                    ReferenceSAID = Session["SAID"].ToString(),
                    SAID          = hfSAID.Value.ToString(),
                    UIC           = hfUIC.Value.ToString(),
                    Document      = fileName,
                    DocumentName  = inFilename,
                    //DocType = Convert.ToInt32(ddlDocType.SelectedValue),
                    DocType    = DocID,
                    ClientType = Request.QueryString["t"] != null?Convert.ToInt32(ObjDec.Decrypt(Request.QueryString["t"])) : 0,
                                     AdvisorID = 0,
                                     Status    = 1,
                };

                if (btnSubmit.Text == "Update")
                {
                    res = _objDocBL.DocumentManager(DocumentEntity, 'u');
                }
                else
                {
                    res = _objDocBL.DocumentManager(DocumentEntity, 'i');
                }
            }
            lblSizeError.Text = "";
            //}
            //else
            //{
            //    lblSizeError.ForeColor = System.Drawing.Color.Red;
            //    lblSizeError.Text = "Sorry,the document size should be less than 1MB";
            //}
        }
        return(res);
    }