Example #1
0
        protected bool SaveAttachment(string usernumber, string filName, string extension, string docKind, string callRefNo, string attachedBlob)
        {
            var usaname    = Session["username"].ToString();
            int granttype  = 0;
            var userNumber = "";
            var myyearP    = "";
            var myquarter  = "";
            var prjct      = "";

            if (ddlAccountType.SelectedIndex == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "anything",
                                                        "alert('Please Select Project first');", true);
                return(false);
            }
            else
            {
                prjct = ddlAccountType.SelectedItem.Text;
            }

            if (ddlYears.SelectedIndex == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "anything", "alert('Please Choose Year');",
                                                        true);

                return(false);
            }
            else
            {
                myyearP = ddlYears.SelectedItem.Text;
            }

            if (ddlQuarter.SelectedIndex == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "anything",
                                                        "alert('Please Choose Quarter');", true);
                return(false);
            }
            else
            {
                myquarter = ddlQuarter.SelectedItem.Text;
            }

            var sessx = Session["reportformUser"].ToString();

            switch (sessx)
            {
            case "iamGrantee":
                granttype  = 0;
                userNumber =
                    nav.grantees_Register.ToList()
                    .Where(u => u.Organization_Username == Session["username"].ToString())
                    .Select(u => u.No)
                    .SingleOrDefault();
                break;

            case "iamStudent":
                granttype  = 1;
                userNumber =
                    nav.studentsRegister.ToList()
                    .Where(u => u.Username == Session["username"].ToString())
                    .Select(u => u.No)
                    .SingleOrDefault();
                break;

            case "iamConsult":
                granttype  = 2;
                userNumber =
                    nav.myConsultants.ToList()
                    .Where(u => u.Organization_Username == Session["username"].ToString())
                    .Select(u => u.No)
                    .SingleOrDefault();
                break;
            }

            var credentials = new NetworkCredential(ConfigurationManager.AppSettings["W_USER"],
                                                    ConfigurationManager.AppSettings["W_PWD"], ConfigurationManager.AppSettings["DOMAIN"]);

            string docType = "";

            if ((extension == ".jpg") || (extension == ".jpeg") || (extension == ".png"))
            {
                docType = "Picture";
            }
            else if ((extension == ".pdf"))
            {
                docType = "PDF";
            }
            if ((extension == ".doc") || (extension == ".docx"))
            {
                docType = "Word Document";
            }
            if (extension == ".xlsx")
            {
                docType = "Excel Document";
            }
            //try
            //{
            Portals sup = new Portals {
                Credentials = credentials, PreAuthenticate = true
            };

            if (sup.FnAttachReportForms(userNumber, docType, filName, granttype, docKind, usaname, prjct, callRefNo, attachedBlob, myyearP, myquarter) == true)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "anything",
                                                        "alert('Document: '" + filName + "'successfully uploaded!');", true);
                return(true);
            }
            return(false);

            //}
            //catch (Exception r)
            //{
            //    KCDFAlert.ShowAlert(r.Message);
            //}
        }