コード例 #1
0
        ///<summary>Inserts the new email address and returns it.</summary>
        public static EmailAddress CreateEmailAddress(string senderAddress = "", string emailUserName = "")
        {
            EmailAddress email = new EmailAddress();

            email.SenderAddress = senderAddress;
            if (senderAddress == "")
            {
                email.SenderAddress = "Email" + MiscUtils.CreateRandomAlphaNumericString(4);
            }
            email.EmailUsername = emailUserName;
            EmailAddresses.Insert(email);
            EmailAddresses.RefreshCache();
            return(email);
        }
コード例 #2
0
 private void butArchive_Click(object sender, EventArgs e)
 {
     #region Validation
     if (checkArchiveDoBackupFirst.Checked)              //We only need to validate the backup settings if the user wants to make a backup first
     {
         if (!MsgBox.Show(MsgBoxButtons.YesNo, "To make a backup of the database, ensure no other machines are currently using OpenDental. Proceed?"))
         {
             return;
         }
         //Validation
         if (string.IsNullOrWhiteSpace(textArchiveServerName.Text))
         {
             MsgBox.Show(this, "Please specify a Server Name.");
             return;
         }
         if (string.IsNullOrWhiteSpace(textArchiveUser.Text))
         {
             MsgBox.Show(this, "Please enter a User.");
             return;
         }
         if (string.IsNullOrWhiteSpace(PrefC.GetString(PrefName.ArchiveKey)))                 //If archive key isn't set, generate a new one.
         {
             string archiveKey = MiscUtils.CreateRandomAlphaNumericString(10);
             Prefs.UpdateString(PrefName.ArchiveKey, archiveKey);
         }
     }
     #endregion
     //Create an ODProgress
     ODProgress.ShowAction(() => {
         //Make a backup if needed
         if (checkArchiveDoBackupFirst.Checked)
         {
             try {
                 MiscData.MakeABackup(textArchiveServerName.Text, textArchiveUser.Text, textArchivePass.Text, doVerify: true);
             }
             catch (Exception ex) {
                 FriendlyException.Show("An error occurred backing up the old database. Old data was not removed from the database. " +
                                        "Ensure no other machines are currently using OpenDental and try again.", ex);
                 return;
             }
         }
         //Delete the unnecessary data
         SecurityLogs.DeleteBeforeDateInclusive(dateTimeArchive.Value);
         SecurityLogs.MakeLogEntry(Permissions.Backup, 0, $"SecurityLog and SecurityLogHashes on/before {dateTimeArchive.Value} deleted.");
     },
                           eventType: typeof(MiscDataEvent),
                           odEventType: ODEventType.MiscData);
 }
コード例 #3
0
ファイル: MedicationT.cs プロジェクト: ChemBrain/OpenDental
        ///<summary>Inserts the new medication and returns it.</summary>
        public static Medication CreateMedication(string medName = "", string rxCui = "")
        {
            Medication medication = new Medication();

            medication.MedName = medName;
            if (medication.MedName == "")
            {
                medication.MedName = "Med_" + MiscUtils.CreateRandomAlphaNumericString(8);
            }
            medication.RxCui = PIn.Long(rxCui, false);
            if (medication.RxCui != 0 && RxNorms.GetByRxCUI(rxCui) == null)
            {
                RxNorm rxNorm = new RxNorm();
                rxNorm.RxCui       = rxCui;
                rxNorm.Description = medication.MedName;
                RxNorms.Insert(rxNorm);
            }
            Medications.Insert(medication);
            return(medication);
        }
コード例 #4
0
        public static SmsFromMobile CreateSmsFromMobile(long patNum, long clinicNum, string patPhone, string provPhone, DateTime dateTimeReceived,
                                                        string msgText = "", string guidMessage = "")
        {
            if (string.IsNullOrEmpty(guidMessage))
            {
                guidMessage = Guid.NewGuid().ToString();
            }
            SmsFromMobile smsFromMobile = new SmsFromMobile()
            {
                GuidMessage       = guidMessage,
                PatNum            = patNum,
                MobilePhoneNumber = patPhone,
                SmsPhoneNumber    = provPhone,
                ClinicNum         = clinicNum,
                DateTimeReceived  = dateTimeReceived,
                MsgText           = string.IsNullOrEmpty(msgText) ? MiscUtils.CreateRandomAlphaNumericString(10) : msgText,
            };

            smsFromMobile.SmsFromMobileNum = SmsFromMobiles.Insert(smsFromMobile);
            return(smsFromMobile);
        }
