Exemple #1
0
        protected override void Preview()
        {
            base.Preview();

            //print the first item on selection
            String      reportFormName = VLookupProvider.DataSetLookup(VLookupProvider.dstSystemPrintouts, "FormCaption", this.Caption, "PrintoutFormName").ToString();
            IParentForm reportForm     = IAppHandler.FindForm(reportFormName, "Printout", true);

            if (reportForm == null)
            {
                IMessageHandler.ShowError(ISystemMessages.PrintoutNotSet);
            }
            else
            {
                IAppHandler.AddUsedForm(this);
                this.Hide();

                if (reportForm.Parameters.Find(p => p.Name == "Id") != null)
                {
                    reportForm.Parameters.Find(p => p.Name == "Id").Value = this.Parameters.Find(pa => pa.Name == "Id").Value;
                }

                (reportForm as IReportForm).PrintoutHeader = this.Caption;
                reportForm.Run();
            }
        }
        //loads selection for printout
        private void LoadPrintoutSelection()
        {
            if (FormState == FormStates.fsView &&
                !IsListForm())
            {
                foreach (DataRow row in VLookupProvider.dstSystemPrintouts.DataTable.Select(String.Format("FormCaption = '{0}'", this.Caption)))
                {
                    ToolStripMenuItem item = new ToolStripMenuItem();

                    item.Name   = "toolStripMenuItemPrint" + row["Report"].ToString().Replace(" ", "");
                    item.Text   = row["Report"].ToString();
                    item.Tag    = row["PrintoutFormName"].ToString();
                    item.Click += (obj, ea) =>
                    {
                        IParentForm reportForm = IAppHandler.FindForm(item.Tag.ToString(), "Printout", true);

                        if (reportForm == null)
                        {
                            IMessageHandler.ShowError(ISystemMessages.PrintoutNotSet);
                        }
                        else
                        {
                            IAppHandler.AddUsedForm(this);
                            this.Hide();

                            if (reportForm.Parameters.Find(p => p.Name == "Id") != null)
                            {
                                reportForm.Parameters.Find(p => p.Name == "Id").Value = this.Parameters.Find(pa => pa.Name == "Id").Value;
                            }

                            (reportForm as IReportForm).PrintoutHeader = this.Caption;
                            reportForm.Run();
                        }
                    };

                    if (btnPreview.DropDownItems.Find(item.Name, true).Length == 0)
                    {
                        btnPreview.DropDownItems.Add(item);
                    }
                }
            }
        }
        protected virtual void OnOpenForm(IParentForm Form, object sender)
        {
            String senderName = null;

            if (sender.GetType().Name == "ToolStripButton" && (sender as ToolStripButton).Name == "btnNew")
            {
                senderName = "btnNew";
                Form       = IAppHandler.FindForm(this.NewFormName);
            }
            else
            {
                Form = IAppHandler.FindForm(this.OpenFormName);
            }

            try
            {
                IAppHandler.StartBusy("Opening master form");

                if (Form == null)
                {
                    if (senderName == "btnNew")
                    {
                        IMessageHandler.Inform(ISystemMessages.NoFormFound(this.NewFormName));
                    }
                    else
                    {
                        IMessageHandler.Inform(ISystemMessages.NoFormFound(this.OpenFormName));
                    }

                    return;
                }

                if (senderName == "btnNew")
                {
                    Form.FormState = FormStates.fsNew;
                }
                else
                {
                    Form.FormState = FormStates.fsView;
                }

                for (int i = 0; i <= this.Parameters.Count - 1; i++)
                {
                    for (int j = 0; j <= Form.Parameters.Count - 1; j++)
                    {
                        if (this.Parameters[i].Name == Form.Parameters[j].Name)
                        {
                            Form.Parameters[j].Value = this.Parameters[i].Value;
                        }

                        if (Form.Parameters[j].Name == "Id")
                        {
                            if (Form.FormState == FormStates.fsNew)
                            {
                                Form.Parameters[j].Value = String.Empty;
                            }
                            else
                            {
                                Form.Parameters[j].Value = GetSelectedValueOnGrid(dataGridView, 0, "dataGridViewColumnId");
                            }
                        }
                    }
                }

                if (OpenForm != null)
                {
                    OpenForm();
                }

                (Form as IMasterForm).KeyList.Clear();
                for (int i = 0; i <= dataGridView.Rows.Count - 1; i++)
                {
                    (Form as IMasterForm).KeyList.Add(dataGridView.Rows[i].Cells[0].Value.ToString());
                    if (Form.Parameters[0].Value == dataGridView.Rows[i].Cells[0].Value.ToString())
                    {
                        (Form as IMasterForm).KeyId = i;
                    }
                }

                IAppHandler.AddUsedForm(this);
                this.Hide();
                Form.Run();
            }
            finally
            {
                IAppHandler.EndBusy("Opening master form");
            }
        }