Exemple #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        this.RequirePermission(Affinity.RolePermission.AdminSystem);
        //this.Master.SetLayout("Administration Dashboard", MasterPage.LayoutStyle.ContentOnly);

        if (Request["a"].Equals("delete"))
        {
            Affinity.Attachment att = new Affinity.Attachment(this.phreezer);
            att.Load(int.Parse(Request["id"]));
            int orderId = att.Request.Order.Id;

            string fileName = att.Filepath;
            string filePath = Server.MapPath("./") + "attachments/" + fileName;

            try
            {
                File.Delete(filePath);
                log.Debug("Deleted attachment #" + att.Id + ": " + filePath);
            }
            catch (Exception ex)
            {
                log.Error("Unable attachment #" + att.Id + ": " + filePath);
            }

            att.Delete();
            Affinity.UploadLogCriteria ulc = new Affinity.UploadLogCriteria();
            ulc.AttachmentID = att.Id;
            ulc.OrderID      = orderId;

            Affinity.UploadLogs uplogs = new Affinity.UploadLogs(this.phreezer);
            uplogs.Query(ulc);
            int cnt = uplogs.Count;

            for (int i = 0; i < cnt; i++)
            {
                Affinity.UploadLog ul = (Affinity.UploadLog)uplogs[i];
                ul.Delete();
            }

            //Affinity.UploadLogs ulc = new Affinity.UploadLogs(this.phreezer);
            this.Redirect("AdminOrder.aspx?id=" + orderId + "&feedback=Attachment+Deleted");
        }
        else
        {
            this.Master.ShowFeedback("Unknown Action", MasterPage.FeedbackType.Error);
        }
    }
