public static bool SavePatientAttachement(PatientAttachment_cu patientAttachement)
        {
            if (patientAttachement == null)
            {
                return(false);
            }
            if (patientAttachement.SaveChanges())
            {
                PatientAttachment_cu.ItemsList.Add(patientAttachement);
                return(true);
            }

            return(false);
        }
        private void chkInvestigation_CheckedChanged(object sender, EventArgs e)
        {
            ImagesList = null;
            switch (ActiveScanningMode)
            {
            case ScanningMode.Regular:
                if (ActiveSelectedPatient != null)
                {
                    if (ImagesList == null)
                    {
                        ImagesList = new List <PatientAttachment_cu>();
                    }
                    ImagesList = PatientAttachment_cu.ItemsList.FindAll(item =>
                                                                        Convert.ToInt32(item.Patient_CU_ID)
                                                                        .Equals(Convert.ToInt32(ActiveSelectedPatient.Person_CU_ID)) &&
                                                                        Convert.ToInt32(item.ImageType_P_ID).Equals(Convert.ToInt32(ImageType_P_ID)));
                }
                break;

            case ScanningMode.MedicalVisit:
                if (PEMRBusinessLogic.ActivePEMRObject != null && PEMRBusinessLogic.ActivePEMRObject.List_VisitTiming_Attachment != null)
                {
                    foreach (VisitTiming_Attachment visitTimingAttachement in PEMRBusinessLogic.ActivePEMRObject
                             .List_VisitTiming_Attachment)
                    {
                        PatientAttachment_cu patientAttachment = PatientAttachment_cu.ItemsList.Find(item =>
                                                                                                     Convert.ToInt32(item.ID)
                                                                                                     .Equals(Convert.ToInt32(visitTimingAttachement.PatientAttachement_CU_ID)) &&
                                                                                                     Convert.ToInt32(item.ImageType_P_ID).Equals(Convert.ToInt32(ImageType_P_ID)));
                        if (ImagesList == null)
                        {
                            ImagesList = new List <PatientAttachment_cu>();
                        }
                        if (patientAttachment != null)
                        {
                            ImagesList.Add(patientAttachment);
                        }
                    }
                }

                break;
            }
            CommonViewsActions.FillListBoxControl(lstImageNames, ImagesList, "ImageName");
            if (ImagesList == null || ImagesList.Count == 0)
            {
                pictureEdit1.Image = Properties.Resources.TopLogin;
            }
            lstImageNames.Refresh();
        }
        private void chkSelectAll_CheckedChanged(object sender, EventArgs e)
        {
            chkSelectAll.Image = chkSelectAll.Checked
                                ? Properties.Resources.AcceptIcon_16_02
                                : Properties.Resources.RejectIcon_16_01;
            ImagesList = null;

            if (chkSelectAll.Checked)
            {
                OverridenScanningMode = ActiveScanningMode;
                ActiveScanningMode    = ScanningMode.Regular;
                if (ImagesList == null)
                {
                    ImagesList = new List <PatientAttachment_cu>();
                }
                ImagesList = PatientAttachment_cu.ItemsList.FindAll(item =>
                                                                    Convert.ToInt32(item.Patient_CU_ID)
                                                                    .Equals(Convert.ToInt32(ActiveSelectedPatient.Person_CU_ID)) &&
                                                                    Convert.ToInt32(item.ImageType_P_ID).Equals(Convert.ToInt32(ImageType_P_ID)));
            }
            else
            {
                ActiveScanningMode = OverridenScanningMode;
                if (PEMRBusinessLogic.ActivePEMRObject != null &&
                    PEMRBusinessLogic.ActivePEMRObject.List_VisitTiming_Attachment != null)
                {
                    foreach (VisitTiming_Attachment visitTimingAttachement in PEMRBusinessLogic.ActivePEMRObject
                             .List_VisitTiming_Attachment)
                    {
                        PatientAttachment_cu patientAttachment = PatientAttachment_cu.ItemsList.Find(item =>
                                                                                                     Convert.ToInt32(item.ID)
                                                                                                     .Equals(Convert.ToInt32(visitTimingAttachement.PatientAttachement_CU_ID)));
                        if (patientAttachment != null)
                        {
                            if (ImagesList == null)
                            {
                                ImagesList = new List <PatientAttachment_cu>();
                            }
                            ImagesList.Add(patientAttachment);
                        }
                    }
                }
            }

            CommonViewsActions.FillListBoxControl(lstImageNames, ImagesList, "ImageName");
            lstImageNames.Refresh();
        }
        public static PatientAttachment_cu CreateNewPatientAttachement(int patientID, string imageName,
                                                                       string imagePath, DB_ImageType imageType, object description, int userID)
        {
            PatientAttachment_cu patientAttachment = DBCommon.CreateNewDBEntity <PatientAttachment_cu>();

            patientAttachment.Patient_CU_ID  = patientID;
            patientAttachment.ImageName      = imageName;
            patientAttachment.ImagePath      = imagePath;
            patientAttachment.ImageType_P_ID = Convert.ToInt32(imageType);
            patientAttachment.IsOnDuty       = true;
            if (description != null)
            {
                patientAttachment.Description = description.ToString();
            }
            patientAttachment.InsertedBy = userID;

            return(patientAttachment);
        }
        public void Initialize(Patient_cu patient, ScanningMode scanningMode, MedicalType medicalType)
        {
            ActiveSelectedPatient = patient;
            ActiveScanningMode    = scanningMode;
            MedicalType           = medicalType;
            BackColor             = Color.White;

            List <PatientAttachment_cu> list = null;

            switch (ActiveScanningMode)
            {
            case ScanningMode.Regular:
                if (ActiveSelectedPatient != null)
                {
                    if (ImagesList == null)
                    {
                        ImagesList = new List <PatientAttachment_cu>();
                    }
                }
                ImagesList = PatientAttachment_cu.ItemsList.FindAll(item =>
                                                                    Convert.ToInt32(item.Patient_CU_ID)
                                                                    .Equals(Convert.ToInt32(ActiveSelectedPatient.Person_CU_ID)) &&
                                                                    Convert.ToInt32(item.ImageType_P_ID).Equals(Convert.ToInt32(ImageType_P_ID)));
                emptySpaceItem3.Visibility     = LayoutVisibility.Always;
                layoutControlItem4.Visibility  = LayoutVisibility.Always;
                layoutControlItem3.Visibility  = LayoutVisibility.Always;
                layoutControlGroup2.Visibility = LayoutVisibility.Always;
                layoutControlGroup3.Visibility = LayoutVisibility.Always;
                layoutControlItem5.Visibility  = LayoutVisibility.Always;
                layoutControlItem15.Visibility = LayoutVisibility.Always;
                simpleSeparator4.Visibility    = LayoutVisibility.Always;
                layoutControlGroup2.Visibility = LayoutVisibility.Always;
                layoutControlGroup3.Visibility = LayoutVisibility.Always;
                layoutControlItem5.Visibility  = LayoutVisibility.Always;
                lytSelectAll.Visibility        = LayoutVisibility.Never;
                break;

            case ScanningMode.MedicalVisit:
                if (PEMRBusinessLogic.ActivePEMRObject != null &&
                    PEMRBusinessLogic.ActivePEMRObject.List_VisitTiming_Attachment != null)
                {
                    foreach (VisitTiming_Attachment visitTimingAttachement in PEMRBusinessLogic.ActivePEMRObject
                             .List_VisitTiming_Attachment)
                    {
                        PatientAttachment_cu patientAttachment = PatientAttachment_cu.ItemsList.Find(item =>
                                                                                                     Convert.ToInt32(item.ID)
                                                                                                     .Equals(Convert.ToInt32(visitTimingAttachement.PatientAttachement_CU_ID)));
                        if (patientAttachment != null)
                        {
                            if (ImagesList == null)
                            {
                                ImagesList = new List <PatientAttachment_cu>();
                            }
                            ImagesList.Add(patientAttachment);
                        }
                    }
                }

                emptySpaceItem3.Visibility     = LayoutVisibility.Never;
                layoutControlItem4.Visibility  = LayoutVisibility.Never;
                layoutControlItem3.Visibility  = LayoutVisibility.Never;
                layoutControlGroup2.Visibility = LayoutVisibility.Never;
                layoutControlGroup3.Visibility = LayoutVisibility.Never;
                layoutControlItem5.Visibility  = LayoutVisibility.Never;
                layoutControlItem15.Visibility = LayoutVisibility.Never;
                simpleSeparator4.Visibility    = LayoutVisibility.Never;
                layoutControlGroup2.Visibility = LayoutVisibility.Never;
                layoutControlGroup3.Visibility = LayoutVisibility.Never;
                layoutControlItem5.Visibility  = LayoutVisibility.Never;
                lytSelectAll.Visibility        = LayoutVisibility.Always;
                break;
            }

            switch (medicalType)
            {
            case MedicalType.InvestigationResult:
                chkPersonalPhoto.Enabled = false;
                chkID.Enabled            = false;
                chkPassport.Enabled      = false;
                chkInvestigation.Enabled = true;
                chkSurgery.Enabled       = false;
                chkLab.Enabled           = false;
                chkOther.Enabled         = false;
                chkInvestigation.Checked = true;
                break;

            case MedicalType.LabResult:
                chkPersonalPhoto.Enabled = false;
                chkID.Enabled            = false;
                chkPassport.Enabled      = false;
                chkInvestigation.Enabled = false;
                chkSurgery.Enabled       = false;
                chkLab.Enabled           = true;
                chkOther.Enabled         = false;
                chkLab.Checked           = true;
                break;

            case MedicalType.SurgeryResult:
                chkPersonalPhoto.Enabled = false;
                chkID.Enabled            = false;
                chkPassport.Enabled      = false;
                chkInvestigation.Enabled = false;
                chkLab.Enabled           = false;
                chkSurgery.Enabled       = true;
                chkOther.Enabled         = false;
                chkSurgery.Checked       = true;
                break;

            case MedicalType.None:
                chkPersonalPhoto.Enabled = true;
                chkID.Enabled            = true;
                chkPassport.Enabled      = true;
                chkSurgery.Enabled       = true;
                chkInvestigation.Enabled = true;
                chkLab.Enabled           = true;
                chkOther.Enabled         = true;
                chkPersonalPhoto.Checked = true;
                break;
            }

            CommonViewsActions.FillListBoxControl(lstImageNames, ImagesList, "ImageName");
            lstImageNames.Refresh();

            if (!string.IsNullOrEmpty(ApplicationStaticConfiguration.SkinName) &&
                !string.IsNullOrWhiteSpace(ApplicationStaticConfiguration.SkinName))
            {
                if (ApplicationStaticConfiguration.SkinName.Equals("McSkin"))
                {
                    lblPatientID.ForeColor               = Color.DarkOrange;
                    lblPatientName.ForeColor             = lblInsuranceCarrierName.ForeColor = lblInsuranceLevelName.ForeColor =
                        lblInsurancePercentage.ForeColor = Color.DarkBlue;
                    labelControl1.ForeColor              = labelControl3.ForeColor =
                        labelControl5.ForeColor          = labelControl7.ForeColor = Color.Black;
                    btnClose.Image = Properties.Resources.ExitIcon_8;
                }
                else
                {
                    lblPatientID.ForeColor               = Color.OrangeRed;
                    lblPatientName.ForeColor             = lblInsuranceCarrierName.ForeColor = lblInsuranceLevelName.ForeColor =
                        lblInsurancePercentage.ForeColor = Color.Ivory;
                    labelControl1.ForeColor              = labelControl3.ForeColor =
                        labelControl5.ForeColor          = labelControl7.ForeColor = Color.OldLace;
                    btnClose.Image = Properties.Resources.Exit_1_16;
                }
            }

            lblPatientID.Text   = ActiveSelectedPatient.Person_CU_ID.ToString();
            lblPatientName.Text = ActiveSelectedPatient.PatientFullName;
            if (ActiveSelectedPatient.InsuranceCarrier_InsuranceLevel_CU_ID != null)
            {
                InsuranceCarrier_InsuranceLevel_cu insuranceBridge =
                    InsuranceCarrier_InsuranceLevel_cu.ItemsList.Find(
                        item =>
                        Convert.ToInt32(item.ID)
                        .Equals(Convert.ToInt32(ActiveSelectedPatient.InsuranceCarrier_InsuranceLevel_CU_ID)));
                if (insuranceBridge != null)
                {
                    InsuranceCarrier_cu insuranceCarrier =
                        InsuranceCarrier_cu.ItemsList.Find(
                            item => Convert.ToInt32(item.ID).Equals(Convert.ToInt32(insuranceBridge.InsuranceCarrier_CU_ID)));
                    if (insuranceCarrier != null)
                    {
                        lblInsuranceCarrierName.Text = insuranceCarrier.Name_P;
                    }
                    InsuranceLevel_cu insurancelevel =
                        InsuranceLevel_cu.ItemsList.Find(
                            item => Convert.ToInt32(item.ID).Equals(Convert.ToInt32(insuranceBridge.InsuranceLevel_CU_ID)));
                    if (insurancelevel != null)
                    {
                        lblInsuranceLevelName.Text = insurancelevel.Name_P;
                    }
                    lblInsurancePercentage.Text = Convert.ToString(insuranceBridge.InsurancePercentage * 100);
                }
            }
        }
        private void btnOpen_Click(object sender, EventArgs e)
        {
            List <string> copiedImagesList =
                FileManager.FileDialogeAndCopy(ActiveSelectedPatient.Person_CU_ID.ToString(),
                                               FileManager.GetServerDirectoryPath(DB_ServerDirectory.ScanDirectory), true,
                                               FileSelectionFilter.Images, ref errorMessage,
                                               ActiveSelectedPatient.Person_CU_ID + "_" + (int)ImageType_P_ID + "_" + DateTime.Now.Date.Day +
                                               "_" + DateTime.Now.Date.Month + "_" + DateTime.Now.Date.Year);

            if (!string.IsNullOrEmpty(errorMessage))
            {
                XtraMessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error,
                                    MessageBoxDefaultButton.Button1, DefaultBoolean.Default);
                errorMessage = string.Empty;
                return;
            }

            if (copiedImagesList == null || copiedImagesList.Count == 0)
            {
                return;
            }

            if (ImagesList == null)
            {
                ImagesList = new List <PatientAttachment_cu>();
            }

            foreach (string fileName in copiedImagesList)
            {
                PatientAttachment_cu patientAttachment = MerkDBBusinessLogicEngine.CreateNewPatientAttachement(
                    ActiveSelectedPatient.Person_CU_ID,
                    Path.GetFileName(fileName), fileName, (DB_ImageType)ImageType_P_ID, Description,
                    ApplicationStaticConfiguration.ActiveLoginUser.Person_CU_ID);

                switch (ActiveScanningMode)
                {
                case ScanningMode.Regular:
                    if (MerkDBBusinessLogicEngine.SavePatientAttachement(patientAttachment))
                    {
                        ImagesList.Add(patientAttachment);
                    }
                    break;

                case ScanningMode.MedicalVisit:
                    VisitTiming_Attachment visitTimingAttachement =
                        PEMRBusinessLogic.CreateNew_VisitTiming_Attachment(
                            patientAttachment, ApplicationStaticConfiguration.ActiveLoginUser.Person_CU_ID);
                    if (visitTimingAttachement != null)
                    {
                        if (PEMRBusinessLogic.ActivePEMRObject.List_VisitTiming_Attachment == null)
                        {
                            PEMRBusinessLogic.ActivePEMRObject.List_VisitTiming_Attachment = new List <VisitTiming_Attachment>();
                        }
                    }
                    PEMRBusinessLogic.ActivePEMRObject.List_VisitTiming_Attachment.Add(visitTimingAttachement);
                    ImagesList.Add(patientAttachment);

                    break;
                }
            }

            txtDescription.EditValue = null;
            txtPictureName.EditValue = null;
            CommonViewsActions.FillListBoxControl(lstImageNames, ImagesList, "ImageName");
            lstImageNames.Refresh();
        }
        private void btnScanner_Click(object sender, EventArgs e)
        {
            if (txtPictureName.EditValue == null)
            {
                XtraMessageBox.Show("يجــب كتابــة إســم الصـــورة", "Note",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error,
                                    MessageBoxDefaultButton.Button1, DefaultBoolean.Default);
                return;
            }

            string savedPath = "";
            Image  image     = WIAScannerEngine.ScanFile(ActiveSelectedPatient.Person_CU_ID.ToString(),
                                                         ActiveSelectedPatient.Person_CU_ID + "_" + (int)ImageType_P_ID + "_" + DateTime.Now.Date.Day + "_" +
                                                         DateTime.Now.Date.Month + "_" + DateTime.Now.Date.Year + "_" + txtPictureName.Text, ImageFormat.JPEG,
                                                         false, ref savedPath, ref errorMessage);

            if (image == null)
            {
                if (!string.IsNullOrEmpty(errorMessage) && !string.IsNullOrWhiteSpace(errorMessage))
                {
                    XtraMessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error,
                                        MessageBoxDefaultButton.Button1, DefaultBoolean.Default);
                    errorMessage = string.Empty;
                    return;
                }
            }

            if (!string.IsNullOrEmpty(errorMessage) && !string.IsNullOrWhiteSpace(errorMessage))
            {
                XtraMessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error,
                                    MessageBoxDefaultButton.Button1, DefaultBoolean.Default);
                errorMessage = string.Empty;
                return;
            }

            pictureEdit1.Image = image;
            if (ImagesList == null)
            {
                ImagesList = new List <PatientAttachment_cu>();
            }

            PatientAttachment_cu patientAttachment = MerkDBBusinessLogicEngine.CreateNewPatientAttachement(
                ActiveSelectedPatient.Person_CU_ID,
                txtPictureName.Text, savedPath, (DB_ImageType)ImageType_P_ID, Description,
                ApplicationStaticConfiguration.ActiveLoginUser.Person_CU_ID);
            VisitTiming_InvestigationResult investigationResult    = null;
            VisitTiming_Attachment          visitTimingAttachement = null;

            switch (ActiveScanningMode)
            {
            case ScanningMode.Regular:
                if (MerkDBBusinessLogicEngine.SavePatientAttachement(patientAttachment))
                {
                    ImagesList.Add(patientAttachment);
                }
                break;

            case ScanningMode.MedicalVisit:
                visitTimingAttachement =
                    PEMRBusinessLogic.CreateNew_VisitTiming_Attachment(
                        patientAttachment, ApplicationStaticConfiguration.ActiveLoginUser.Person_CU_ID);
                if (visitTimingAttachement != null)
                {
                    if (PEMRBusinessLogic.ActivePEMRObject.List_VisitTiming_Attachment == null)
                    {
                        PEMRBusinessLogic.ActivePEMRObject.List_VisitTiming_Attachment = new List <VisitTiming_Attachment>();
                    }
                    PEMRBusinessLogic.ActivePEMRObject.List_VisitTiming_Attachment.Add(visitTimingAttachement);
                    ImagesList.Add(patientAttachment);

                    switch (MedicalType)
                    {
                    case MedicalType.InvestigationResult:
                        investigationResult =
                            PEMRBusinessLogic.CreateNew_VisitTiming_InvestigationResult(visitTimingAttachement,
                                                                                        Active_VisitTiming_InvestigationReservation,
                                                                                        ApplicationStaticConfiguration.ActiveLoginUser.Person_CU_ID);
                        if (investigationResult != null)
                        {
                            if (PEMRBusinessLogic.ActivePEMRObject.List_VisitTiming_InvestigationResult == null)
                            {
                                PEMRBusinessLogic.ActivePEMRObject.List_VisitTiming_InvestigationResult =
                                    new List <VisitTiming_InvestigationResult>();
                            }
                        }
                        PEMRBusinessLogic.ActivePEMRObject.List_VisitTiming_InvestigationResult.Add(
                            investigationResult);
                        break;
                    }
                }

                break;
            }

            txtDescription.EditValue = null;
            txtPictureName.EditValue = null;
            CommonViewsActions.FillListBoxControl(lstImageNames, ImagesList, "ImageName");
            lstImageNames.Refresh();

            if (investigationResult != null && visitTimingAttachement != null &&
                PEMRBusinessLogic.ActiveVisitTimming != null && SaveImmediately)
            {
                visitTimingAttachement.VisitTimingID = PEMRBusinessLogic.ActiveVisitTimming.ID;
                investigationResult.VisitTiming_InvestigationReservationID =
                    Active_VisitTiming_InvestigationReservation.ID;
                if (investigationResult.SaveChanges())
                {
                    PatientAttachment_cu.ItemsList.Add(patientAttachment);
                }
            }
        }