コード例 #5
0
        ///<summary>Inserts the new user, refreshes the cache and then returns UserNum</summary>
        public static Userod CreateUser(string userName = "", string password = "", List <long> userGroupNumbers = null, long clinicNum = 0, bool isClinicIsRestricted = false)
        {
            if (userName == "")
            {
                userName = "******" + MiscUtils.CreateRandomAlphaNumericString(8);
            }
            if (password == "")
            {
                password = "******";
            }
            if (userGroupNumbers == null)
            {
                userGroupNumbers = new List <long> {
                    1
                };
            }
            Userod newUser = new Userod();

            newUser.UserName           = userName;
            newUser.LoginDetails       = Authentication.GenerateLoginDetails(password, HashTypes.SHA3_512);
            newUser.ClinicNum          = clinicNum;
            newUser.ClinicIsRestricted = isClinicIsRestricted;
            do
            {
                //In case the username is already taken
                try {
                    newUser.UserNum = Userods.Insert(newUser, userGroupNumbers);
                }
                catch {
                    newUser.UserName = "******" + MiscUtils.CreateRandomAlphaNumericString(8);
                }
            }while(newUser.UserNum == 0);
            Userods.RefreshCache();
            UserGroupAttaches.RefreshCache();
            return(newUser);
        }
コード例 #6
0
        ///<summary>Throws exceptions.  Creates a new file inside of the email attachment path (inside OpenDentImages) and returns an EmailAttach object
        ///referencing the new file.  If isOutbound is true, then the file will be saved to the "Out" subfolder, otherwise the file will be saved to the
        ///"In" subfolder.  The displayFileName will always contain valid file name characters, because it is either a hard coded value or is based on an
        ///existing valid file name.  If a file already exists matching the actualFileName, then an exception will occur.  Set actualFileName to empty
        ///string to generate a unique actual file name.  If the actual file name is generated, then actual file name will end with the displayFileName,
        ///so that the actual files are easier to locate and have the same file extension as the displayedFileName.</summary>
        public static EmailAttach CreateAttach(string displayedFileName, string actualFileName, byte[] arrayData, bool isOutbound)
        {
            //No need to check RemotingRole; no call to db.
            EmailAttach emailAttach = new EmailAttach();

            emailAttach.DisplayedFileName = displayedFileName;
            if (String.IsNullOrEmpty(emailAttach.DisplayedFileName))
            {
                //This could only happen for malformed incoming emails, but should not happen.  Name uniqueness is virtually guaranteed below.
                //The actual file name will not have an extension, so the user will be asked to pick the program to open the attachment with when
                //the attachment is double-clicked.
                emailAttach.DisplayedFileName = "attach";
            }
            string attachDir = GetAttachPath();
            string subDir    = "In";

            if (isOutbound)
            {
                subDir = "Out";
            }
            if (!CloudStorage.IsCloudStorage && !Directory.Exists(ODFileUtils.CombinePaths(attachDir, subDir)))
            {
                Directory.CreateDirectory(ODFileUtils.CombinePaths(attachDir, subDir));
            }
            if (String.IsNullOrEmpty(actualFileName))
            {
                while (String.IsNullOrEmpty(emailAttach.ActualFileName) ||
                       FileAtoZ.Exists(FileAtoZ.CombinePaths(attachDir, emailAttach.ActualFileName)))
                {
                    //Display name is tacked onto actual file name last as to ensure file extensions are the same.
                    emailAttach.ActualFileName = FileAtoZ.CombinePaths(subDir,
                                                                       DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.TimeOfDay.Ticks.ToString()
                                                                       + "_" + MiscUtils.CreateRandomAlphaNumericString(4) + "_" + emailAttach.DisplayedFileName);
                }
            }
            else
            {
                //The caller wants a specific actualFileName.  Use the given name as is.
                emailAttach.ActualFileName = FileAtoZ.CombinePaths(subDir, actualFileName);
            }
            string attachFilePath = FileAtoZ.CombinePaths(attachDir, emailAttach.ActualFileName);

            if (FileAtoZ.Exists(attachFilePath))
            {
                throw new ApplicationException("Email attachment could not be saved because a file with the same name already exists.");
            }
            try {
                FileAtoZ.WriteAllBytes(attachFilePath, arrayData);
            }
            catch (Exception ex) {
                try {
                    if (FileAtoZ.Exists(attachFilePath))
                    {
                        FileAtoZ.Delete(attachFilePath);
                    }
                }
                catch {
                    //We tried our best to delete the file, and there is nothing else to try.
                }
                throw ex;                //Show the initial error message, even if the Delete() failed.
            }
            return(emailAttach);
        }