Exemple #2
0
    protected void saveAgentExaminationForm(bool submitted, Affinity.Account me)
    {
        //submitted = false;
        // Declare objects:
        //ZfAPIClass oZfAPI = new ZfAPIClass();
        //ZfLib.UserSession oUserSession;
        //ZfLib.Messages oMessages;
        //ZfLib.Message oMessage;

        try
        {
            // make this an attachment to the request

            string ext = ".pdf";
            //string fileName = "req_att_" + request.Id + "_" + DateTime.Now.ToString("yyyyMMddhhss") + "." + ext.Replace(".","");
            string commitment = txtCommitmentNumber.Text;
            string fileName   = "Agent_Exam_Sheet_for_AFF-" + ((commitment.Equals(""))? request.OrderId.ToString() : commitment.Replace("AFF", ""));
            string suffix     = "_001";

            int    idx          = 1;
            string attID        = "0";
            string contentsHTML = "";

            if (submitted)
            {
                while (File.Exists(Server.MapPath("./") + "attachments/" + fileName + suffix + ext))
                {
                    idx++;
                    string idxstr = idx.ToString();
                    if (idxstr.Length == 1)
                    {
                        suffix = "_00" + idxstr;
                    }
                    else if (idxstr.Length == 2)
                    {
                        suffix = "_0" + idxstr;
                    }
                    else
                    {
                        suffix = "_" + idxstr;
                    }
                }
                fileName = fileName + suffix + ext;

                //string contentsTXT = "";

                using (FileStream fs = new FileStream(Server.MapPath("./") + "AgentExaminationForm.html", FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 8, true))
                {
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        // Read the file using StreamReader class
                        contentsHTML = sr.ReadToEnd();
                    }
                }

                contentsHTML = contentsHTML.Replace("margin-left:46px", "").Replace("txtAgentsName", txtAgentsName.Text).Replace("txtCommitmentNumber", commitment).Replace("txtPropertyVesting", txtPropertyVesting.Text).Replace("txtPropertyAddress", txtPropertyAddress.Text).Replace("txtPropertyCityStateZip", txtPropertyCityStateZip.Text).Replace("txtPropertyCounty", txtPropertyCounty.Text).Replace("txtPIN", txtPIN.Text).Replace("txtPriorYear", txtPriorYear.Text).Replace("txt1stInstallment", txt1stInstallment.Text).Replace("txt2ndInstallment", txt2ndInstallment.Text).Replace("txtCurrentYear", txtCurrentYear.Text).Replace("txtTaxAmount1st", txtTaxAmount1st.Text).Replace("txtTaxAmount2nd", txtTaxAmount2nd.Text).Replace("txtDueDate1st", txtDueDate1st.Text).Replace("txtDueDate2nd", txtDueDate2nd.Text).Replace("txtTaxYearofSoldtaxes", txtTaxYearofSoldtaxes.Text).Replace("txtMortgagesofRecord", txtMortgagesofRecord.Text.Replace("\n", "<br />")).Replace("txtOtherLiensofRecord", txtOtherLiensofRecord.Text.Replace("\n", "<br />")).Replace("txtBuildingLines", txtBuildingLines.Text.Replace("\n", "<br />")).Replace("txtEasements", txtEasements.Text.Replace("\n", "<br />")).Replace("txtDocumentNumbers", txtDocumentNumbers.Text.Replace("\n", "<br />")).Replace("radioCondoAssociationYes", ((radioCondoAssociationYes.Checked) ? " checked='checked'" : "")).Replace("radioCondoAssociationNo", ((radioCondoAssociationNo.Checked) ? " checked='checked'" : "")).Replace("chkSearchPackageReviewedAmendments", ((chkSearchPackageReviewedAmendments.Checked) ? " checked='checked'" : "")).Replace("chkSearchPackageReviewed", ((chkSearchPackageReviewed.Checked) ? " checked='checked'" : "")).Replace("txtAmendments", txtAmendments.Text.Replace("\n", "<br />")).Replace("SIGNATURE", (me.Signature.Equals("")) ? "" : "<img src=\"" + ((Request.Url.Port == 443) ? "https://" : "http://") + Request.Url.Host + "/signatures/" + me.Signature + "\" height=\"50\" border=\"0\">").Replace("DATESTAMP", DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString());

                /*
                 * using (FileStream fs = new FileStream(Server.MapPath("./") + "AgentExaminationForm.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 8, true))
                 * {
                 *      using (StreamReader sr = new StreamReader(fs))
                 *      {
                 *
                 *              // Read the file using StreamReader class
                 *              contentsTXT = sr.ReadToEnd();
                 *      }
                 * }
                 *
                 * contentsTXT = contentsTXT.Replace("txtAgentsName", txtAgentsName.Text).Replace("txtCommitmentNumber", commitment).Replace("txtPropertyVesting", txtPropertyVesting.Text).Replace("txtPropertyAddress", txtPropertyAddress.Text).Replace("txtPropertyCityStateZip", txtPropertyCityStateZip.Text).Replace("txtPropertyCounty", txtPropertyCounty.Text).Replace("txtPIN", txtPIN.Text).Replace("txtPriorYear", txtPriorYear.Text).Replace("txt1stInstallment", txt1stInstallment.Text).Replace("txt2ndInstallment", txt2ndInstallment.Text).Replace("txtCurrentYear", txtCurrentYear.Text).Replace("txtTaxAmount1st", txtTaxAmount1st.Text).Replace("txtTaxAmount2nd", txtTaxAmount2nd.Text).Replace("txtDueDate1st", txtDueDate1st.Text).Replace("txtDueDate2nd", txtDueDate2nd.Text).Replace("txtTaxYearofSoldtaxes", txtTaxYearofSoldtaxes.Text).Replace("txtMortgagesofRecord", txtMortgagesofRecord.Text).Replace("txtOtherLiensofRecord", txtOtherLiensofRecord.Text).Replace("txtBuildingLines", txtBuildingLines.Text).Replace("txtEasements", txtEasements.Text).Replace("txtDocumentNumbers", txtDocumentNumbers.Text).Replace("radioCondoAssociation", ((radioCondoAssociationYes.Checked) ? "Yes" : "No")).Replace("chkSearchPackageReviewedAmendments", ((chkSearchPackageReviewedAmendments.Checked) ? "The search and the search package has been\nreviewed and examined and we have made our determination of insurability and we direct ATS to\nissue the title commitment in accordance with the search package." : "")).Replace("chkSearchPackageReviewed", ((chkSearchPackageReviewed.Checked) ? "The search and the search package\nhas been reviewed and examined and we have made our determination of insurability and we\ndirect ATS to issue the title commitment after making the following amendments." : "")).Replace("txtAmendments", txtAmendments.Text);
                 */
                Affinity.Attachment att = new Affinity.Attachment(this.phreezer);
                att.RequestId   = this.request.Id;
                att.Name        = "AgentExaminationForm.pdf";
                att.PurposeCode = "ExamSheet";
                att.Filepath    = fileName;
                att.MimeType    = ext;
                att.SizeKb      = 0;            // fuAttachment.FileBytes.GetUpperBound() * 1024;

                att.Insert();
                attID = att.Id.ToString();
                //TODO: block any harmful file types

                Affinity.UploadLog ul = new Affinity.UploadLog(this.phreezer);

                ul.AttachmentID    = att.Id;
                ul.AccountID       = this.request.Account.Id;
                ul.UploadAccountID = this.GetAccount().Id;
                ul.OrderID         = this.request.OrderId;
                ul.RequestID       = this.request.Id;

                ul.Insert();
            }

            using (MySqlConnection mysqlCon = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DBConn"].ConnectionString))
            {
                mysqlCon.Open();

                bool   doInsert = true;
                string aefid    = "0";

                using (MySqlCommand cmd1 = new MySqlCommand("SELECT aef_id FROM agent_examination WHERE aef_status = 0 AND aef_account_id = " + this.GetAccount().Id.ToString() + " and aef_request_id = " + this.request.Id.ToString(), mysqlCon))
                {
                    try
                    {
                        MySqlDataReader Reader = cmd1.ExecuteReader();
                        while (Reader.Read()) // this part is wrong somehow
                        {
                            aefid = Reader["aef_id"].ToString();
                        }
                        Reader.Close();
                    }

                    catch (Exception ex)
                    {
                        //MessageBox.Show(ex.Message);
                        Response.Write(ex.Message);
                    }
                }

                DateTime t = DateTime.Now;
                if (aefid.Equals("0"))
                {
                    using (MySqlCommand cmd = new MySqlCommand("INSERT INTO agent_examination (`aef_agents_name`, `aef_commitment_number`, `aef_property_vesting`, `aef_property_address`, `aef_property_city_state_zip`, `aef_property_county`, `aef_pin`, `aef_prior_year`, `aef_1st_installment`, `aef_2nd_installment`, `aef_current_year`, `aef_tax_amount_1st`, `aef_tax_amount_2nd`, `aef_due_date_1st`, `aef_due_date_2nd`, `aef_tax_year_of_sold_taxes`, `aef_mortgages_of_record`,  `aef_other_liens_of_record`, `aef_building_lines`, `aef_easements`, `aef_document_numbers`, `aef_condo_association`, `aef_search_package_reviewed_amendments`, `aef_search_package_reviewed`, `aef_amendments`, `aef_signature`, `aef_date_stamp`, `aef_attachment_id`, `aef_upload_account_id`, `aef_account_id`, `aef_order_id`, `aef_request_id`, `aef_created`, `aef_status`) VALUES ('" + txtAgentsName.Text.Replace("'", "''") + "', '" + commitment.Replace("'", "''") + "', '" + txtPropertyVesting.Text.Replace("'", "''") + "', '" + txtPropertyAddress.Text.Replace("'", "''") + "', '" + txtPropertyCityStateZip.Text.Replace("'", "''") + "', '" + txtPropertyCounty.Text.Replace("'", "''") + "', '" + txtPIN.Text.Replace("'", "''") + "', '" + txtPriorYear.Text.Replace("'", "''") + "', '" + txt1stInstallment.Text.Replace("'", "''") + "', '" + txt2ndInstallment.Text.Replace("'", "''") + "', '" + txtCurrentYear.Text.Replace("'", "''") + "', '" + txtTaxAmount1st.Text.Replace("'", "''") + "', '" + txtTaxAmount2nd.Text.Replace("'", "''") + "', " + ((txtDueDate1st.Text.Trim().Equals("") || !DateTime.TryParse(txtDueDate1st.Text, out t))? "null" : "'" + String.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(txtDueDate1st.Text.Replace("'", "''"))) + "'") + ", " + ((txtDueDate2nd.Text.Trim().Equals("") || !DateTime.TryParse(txtDueDate2nd.Text, out t))? "null" : "'" + String.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(txtDueDate2nd.Text.Replace("'", "''"))) + "'") + ", '" + txtTaxYearofSoldtaxes.Text.Replace("'", "''") + "', '" + txtMortgagesofRecord.Text.Replace("'", "''") + "', '" + txtOtherLiensofRecord.Text.Replace("'", "''") + "', '" + txtBuildingLines.Text.Replace("'", "''") + "', '" + txtEasements.Text.Replace("'", "''") + "', '" + txtDocumentNumbers.Text.Replace("'", "''") + "', '" + ((radioCondoAssociationYes.Checked) ? "Yes" : "No") + "', '" + ((chkSearchPackageReviewedAmendments.Checked) ? "Yes" : "No") + "', '" + ((chkSearchPackageReviewed.Checked) ? "Yes" : "No") + "', '" + txtAmendments.Text.Replace("'", "''") + "', '" + me.Signature.Replace("'", "''") + "', '" + String.Format("{0:yyyy-MM-dd}", DateTime.Now) + "', " + attID + ", " + this.request.Account.Id.ToString() + ", " + this.GetAccount().Id.ToString() + ", " + this.request.OrderId.ToString() + ", " + this.request.Id.ToString() + ", '" + String.Format("{0:yyyy-MM-dd}", DateTime.Now) + "', " + ((submitted)? "1" : "0") + " )", mysqlCon))
                    {
                        try
                        {
                            MySqlDataReader Reader = cmd.ExecuteReader();
                            while (Reader.Read()) // this part is wrong somehow
                            {
                                //citationstexter.Add(Reader.GetString(loopReading)); // this works
                                //loopReading++; // this works
                            }
                            Reader.Close();
                        }

                        catch (Exception ex)
                        {
                            //MessageBox.Show(ex.Message);
                            Response.Write(ex.Message);
                        }
                    }
                }
                else
                {
                    using (MySqlCommand cmd = new MySqlCommand("UPDATE agent_examination SET `aef_agents_name` = '" + txtAgentsName.Text.Replace("'", "''") + "', `aef_commitment_number` = '" + commitment.Replace("'", "''") + "', `aef_property_vesting` = '" + txtPropertyVesting.Text.Replace("'", "''") + "', `aef_property_address` = '" + txtPropertyAddress.Text.Replace("'", "''") + "', `aef_property_city_state_zip` = '" + txtPropertyCityStateZip.Text.Replace("'", "''") + "', `aef_property_county` = '" + txtPropertyCounty.Text.Replace("'", "''") + "', `aef_pin` = '" + txtPIN.Text.Replace("'", "''") + "', `aef_prior_year` = '" + txtPriorYear.Text.Replace("'", "''") + "', `aef_1st_installment` = '" + txt1stInstallment.Text.Replace("'", "''") + "', `aef_2nd_installment` = '" + txt2ndInstallment.Text.Replace("'", "''") + "', `aef_current_year` = '" + txtCurrentYear.Text.Replace("'", "''") + "', `aef_tax_amount_1st` = '" + txtTaxAmount1st.Text.Replace("'", "''") + "', `aef_tax_amount_2nd` = '" + txtTaxAmount2nd.Text.Replace("'", "''") + "', `aef_due_date_1st` = " + ((txtDueDate1st.Text.Trim().Equals("") || !DateTime.TryParse(txtDueDate1st.Text, out t))? "null" : "'" + String.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(txtDueDate1st.Text.Replace("'", "''"))) + "'") + ", `aef_due_date_2nd` = " + ((txtDueDate2nd.Text.Trim().Equals("") || !DateTime.TryParse(txtDueDate2nd.Text, out t))? "null" : "'" + String.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(txtDueDate2nd.Text.Replace("'", "''"))) + "'") + ", `aef_tax_year_of_sold_taxes` = '" + txtTaxYearofSoldtaxes.Text.Replace("'", "''") + "', `aef_mortgages_of_record` = '" + txtMortgagesofRecord.Text.Replace("'", "''") + "',  `aef_other_liens_of_record` = '" + txtOtherLiensofRecord.Text.Replace("'", "''") + "', `aef_building_lines` = '" + txtBuildingLines.Text.Replace("'", "''") + "', `aef_easements` = '" + txtEasements.Text.Replace("'", "''") + "', `aef_document_numbers` = '" + txtDocumentNumbers.Text.Replace("'", "''") + "', `aef_condo_association` = '" + ((radioCondoAssociationYes.Checked) ? "Yes" : "No") + "', `aef_search_package_reviewed_amendments` = '" + ((chkSearchPackageReviewedAmendments.Checked) ? "Yes" : "No") + "', `aef_search_package_reviewed` = '" + ((chkSearchPackageReviewed.Checked) ? "Yes" : "No") + "', `aef_amendments` = '" + txtAmendments.Text.Replace("'", "''") + "', `aef_signature` = '" + me.Signature.Replace("'", "''") + "', `aef_date_stamp` = '" + String.Format("{0:yyyy-MM-dd}", DateTime.Now) + "', `aef_attachment_id` = " + attID + ", `aef_upload_account_id` = " + this.request.Account.Id.ToString() + ", `aef_account_id` = " + this.GetAccount().Id.ToString() + ", `aef_order_id` = " + this.request.OrderId.ToString() + ", `aef_request_id` = " + this.request.Id.ToString() + ", `aef_created` = '" + String.Format("{0:yyyy-MM-dd}", DateTime.Now) + "', `aef_status` = " + ((submitted)? "1" : "0") + " WHERE aef_id = " + aefid, mysqlCon))
                    {
                        try
                        {
                            MySqlDataReader Reader = cmd.ExecuteReader();
                            while (Reader.Read()) // this part is wrong somehow
                            {
                                //citationstexter.Add(Reader.GetString(loopReading)); // this works
                                //loopReading++; // this works
                            }
                            Reader.Close();
                        }

                        catch (Exception ex)
                        {
                            //MessageBox.Show(ex.Message);
                            Response.Write(ex.Message);
                        }
                    }
                }
            }

            if (submitted)
            {
                using (FileStream fs = new FileStream(Server.MapPath("./") + "attachments/" + fileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite, 8, true))
                {
                    /*
                     * using (StreamWriter sw = new StreamWriter(fs))
                     * {
                     *      // Write to the file using StreamWriter class
                     *      sw.BaseStream.Seek(0, SeekOrigin.End);
                     *      sw.Write(contentsHTML);
                     *      sw.Flush();
                     * }
                     */
                    HiQPdf.HtmlToPdf converter = new HtmlToPdf();
                    converter.SerialNumber = "TwcmHh8rKQMmLT0uPTZ6YX9vfm9+b354eW98fmF+fWF2dnZ2";
                    converter.ConvertHtmlToStream(contentsHTML, "http://" + Request.Url.Host, fs);
                }

                /*
                 * using (FileStream fs = new FileStream(Server.MapPath("./") + "App_Data/" + fileName.Replace(".html", ".txt"), FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite, 8, true))
                 * {
                 *      using (StreamWriter sw = new StreamWriter(fs))
                 *      {
                 *              // Write to the file using StreamWriter class
                 *              sw.BaseStream.Seek(0, SeekOrigin.End);
                 *              sw.Write(contentsTXT);
                 *              sw.Flush();
                 *      }
                 * }
                 */

                //fuAttachment.SaveAs(Server.MapPath("./") + "attachments/" + fileName);

                /*
                 * txtEmailNote.Text = "A new file '" + att.Name + "' has been posted and is ready for your review.  "
                 + txtEmailNote.Text;
                 +
                 + SendNotification(oldStatus, newStatus, filePosted, txtEmailNote.Text);
                 */



                /*
                 * // Load the available messages to the combo box so we can pick one and view the details of this message
                 * // Logon and get message:
                 * oUserSession = oZfAPI.Logon("ADMINIST", false);
                 * oMessages = oUserSession.Outbox.GetMsgList();
                 *
                 * // Insert the message body into the combobox so the message would be selected according to this value
                 * IEnumerator MessaegesEnum = oMessages.GetEnumerator();
                 *
                 * while (MessaegesEnum.MoveNext())
                 * {
                 *      // Iterate through the messages
                 *      oMessage = (ZfLib.Message)MessaegesEnum.Current;
                 *      //cmbMessages.Items.Add(oMessage.GetMsgInfo().Body); //Insert the message into the combobox
                 * }
                 *
                 * // Enable the controls according to the number of messages:
                 * if (cmbMessages.Items.Count == 0) //If there aren't any messages - disable both the combobox and the button
                 * {
                 *      cmbMessages.Enabled = false;
                 *      btnGetMessageInfo.Enabled = false;
                 * }
                 * else // In case there is at least 1 message in the outbox - put it as a default selection in the combobox
                 *      cmbMessages.SelectedIndex = 0;
                 */

                if (FaxRadio.Checked)
                {
                    AffinityFaxServer afs = new AffinityFaxServer();
                    afs.Form_Load(contentsHTML, fileName);
                }
                else
                {
                    //Response.Write(this.GetSystemSetting("SendFromEmail") + "<br />");

                    // send to: [email protected]
                    MailMessage mm = new MailMessage(this.GetSystemSetting("SendFromEmail"), "[email protected], [email protected]", "Agent Examination Form " + commitment, "Agent Examination Form has been submitted by: " + me.FirstName + " " + me.LastName + "<br /><br /><br />\r\n\r\n" + this.GetSystemSetting("EmailFooter"));
                    mm.IsBodyHtml = true;
                    mm.Priority   = MailPriority.Normal;

                    if (File.Exists(Server.MapPath("./") + "attachments/" + fileName))
                    {
                        Attachment attch = new Attachment(Server.MapPath("./") + "attachments/" + fileName);
                        attch.Name = fileName;

                        mm.Attachments.Add(attch);
                    }
                    //SmtpClient sc = new SmtpClient(this.GetSystemSetting("SmtpHost"));
                    //sc.Send(mm);

                    Com.VerySimple.Email.Mailer mailer = new Com.VerySimple.Email.Mailer(this.GetSystemSetting("SmtpHost"));
                    mailer.Send(mm);
                }

                /*
                 * HttpContext.Current.Response.BufferOutput = true;
                 * HttpContext.Current.Response.ContentType = "application/pdf";
                 * HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=AgentExaminationForm.pdf");
                 */

                Response.Write(contentsHTML.Replace("<h2>Affinity Title Search</h2>", "<h2>Affinity Title Search</h2><div style=\"font-size:24px;color:blue;\">The Agent Examination Form has been submitted successfully.</div>"));
                //Response.End();
            }
        }
        catch (System.Exception ex)
        {
            //this.Master.ShowFeedback(ex.Message, MasterPage.FeedbackType.Information);
            //Response.Write(ex.Message);
            Response.End();
        }
    }
    /// <summary>
    /// Persist to DB and send email notification
    /// </summary>
    /// <returns>result of email notification</returns>
    protected string UpdateRequest()
    {
        // see if the status was changed from it's previous value
        // note we are getting the full description here vs the code
        string oldStatus  = this.request.RequestStatus.Description;
        string newStatus  = ddStatus.SelectedItem.Text;
        bool   filePosted = fuAttachment.HasFile;

        this.request.StatusCode = ddStatus.SelectedValue;          // here we need the code, tho
        this.request.Note       = txtNote.Text;

        // update the details
        XmlForm xf = new XmlForm(this.request.Account);

        this.request.Xml = XmlForm.XmlToString(xf.GetResponse(pnlDetails));

        this.request.Update();
        this.request.Order.SyncStatus();

        // if a file was provided, then upload it
        if (filePosted)
        {
            string ext              = System.IO.Path.GetExtension(fuAttachment.FileName);
            string fileName         = "req_att_" + request.Id + "_" + DateTime.Now.ToString("yyyyMMddhhss") + "." + ext.Replace(".", "");
            Affinity.Attachment att = new Affinity.Attachment(this.phreezer);
            att.RequestId   = this.request.Id;
            att.Name        = txtAttachmentName.Text != "" ? txtAttachmentName.Text : ddFilePurpose.SelectedItem.Text;
            att.PurposeCode = ddFilePurpose.SelectedValue;
            att.Filepath    = fileName;
            att.MimeType    = ext;
            att.SizeKb      = 0;        // fuAttachment.FileBytes.GetUpperBound() * 1024;

            att.Insert();
            if (ddFilePurpose.SelectedValue.Equals("SearchPkg"))
            {
                Affinity.Schedule sched = new Affinity.Schedule(this.phreezer);
                sched.AttachmentID        = att.Id;
                sched.AccountID           = this.request.Account.Id;
                sched.UploadAccountID     = this.GetAccount().Id;
                sched.OrderID             = this.request.OrderId;
                sched.RequestID           = this.request.Id;
                sched.Search_package_date = DateTime.Now;

                sched.Insert();
                Affinity.Global.SetSchedule();
            }
            //TODO: block any harmful file types

            Affinity.UploadLog ul = new Affinity.UploadLog(this.phreezer);

            ul.AttachmentID    = att.Id;
            ul.AccountID       = this.request.Account.Id;
            ul.UploadAccountID = this.GetAccount().Id;
            ul.OrderID         = this.request.OrderId;
            ul.RequestID       = this.request.Id;

            ul.Insert();

            fuAttachment.SaveAs(Server.MapPath("./") + "attachments/" + fileName);

            txtEmailNote.Text = "A new file '" + att.Name + "' has been posted and is ready for your review.  "
                                + txtEmailNote.Text;
        }

        return(SendNotification(oldStatus, newStatus, filePosted, txtEmailNote.Text));
    }
