示例#1
0
        public void run(FormStrings formStrings)
        {
            string filePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +
                              @"\VillaFarms,LeaseMaker\BaseFolder\lease.docx";
            string fileResult = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +
                                @"\VillaFarms,LeaseMaker\PastPrinting\" +
                                @formStrings.residentName + " Lease " + formStrings.signYear + ".docx";

            //Tries to find and edit a doc. Base doc is formated to find keywords and replace them.
            try
            {
                var dc = DocX.Load(filePath);
                dc.ReplaceText("[[residentName]]", formStrings.residentName);
                //Resident 2 might not exist.
                if (formStrings.resident2Name != "")
                {
                    dc.ReplaceText("[[resident2NameOpening]]", " (and " + formStrings.resident2Name + ") ");
                    dc.ReplaceText("[[resident2Name]]", formStrings.resident2Name +
                                   "\n\tX____________________________________________________________________");
                }

                else
                {
                    dc.ReplaceText("[[resident2Name]]", "");
                    dc.ReplaceText("[[resident2NameOpening]]", "");
                }

                dc.ReplaceText("[[lotNum]]", formStrings.lotNum);
                dc.ReplaceText("[[monthLength]]", formStrings.monthLength.ToWrittenWord() +
                               " (" + formStrings.monthLength + ")");
                dc.ReplaceText("[[payExecution]]", "$" + formStrings.payExecution + ".00");
                dc.ReplaceText("[[payRent]]", "$" + formStrings.payRent + ".00");
                dc.ReplaceText("[[amountPaid]]", "$" + formStrings.amountPaid + ".00");
                dc.ReplaceText("[[balanceDue]]", "$" + formStrings.balanceDue + ".00");
                dc.ReplaceText("[[signDay]]", long.Parse(formStrings.signDay).ToOrdinal().ToString());
                dc.ReplaceText("[[leaseDay]]", long.Parse(formStrings.leaseDay).ToOrdinal().ToString());
                dc.ReplaceText("[[endDay]]", long.Parse(formStrings.endDay).ToOrdinal().ToString());
                dc.ReplaceText("[[signMonth]]", Int32.Parse(formStrings.signMonth).MonthDic());
                dc.ReplaceText("[[leaseMonth]]", Int32.Parse(formStrings.signMonth).MonthDic());
                dc.ReplaceText("[[endMonth]]", Int32.Parse(formStrings.signMonth).MonthDic());
                dc.ReplaceText("[[signYear]]", formStrings.signYear);
                dc.ReplaceText("[[leaseYear]]", formStrings.leaseYear);
                dc.ReplaceText("[[endYear]]", formStrings.endYear);
                dc.ReplaceText("[[preparer]]", formStrings.preparer);


                dc.SaveAs(fileResult);
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(fileResult)
                {
                    UseShellExecute = true
                });
            }

            //Locks prevent multiple files being open at once.
            catch (Exception)
            {
                MessageBox.Show("Error saving. Are you sure Document isn't already opened? Try closing it.", "ERROR");
            }
        }
示例#2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            loader            = new FormStrings();
            residentText.Text = loader.residentName;
            DateTime dt = new DateTime();

            dt = DateTime.Now;
            string jsonFromFile;

            //Based off the user's system. Has a formatted .docx file.
            using (var reader = new StreamReader(
                       Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +
                       @"\VillaFarms,LeaseMaker\BaseFolder\lease.json"
                       ))
            {
                jsonFromFile = reader.ReadToEnd();
            };

            //A Json file has the default values for the form. Changes when updated.
            loader            = JsonConvert.DeserializeObject <FormStrings>(jsonFromFile);
            residentText.Text = loader.residentName;
            //Resident 2 is an optional thing that might not exist.
            if (loader.resident2Name != "")
            {
                resident2Text.Text = loader.resident2Name;
            }
            lotText.Text         = loader.lotNum;
            lotText.Text         = loader.lotNum;
            leaseLengthText.Text = loader.monthLength;
            initialCostText.Text = loader.payExecution;
            rentText.Text        = loader.payRent;
            amountPaidText.Text  = loader.amountPaid;
            balanceDueText.Text  = loader.balanceDue;
            preparerText.Text    = loader.preparer;

            dt = dt.AddMonths(1);
            dt = dt.AddDays(-1 * dt.Day + 1);
            leasePicker.Value = dt;
            dt = dt.AddMonths(Int32.Parse(loader.monthLength));
            dt = dt.AddDays(-1);
            endPicker.Value = dt;
        }