private WebReportData GetBaseData(Building building)
        {
            WebReportData wrd = new WebReportData();

            wrd.building = building.Name;
            wrd.picture  = null;
            var logoData = new AstrodonClientPortal(SqlDataHandler.GetClientPortalConnectionString()).GetBuildingImage(building.ID);

            if (logoData != null)
            {
                using (var memLogo = new MemoryStream(logoData))
                {
                    Image img = Image.FromStream(memLogo);
                    wrd.picture = img;
                }
            }

            //String status;
            //DataSet dsPic = mysql.GetData("SELECT image FROM tt_content WHERE pid = " + building.pid + " AND CType = 'image'", null, out status);
            //if (dsPic != null && dsPic.Tables.Count > 0 && dsPic.Tables[0].Rows.Count > 0)
            //{
            //    String picture = dsPic.Tables[0].Rows[0]["image"].ToString();
            //    Classes.Sftp sftpClient = new Classes.Sftp(String.Empty, true);
            //    sftpClient.WorkingDirectory = "/srv/www/htdocs/uploads/pics";
            //    String thisDirectory = AppDomain.CurrentDomain.BaseDirectory;
            //    String file1 = picture.Replace(Path.GetFileNameWithoutExtension(picture), Path.GetFileNameWithoutExtension(picture) + "_web1");
            //    String tempPath = Path.Combine(thisDirectory, file1);
            //    bool success = sftpClient.Download(tempPath, picture, false, out status);
            //    if (!success)
            //    {
            //        MessageBox.Show(status);
            //        wrd.picture = null;
            //    }
            //    else
            //    {
            //        Image img = Image.FromFile(file1);
            //        wrd.picture = img;
            //    }
            //}
            //else
            //{
            //    wrd.picture = null;
            //}

            List <String> folders   = LoadFolders(building.webFolder);
            List <String> rootFiles = ListFiles(building.webFolder, String.Empty);

            wrd.files.Add("Root", rootFiles);
            foreach (String folder in folders)
            {
                try
                {
                    wrd.files.Add(folder, ListFiles(building.webFolder, folder));
                }
                catch (Exception ex) { Controller.HandleError(ex); }
            }
            return(wrd);
        }