Exemple #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // System.IO.Path.GetExtension();

        Affinity.Attachment att = new Affinity.Attachment(this.phreezer);
        att.Load(NoNull.GetInt(Request["id"], 0));

        if (!att.Request.Order.CanRead(this.GetAccount()))
        {
            Crash(302, "You do not have permission to view this attachment");
        }

        string fileName  = att.Filepath;
        string viewStyle = this.GetAccount().GetPreference("AttachmentBehavior", "attachment");         // inline || attachment
        string filePath  = Server.MapPath("./") + "attachments/" + fileName.Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "");

        FileInfo fi = new FileInfo(filePath);

        string contentType;

        // the viewstyle itself being inline/attachment would seem to be what we want
        // however it seems to be generally ignored by the browser.  So, in addition
        // to setting that header, we will force the content type as well
        if (viewStyle.Equals("attachment"))
        {
            contentType = "application/octet-stream";
        }
        else
        {
            switch (fi.Extension.Replace(".", "").ToLower())
            {
            case "pdf":
                contentType = "application/pdf";
                break;

            case "doc":
                contentType = "application/msword";
                break;

            case "xls":
                contentType = "application/vnd.ms-excel";
                break;

            case "tif":
            case "tiff":
                contentType = "image/tiff";
                break;

            default:
                contentType = "application/octet-stream";
                break;
            }
        }

        Response.Clear();
        Response.ContentType = contentType;
        Response.AddHeader("content-length", fi.Length.ToString());
        Response.AddHeader("Content-Disposition", "" + viewStyle + ";filename=\"" + fileName + "\"");

        Response.Buffer = true;
        Response.WriteFile(filePath);
        Response.End();

        /*
         * // alternate way to write binary to the browser
         * byte[] data = pdf.GetData();
         * Response.Clear();
         * Response.ContentType = "application/pdf";
         * Response.AddHeader("content-disposition", "inline;filename=FileName.pdf");
         * Response.AddHeader("content-length", data.Length.ToString());
         * Response.Buffer = true;
         * Response.BinaryWrite(data);
         * Response.End();  // this is required or else the pdf will open in a new window
         */
    }
