コード例 #1
0
ファイル: RACAPPrintLetter.cs プロジェクト: thobzabuyi/cyca
        public void AddRACAPCorrespondence(int id, string commentCap, string corId, string outputFileName, int loggedInUser, int iD)
        {
            var currentHoursAndMinutes = DateTime.Now.Hour.ToString("0#") + DateTime.Now.Minute.ToString("0#") + DateTime.Now.Millisecond.ToString("0#");
            RACAPPrintLetter Model     = new RACAPPrintLetter();

            var parentPersonalinformation = Model.GetparentPersonalinformation(id);
            var racapCorTable             = new RACAP_Correspondence();

            racapCorTable.RACAP_Correspondence_Comments = commentCap;
            racapCorTable.RACAP_Case_Id = id;
            racapCorTable.RACAP_Correspondence_Type_Id      = Convert.ToInt32(corId);
            racapCorTable.RACAP_Correspondence_FileName     = iD + "_" + Convert.ToInt32(corId) + ".pdf";
            racapCorTable.RACAP_Correspondence_Date_Created = DateTime.Now;
            var userModel = new UserModel();

            racapCorTable.RACAP_Correspondence_Created_By = loggedInUser;
            racapCorTable.RACAP_Correspondence_FilePath   = "RACAPDocumentPath";
            _db.RACAP_Correspondence.Add(racapCorTable);
            _db.SaveChanges();
        }