コード例 #7
0
ファイル: EmailAttachL.cs プロジェクト: kjb7749/testImport
        ///<summary>Allow the user to pick the files to be attached. The 'pat' argument can be null. If the user cancels at any step, the return value
        ///will be an empty list.</summary>
        public static List <EmailAttach> PickAttachments(Patient pat)
        {
            List <EmailAttach> listAttaches = new List <EmailAttach>();
            OpenFileDialog     dlg          = new OpenFileDialog();

            dlg.Multiselect = true;
            bool          isLocalFileSelected = false;
            List <string> listFileNames;

            if (pat != null && PrefC.AtoZfolderUsed != DataStorageType.InDatabase)
            {
                string patFolder = ImageStore.GetPatientFolder(pat, ImageStore.GetPreferredAtoZpath());
                if (CloudStorage.IsCloudStorage)
                {
                    FormFilePicker FormFP = new FormFilePicker(patFolder);
                    if (FormFP.ShowDialog() != DialogResult.OK)
                    {
                        return(listAttaches);
                    }
                    isLocalFileSelected = FormFP.WasLocalFileSelected;
                    listFileNames       = FormFP.SelectedFiles;
                }
                else
                {
                    dlg.InitialDirectory = patFolder;
                    if (dlg.ShowDialog() != DialogResult.OK)
                    {
                        return(listAttaches);
                    }
                    isLocalFileSelected = true;
                    listFileNames       = dlg.FileNames.ToList();
                }
            }
            else              //No patient selected or images in database
                              //Use the OS default directory for this type of file viewer.
            {
                dlg.InitialDirectory = "";
                if (dlg.ShowDialog() != DialogResult.OK)
                {
                    return(listAttaches);
                }
                isLocalFileSelected = true;
                listFileNames       = dlg.FileNames.ToList();
            }
            try {
                for (int i = 0; i < listFileNames.Count; i++)
                {
                    if (CloudStorage.IsCloudStorage)
                    {
                        FileAtoZSourceDestination sourceDestination;
                        if (isLocalFileSelected)
                        {
                            sourceDestination = FileAtoZSourceDestination.LocalToAtoZ;
                        }
                        else
                        {
                            sourceDestination = FileAtoZSourceDestination.AtoZToAtoZ;
                        }
                        //Create EmailAttach using EmailAttaches.CreateAttach logic, shortened for our specific purpose.
                        EmailAttach emailAttach = new EmailAttach();
                        emailAttach.DisplayedFileName = Path.GetFileName(listFileNames[i]);
                        string attachDir = EmailAttaches.GetAttachPath();
                        string subDir    = "Out";
                        emailAttach.ActualFileName = ODFileUtils.CombinePaths(subDir,
                                                                              DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.TimeOfDay.Ticks.ToString()
                                                                              + "_" + MiscUtils.CreateRandomAlphaNumericString(4) + "_" + emailAttach.DisplayedFileName).Replace("\\", "/");
                        FileAtoZ.Copy(listFileNames[i], FileAtoZ.CombinePaths(attachDir, emailAttach.ActualFileName), sourceDestination);
                        listAttaches.Add(emailAttach);
                    }
                    else                      //Not cloud
                    {
                        listAttaches.Add(EmailAttaches.CreateAttach(Path.GetFileName(listFileNames[i]), File.ReadAllBytes(listFileNames[i])));
                    }
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
            return(listAttaches);
        }