Exemple #5
0
    /// <summary>
    /// Persist to DB and send email notification
    /// </summary>
    /// <returns>result of email notification</returns>
    protected string UpdateRequest()
    {
        if (!fuAttachment.HasFile)
        {
            return("No File Uploaded.");
        }

        this.request.StatusCode = "New";          // here we need the code, tho
        this.request.Note       = txtNote.Text;

        // if a file was provided, then upload it
        string ext      = System.IO.Path.GetExtension(fuAttachment.FileName);
        string fileName = "req_att_" + request.Id + "_" + DateTime.Now.ToString("yyyyMMddhhss") + "." + ext.Replace(".", "");

        Affinity.Attachment att = new Affinity.Attachment(this.phreezer);
        att.RequestId   = this.request.Id;
        att.Name        = txtAttachmentName.Text != "" ? txtAttachmentName.Text : ddFilePurpose.SelectedItem.Text;
        att.PurposeCode = ddFilePurpose.SelectedValue;
        att.Filepath    = fileName;
        att.MimeType    = ext;
        att.SizeKb      = 0;    // fuAttachment.FileBytes.GetUpperBound() * 1024;

        att.Insert();
        //TODO: block any harmful file types

        Affinity.UploadLog ul = new Affinity.UploadLog(this.phreezer);

        ul.AttachmentID    = att.Id;
        ul.AccountID       = this.request.Account.Id;
        ul.UploadAccountID = this.GetAccount().Id;
        ul.OrderID         = this.request.OrderId;
        ul.RequestID       = this.request.Id;

        ul.Insert();

        fuAttachment.SaveAs(Server.MapPath("./") + "attachments/" + fileName);

        Affinity.Account me = this.GetAccount();
        bool             isNotSurveyServices = this.request.GetDataValue("SurveyServices").Equals("");

        string to    = "[email protected], [email protected]";
        string state = this.request.Order.PropertyState.ToUpper();

        if (isNotSurveyServices && (state.Equals("IN") || state.Equals("MI") || state.Equals("FL")))
        {
            to += ", " + ((state.Equals("IN"))? "*****@*****.**" : (state.Equals("MI"))? "*****@*****.**" : "*****@*****.**");
        }

        MailMessage mm = new MailMessage(this.GetSystemSetting("SendFromEmail"), to, "File Uploaded for Affinity Order '" + this.request.Order.ClientName.Replace("\r", "").Replace("\n", "") + "' #" + this.request.Order.WorkingId, "File: " + att.Name + " (" + fileName + ") was uploaded to: #" + this.request.Order.WorkingId + " and was uploaded by: " + me.FirstName + " " + me.LastName + "<br /><br /><br />\r\n\r\n" + this.GetSystemSetting("EmailFooter"));

        mm.IsBodyHtml = true;
        mm.Priority   = MailPriority.Normal;

        if (File.Exists(Server.MapPath("./") + "attachments/" + fileName))
        {
            Attachment attch = new Attachment(Server.MapPath("./") + "attachments/" + fileName);
            attch.Name = fileName;

            mm.Attachments.Add(attch);
        }
        //SmtpClient sc = new SmtpClient(this.GetSystemSetting("SmtpHost"));
        //sc.Send(mm);

        Com.VerySimple.Email.Mailer mailer = new Com.VerySimple.Email.Mailer(this.GetSystemSetting("SmtpHost"));
        mailer.Send(mm);

        return("File was uploaded successfully.");
    }