Esempio n. 2
0
        private void SaveBuilding()
        {
            building.Name             = txtName.Text;
            building.Abbr             = txtAbbr.Text;
            building.Trust            = txtTrust.Text;
            building.DataPath         = txtPath.Text;
            building.Period           = int.Parse(txtPeriod.Text);
            building.Cash_Book        = txtCash.Text;
            building.Payments         = int.Parse(txtPayment.Text);
            building.Receipts         = int.Parse(txtReceipt.Text);
            building.Journal          = int.Parse(txtJournal.Text);
            building.Centrec_Account  = txtCentrec1.Text;
            building.Centrec_Building = txtCentrec2.Text;
            building.Business_Account = txtBus.Text;
            building.Bank             = txtBank.Text;
            building.PM              = txtPM.Text;
            building.Bank_Name       = txtBankName.Text;
            building.Bank_Acc_Number = txtAccNumber.Text;
            building.Acc_Name        = txtAccName.Text;
            building.Branch_Code     = txtBranch.Text;
            building.Web_Building    = chkWeb.Checked;
            building.letterName      = txtLetter.Text;
            building.addy1           = txtAddress1.Text;
            building.addy2           = txtAddress2.Text;
            building.addy3           = txtAddress3.Text;
            building.addy4           = txtAddress4.Text;
            building.addy5           = txtAddress5.Text;

            Buildings BuildingManager = new Buildings(true);
            String    websafeName     = building.Name.Replace(" ", "_").Replace("/", "_").Replace("\\", "_");

            building.webFolder = websafeName;
            try
            {
                String status = String.Empty;
                if (BuildingManager.Update(building, out status))
                {
                    String newID = "";
                    building.pid = newID;
                    BuildingManager.Update(building, out status);

                    new AstrodonClientPortal(SqlDataHandler.GetClientPortalConnectionString()).SyncBuildingAndClients(building.ID);

                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Building update failed: SV3" + status, "Buildings", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Building update failed: SV4" + ex.Message, "Buildings", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 3
0
        private void btnSendNow_Click(object sender, EventArgs e)
        {
            if (txtEmail.Text != "" && txtSubject.Text != "" && txtMessage.Text != "" && cmbCustomer.SelectedIndex >= 0 && cmbBuilding.SelectedIndex >= 0)
            {
                var    customer      = customers[cmbCustomer.SelectedIndex];
                var    building      = buildings[cmbBuilding.SelectedIndex];
                string trusteeEmails = "";

                if (cbCCTrustees.Checked)
                {
                    using (var ctx = SqlDataHandler.GetDataContext())
                    {
                        var emls = ctx.CustomerSet.Where(a => a.BuildingId == building.ID &&
                                                         a.IsTrustee &&
                                                         a.EmailAddress1 != "").Select(a => a.EmailAddress1).ToList();
                        foreach (var s in emls)
                        {
                            if (!string.IsNullOrWhiteSpace(s))
                            {
                                if (!string.IsNullOrWhiteSpace(trusteeEmails))
                                {
                                    trusteeEmails = trusteeEmails + ";" + s;
                                }
                                else
                                {
                                    trusteeEmails = s;
                                }
                            }
                        }
                    }
                }

                String[] emails = txtEmail.Text.Split(new String[] { ";" }, StringSplitOptions.None);

                var clientPortal = new AstrodonClientPortal(SqlDataHandler.GetClientPortalConnectionString());

                Dictionary <string, string> attachmentsData = new Dictionary <string, string>();
                foreach (Object obj in lstAttachments.Items)
                {
                    string fileName = obj.ToString();
                    if (File.Exists(fileName))
                    {
                        attachmentsData.Add(Path.GetFileName(fileName),
                                            clientPortal.UploadUnitDocument(DocumentCategoryType.Letter, DateTime.Today, building.ID, customer.accNumber, txtSubject.Text, fileName, txtEmail.Text));
                    }
                }


                string cc = txtCC.Text;
                if (!string.IsNullOrWhiteSpace(cc) && !string.IsNullOrWhiteSpace(trusteeEmails))
                {
                    cc = ";" + trusteeEmails;
                }
                else
                {
                    cc = trusteeEmails;
                }


                if (Email.EmailProvider.SendDirectMail(building.ID, customer.accNumber,
                                                       emails, cc, txtBCC.Text, txtSubject.Text, txtMessage.Text, attachmentsData))
                {
                    MessageBox.Show("Message sent");
                }
                else
                {
                    MessageBox.Show("Message not sent");
                }
            }
            else
            {
                if (txtEmail.Text == "")
                {
                    MessageBox.Show("Please enter email address");
                }
                else if (txtSubject.Text == "")
                {
                    MessageBox.Show("Please enter subject");
                }
                else if (txtMessage.Text == "")
                {
                    MessageBox.Show("Please enter message");
                }
            }
        }
        private void SendCalenderInvite(CalendarPrintItem entry)
        {
            if (string.IsNullOrWhiteSpace(entry.PMEmail))
            {
                Controller.HandleError("Email address not found for " + entry.PM);
                return;
            }

            var calendarInvite = CreateCalendarInvite(entry.BuildingName + " - " + entry.Event, "", entry.Venue, entry.EventDate, entry.EventToDate != null ? entry.EventToDate.Value : entry.EventDate.AddHours(2));
            Dictionary <string, byte[]> attachments = new Dictionary <string, byte[]>();

            attachments.Add("Appointment.ics", calendarInvite);
            string subject = entry.InviteSubject;

            if (String.IsNullOrWhiteSpace(subject))
            {
                subject = entry.BuildingName + " - " + entry.Event;
            }

            string bodyContent = entry.InviteBody;

            if (String.IsNullOrWhiteSpace(bodyContent))
            {
                bodyContent = "";
            }

            string bccEmail = entry.BCCEmailAddress;

            if (bccEmail == string.Empty)
            {
                bccEmail = null;
            }

            //add aditional attachments
            using (var context = SqlDataHandler.GetDataContext())
            {
                var attach = context.CalendarEntryAttachmentSet.Where(a => a.BuildingCalendarEntryId == entry.Id).ToList();
                foreach (var a in attach)
                {
                    attachments.Add(a.FileName, a.FileData);
                }

                List <string> toAddress = new List <string>();
                toAddress.Add(entry.PMEmail);
                if (entry.EventyType == CalendarEntryType.Staff)
                {
                    var qInvite = from i in context.CalendarUserInviteSet
                                  where i.CalendarEntryId == entry.Id
                                  select i.User.email;

                    toAddress.AddRange(qInvite.ToList());
                }

                if (!Email.EmailProvider.SendCalendarInvite(entry.PMEmail, toAddress.Distinct().ToArray(), subject, bodyContent, attachments, bccEmail))
                {
                    Controller.HandleError("Error seding email ", "Email error");
                }

                if (entry.NotifyTrustees && entry.EventyType == CalendarEntryType.Financial)
                {
                    var customers    = Controller.pastel.AddCustomers(entry.BuildingAbreviation, entry.BuildingDataPath, true);
                    var dbCustomers  = context.CustomerSet.Where(a => a.BuildingId == entry.BuildingId && a.IsTrustee == true).ToList();
                    var clientPortal = new AstrodonClientPortal(SqlDataHandler.GetClientPortalConnectionString());

                    if (dbCustomers.Count() > 0 && Controller.AskQuestion("Are you sure you want to send the invite to " + dbCustomers.Count().ToString() + " trustees?"))
                    {
                        //upload building documents

                        Dictionary <string, string> trusteeAttachmentLinks = new Dictionary <string, string>();
                        foreach (var fileName in attachments.Keys.ToList())
                        {
                            if (fileName != "Appointment.ics")
                            {
                                var url = clientPortal.UploadBuildingDocument(DocumentCategoryType.PrivilegedCorrespondence, DateTime.Today, entry.BuildingId.Value, Path.GetFileNameWithoutExtension(fileName), fileName, attachments[fileName], "From Email");
                                trusteeAttachmentLinks.Add(fileName, url);
                            }
                        }

                        foreach (var dbCustomer in dbCustomers)
                        {
                            var trustee = customers.Where(a => a.accNumber == dbCustomer.AccountNumber).FirstOrDefault();
                            if (trustee != null)
                            {
                                if (trustee.Email != null && trustee.Email.Length > 0)
                                {
                                    if (!Email.EmailProvider.SendTrusteeCalendarInvite(entry.PMEmail, trustee.Email, subject, bodyContent, attachments, bccEmail, trusteeAttachmentLinks))
                                    {
                                        Controller.HandleError("Error seding email", "Email error");
                                    }
                                }
                            }
                        }

                        var itm = context.BuildingCalendarEntrySet.Single(a => a.id == entry.Id);
                        itm.TrusteesNotified   = true;
                        entry.TrusteesNotified = true;
                        context.SaveChanges();
                        BindDataGrid();
                    }
                }
            }
        }