コード例 #2
0
        public void ExportToWord(MainPageModelRACAPVM cases, int userId, int Assid)
        {
            string FileName = "";

            if (cases.RACAPCaseViewModel != null)
            {
                if (cases.RACAPCaseViewModel.RACAP_Correspondence_Type_Id == 1)
                {
                    FileName = "General_letter_English";
                }
                if (cases.RACAPCaseViewModel.RACAP_Correspondence_Type_Id == 2)
                {
                    FileName = "Reminder_letter_English";
                }
                if (cases.RACAPCaseViewModel.RACAP_Correspondence_Type_Id == 3)
                {
                    FileName = "Fault_letter_English";
                }
                if (cases.RACAPCaseViewModel.RACAP_Correspondence_Type_Id == 4)
                {
                    FileName = "Acknowledgment_letter_English";
                }
                if (cases.RACAPCaseViewModel.RACAP_Correspondence_Type_Id == 5)
                {
                    FileName = "Cover_letter_English";
                }
                if (cases.RACAPCaseViewModel.RACAP_Correspondence_Type_Id == 6)
                {
                    FileName = "Home_Affairs_letter_English";
                }
                if (cases.RACAPCaseViewModel.RACAP_Correspondence_Type_Id == 7)
                {
                    FileName = "Enquiries_letter_English";
                }
                if (cases.RACAPCaseViewModel.RACAP_Correspondence_Type_Id == 8)
                {
                    FileName = "Regret_letter_English";
                }


                string savePath     = ("C:/Users/hermanb.MAIL1/Documents/Visual Studio 2015/Projects/SDIIS (2)/SDIIS_Latest/SDIIS/RACAP_Module/App_Data/" + Assid + FileName + ".doc");
                string templatePath = ("C:\\Users\\hermanb.MAIL1\\Documents\\Visual Studio 2015\\Projects\\SDIIS (2)\\SDIIS_Latest\\SDIIS\\RACAP_Module\\App_Data\\" + FileName + ".dot");
                Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
                Microsoft.Office.Interop.Word.Document    doc = new Microsoft.Office.Interop.Word.Document();
                doc = app.Documents.Open(templatePath);
                doc.Activate();

                int?ChildPersonIDForCHildName = (from c in dbF.RACAP_Prospective_Parent
                                                 join d in dbF.RACAP_Matches on c.RACAP_Prospective_Parent_Id equals d.RACAP_Prospective_Parent_Id
                                                 join e in dbF.RACAP_Adoptive_Child on d.RACAP_Adoptive_Child_Id equals e.RACAP_Adoptive_Child_Id
                                                 join f in dbF.RACAP_Case_Details on e.RACAP_Case_Id equals f.RACAP_Case_Id
                                                 join g in dbF.Intake_Assessments on f.Intake_Assessment_Id equals g.Intake_Assessment_Id
                                                 join h in dbF.Clients on g.Client_Id equals h.Client_Id

                                                 where c.Intake_Assessment_Id == Assid
                                                 select h.Person_Id).FirstOrDefault();
                int?ParentPersonIdForClientName = (from i in dbF.Intake_Assessments
                                                   join h in dbF.Clients on i.Client_Id equals h.Client_Id
                                                   where i.Intake_Assessment_Id == Assid
                                                   select h.Person_Id).FirstOrDefault();



                if (doc.Bookmarks.Exists("ClientName") && ParentPersonIdForClientName != 0 && ParentPersonIdForClientName != null)
                {
                    doc.Bookmarks["ClientName"].Range.Text = dbF.Persons.Find(ParentPersonIdForClientName).First_Name + " " + dbF.Persons.Find(ParentPersonIdForClientName).Last_Name;
                }
                if (doc.Bookmarks.Exists("CHildName") && ChildPersonIDForCHildName != 0 && ChildPersonIDForCHildName != null)
                {
                    doc.Bookmarks["CHildName"].Range.Text = dbF.Persons.Find(ChildPersonIDForCHildName).First_Name + " " + dbF.Persons.Find(ChildPersonIDForCHildName).Last_Name;
                }
                if (doc.Bookmarks.Exists("CHildID") && ChildPersonIDForCHildName != 0 && ChildPersonIDForCHildName != null)
                {
                    doc.Bookmarks["CHildID"].Range.Text = dbF.Persons.Find(ChildPersonIDForCHildName).Identification_Number;
                }

                AddressModel GetAdd = new AddressModel();
                PersonModel  GetPer = new PersonModel();

                var Add       = dbF.Persons.Find(ParentPersonIdForClientName).Addresses.FirstOrDefault();
                int AddressId = Add.Address_Id;
                int PerSonId  = (from a in dbF.Intake_Assessments
                                 join b in dbF.Clients on a.Client_Id equals b.Client_Id
                                 join c in dbF.Persons on b.Person_Id equals c.Person_Id
                                 where a.Intake_Assessment_Id == Assid
                                 select c.Person_Id).FirstOrDefault();
                bool AddressCheck = false;
                if (AddressId > 0 && dbF.Addresses.Find(AddressId).Address_Line_1 != null)
                {
                    AddressCheck = true;
                }
                else
                {
                    AddressCheck = false;
                }
                bool CheckEmail = false;
                if (dbF.Persons.Find(PerSonId).Email_Address != null)
                {
                    CheckEmail = true;
                }
                else
                {
                    CheckEmail = false;
                }

                if (doc.Bookmarks.Exists("StrAdr") && ParentPersonIdForClientName != 0 && ParentPersonIdForClientName != null && AddressCheck == true)
                {
                    doc.Bookmarks["StrAdr"].Range.Text = GetAdd.GetSpecificAddress(AddressId).Address_Line_1;
                }
                if (doc.Bookmarks.Exists("StrAdr") && ParentPersonIdForClientName != 0 && ParentPersonIdForClientName != null && AddressCheck == false)
                {
                    doc.Bookmarks["StrAdr"].Range.Text = "Not completed";
                }
                if (doc.Bookmarks.Exists("TownAdr") && ParentPersonIdForClientName != 0 && ParentPersonIdForClientName != null && AddressCheck == true)
                {
                    doc.Bookmarks["TownAdr"].Range.Text = dbF.Towns.Find(GetAdd.GetSpecificAddress(AddressId).Town_Id).Description;
                }
                if (doc.Bookmarks.Exists("TownAdr") && ParentPersonIdForClientName != 0 && ParentPersonIdForClientName != null && AddressCheck == false)
                {
                    doc.Bookmarks["TownAdr"].Range.Text = "Not completed";
                }
                if (doc.Bookmarks.Exists("PCodeAdr") && ParentPersonIdForClientName != 0 && ParentPersonIdForClientName != null && AddressCheck == true)
                {
                    doc.Bookmarks["PCodeAdr"].Range.Text = GetAdd.GetSpecificAddress(AddressId).Postal_Code;
                }
                if (doc.Bookmarks.Exists("PCodeAdr") && ParentPersonIdForClientName != 0 && ParentPersonIdForClientName != null && AddressCheck == false)
                {
                    doc.Bookmarks["PCodeAdr"].Range.Text = "Not completed";
                }

                if (doc.Bookmarks.Exists("ContactPerson") && ParentPersonIdForClientName != 0 && ParentPersonIdForClientName != null)
                {
                    doc.Bookmarks["ContactPerson"].Range.Text = dbF.Persons.Find(ParentPersonIdForClientName).First_Name + " " + dbF.Persons.Find(ParentPersonIdForClientName).Last_Name;
                }
                if (doc.Bookmarks.Exists("Date"))
                {
                    doc.Bookmarks["Date"].Range.Text = Convert.ToString(DateTime.Now.ToLongDateString());
                }
                if (doc.Bookmarks.Exists("ClientLetterDate"))
                {
                    doc.Bookmarks["ClientLetterDate"].Range.Text = Convert.ToString(DateTime.Now.ToLongDateString());
                }
                if (doc.Bookmarks.Exists("DateOfReg"))
                {
                    doc.Bookmarks["DateOfReg"].Range.Text = Convert.ToDateTime((from d in dbF.RACAP_Case_Details
                                                                                where d.Intake_Assessment_Id == Assid
                                                                                select d.Date_Registered).FirstOrDefault()).ToString("dd MMMM yyyy");
                }
                if (doc.Bookmarks.Exists("ChildDateOfBirth") && ChildPersonIDForCHildName != 0 && ChildPersonIDForCHildName != null)
                {
                    doc.Bookmarks["ChildDateOfBirth"].Range.Text = Convert.ToString(dbF.Persons.Find(ChildPersonIDForCHildName).Date_Of_Birth);
                }
                if (doc.Bookmarks.Exists("BiologicalMother") && ParentPersonIdForClientName != 0 && ParentPersonIdForClientName != null)
                {
                    doc.Bookmarks["BiologicalMother"].Range.Text = dbF.Persons.Find(ParentPersonIdForClientName).First_Name + " " + dbF.Persons.Find(ParentPersonIdForClientName).Last_Name;
                }
                int MotherClientId = (from m in dbF.Client_Biological_Parents
                                      where m.Person_Id == ParentPersonIdForClientName
                                      select m.Client_Biological_Parent_Id).FirstOrDefault();
                if (doc.Bookmarks.Exists("BiologicalMotherCountry") && ParentPersonIdForClientName != 0 && ParentPersonIdForClientName != null)
                {
                    doc.Bookmarks["BiologicalMotherCountry"].Range.Text = Convert.ToString(dbF.Persons.Find(ParentPersonIdForClientName).Population_Group);
                }
                if (doc.Bookmarks.Exists("BiologicalMotherState") && ParentPersonIdForClientName != 0 && ParentPersonIdForClientName != null)
                {
                    doc.Bookmarks["BiologicalMotherState"].Range.Text = Convert.ToString(dbF.Persons.Find(ParentPersonIdForClientName).Population_Group);
                }
                if (doc.Bookmarks.Exists("BiologicalMotherLanguage") && ParentPersonIdForClientName != 0 && ParentPersonIdForClientName != null)
                {
                    doc.Bookmarks["BiologicalMotherLanguage"].Range.Text = Convert.ToString(dbF.Persons.Find(ParentPersonIdForClientName).Language);
                }
                if (doc.Bookmarks.Exists("AdoptionCity") && AddressCheck == true)
                {
                    doc.Bookmarks["AdoptionCity"].Range.Text = dbF.Towns.Find(GetAdd.GetSpecificAddress(AddressId).Town_Id).Description;
                }
                int?RelId = (from r in dbF.RACAP_Prospective_Parent
                             where r.RACAP_Case_Id == Assid
                             select r.Religion_Id).FirstOrDefault();
                if (doc.Bookmarks.Exists("BiologicalMotherChurch"))
                {
                    if (RelId != null)
                    {
                        doc.Bookmarks["BiologicalMotherChurch"].Range.Text = dbF.Religions.Find(RelId).Description;
                    }
                }
                if (doc.Bookmarks.Exists("BiologicalFather") && ParentPersonIdForClientName != 0 && ParentPersonIdForClientName != null)
                {
                    doc.Bookmarks["BiologicalFather"].Range.Text = dbF.Persons.Find(ParentPersonIdForClientName).First_Name + " " + dbF.Persons.Find(ParentPersonIdForClientName).Last_Name;
                }
                if (doc.Bookmarks.Exists("ChildBirthPlace") && AddressCheck == true)
                {
                    doc.Bookmarks["ChildBirthPlace"].Range.Text = dbF.Towns.Find(GetAdd.GetSpecificAddress(AddressId).Town_Id).Description;
                }
                if (doc.Bookmarks.Exists("ChildNameAtBirth") && ChildPersonIDForCHildName != 0 && ChildPersonIDForCHildName != null)
                {
                    doc.Bookmarks["ChildNameAtBirth"].Range.Text = dbF.Persons.Find(ChildPersonIDForCHildName).First_Name + " " + dbF.Persons.Find(ChildPersonIDForCHildName).Last_Name;
                }
                if (doc.Bookmarks.Exists("SubmissionDate"))
                {
                    doc.Bookmarks["SubmissionDate"].Range.Text = Convert.ToDateTime((from d in dbF.RACAP_Case_Details
                                                                                     where d.Intake_Assessment_Id == Assid
                                                                                     select d.Date_Registered).FirstOrDefault()).ToString("dd MMMM yyyy");
                }
                if (doc.Bookmarks.Exists("PlaceOfExec") && AddressCheck == true)
                {
                    doc.Bookmarks["PlaceOfExec"].Range.Text = dbF.Towns.Find(GetAdd.GetSpecificAddress(AddressId).Town_Id).Description;
                }
                if (doc.Bookmarks.Exists("PlaceOfExec") && AddressCheck == false)
                {
                    doc.Bookmarks["PlaceOfExec"].Range.Text = "Not Completed";
                }
                if (doc.Bookmarks.Exists("Email") && ParentPersonIdForClientName != 0 && ParentPersonIdForClientName != null && CheckEmail == true)
                {
                    doc.Bookmarks["Email"].Range.Text = dbF.Persons.Find(ParentPersonIdForClientName).Email_Address;
                }
                if (doc.Bookmarks.Exists("Email") && ParentPersonIdForClientName != 0 && ParentPersonIdForClientName != null && CheckEmail == false)
                {
                    doc.Bookmarks["Email"].Range.Text = "Not completed";
                }
                if (doc.Bookmarks.Exists("Enquiries"))
                {
                    doc.Bookmarks["Enquiries"].Range.Text = "testc";
                }
                if (doc.Bookmarks.Exists("RefNumber") && ParentPersonIdForClientName != 0 && ParentPersonIdForClientName != null)
                {
                    doc.Bookmarks["RefNumber"].Range.Text = (from r in dbF.Clients
                                                             where r.Person_Id == ParentPersonIdForClientName
                                                             select r.Reference_Number).FirstOrDefault();
                }
                if (doc.Bookmarks.Exists("Telephone") && ParentPersonIdForClientName != 0 && ParentPersonIdForClientName != null)
                {
                    doc.Bookmarks["Telephone"].Range.Text = dbF.Persons.Find(ParentPersonIdForClientName).Phone_Number;
                }
                doc.SaveAs2(savePath);
                app.Application.Quit();

                int Case_Id = (from s in dbF.RACAP_Case_Details
                               where s.Intake_Assessment_Id == Assid
                               select s.RACAP_Case_Id).FirstOrDefault();
                RACAP_Correspondence RCorr = (from c in dbF.RACAP_Correspondence
                                              where c.RACAP_Case_Id == Case_Id && c.RACAP_Correspondence_Type_Id == cases.RACAPCaseViewModel.RACAP_Correspondence_Type_Id
                                              select c).FirstOrDefault();
                if (RCorr != null)
                {
                    RCorr.RACAP_Case_Id = Case_Id;
                    RCorr.RACAP_Correspondence_FileName = Assid + FileName;
                    RCorr.RACAP_Correspondence_FilePath = "~/App_Data/";
                    RCorr.RACAP_Correspondence_Type_Id  = cases.RACAPCaseViewModel.RACAP_Correspondence_Type_Id;
                    RCorr.RACAP_Correspondence_Comments = cases.RACAPCaseViewModel.RACAP_Correspondence_Comments;
                    dbF.SaveChanges();
                }
            }
        }