Ejemplo n.º 1
0
        protected override void ExecItemImport()
        {
            dlgOpen.Filter = Pub.GetResText(formCode, "CustomReportFile", "") + "(*.grd)|*.grd";
            if (dlgOpen.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            Pub.ExpandFile(dlgOpen.FileName, SystemInfo.ReportPath);
            StreamReader sr             = null;
            string       reportTitle    = "";
            string       reportView     = "";
            string       reportViewFile = "";
            string       reportFile     = "";
            byte         DateFlag       = 0;
            string       DateField      = "";
            string       OrderField     = "";

            try
            {
                sr = new StreamReader(SystemInfo.ReportPath + "report.txt", Encoding.Default);
                string s = "";
                int    i = 0;
                while (!sr.EndOfStream)
                {
                    s = sr.ReadLine();
                    switch (i)
                    {
                    case 0:
                        reportTitle = s;
                        break;

                    case 1:
                        reportView = s;
                        break;

                    case 2:
                        reportViewFile = s;
                        break;

                    case 3:
                        reportFile = s;
                        break;

                    case 4:
                        byte.TryParse(s, out DateFlag);
                        break;

                    case 5:
                        DateField = s;
                        break;

                    case 6:
                        OrderField = s;
                        break;
                    }
                    i += 1;
                }
            }
            catch (Exception E)
            {
                Pub.ShowErrorMsg(E);
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
            }
            if (reportTitle == "")
            {
                Pub.ShowErrorMsg(Pub.GetResText(formCode, "ErrorReportNameEmpty", ""));
                return;
            }
            if (reportView == "")
            {
                Pub.ShowErrorMsg(Pub.GetResText(formCode, "ErrorReportViewEmpty", ""));
                return;
            }
            if (reportViewFile != "")
            {
                reportViewFile = SystemInfo.ReportPath + reportViewFile;
            }
            if (reportFile != "")
            {
                reportFile = SystemInfo.ReportPath + reportFile;
            }
            if ((reportFile == "") || !File.Exists(reportFile))
            {
                Pub.ShowErrorMsg(Pub.GetResText(formCode, "ErrorReportFileNotExists", ""));
                return;
            }
            if ((reportViewFile != "") && File.Exists(reportViewFile))
            {
                if (!db.UpdateScript(reportViewFile))
                {
                    return;
                }
            }
            bool            IsOk = true;
            DataTableReader dr   = null;

            try
            {
                dr = db.GetDataReader(Pub.GetSQL(DBCode.DB_000001, new string[] { "602", ReportTable, reportTitle }));
                if (dr.Read())
                {
                    Pub.ShowErrorMsg(Pub.GetResText(formCode, "ErrorReportNameRepeat", ""));
                    IsOk = false;
                }
                dr.Close();
                if (IsOk)
                {
                    string sql = Pub.GetSQL(DBCode.DB_000001, new string[] { "603", ReportTable, reportTitle, reportView,
                                                                             OrderField, DateFlag.ToString(), DateField });
                    db.ExecSQL(sql);
                    sr = new StreamReader(reportFile, Encoding.Default);
                    string reportData = sr.ReadToEnd();
                    db.UpdateTextData(Pub.GetSQL(DBCode.DB_000001, new string[] { "303", ReportTable,
                                                                                  reportTitle }), "ReportData", reportData);
                }
            }
            catch (Exception E)
            {
                Pub.ShowErrorMsg(E);
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                }
                dr = null;
                if (sr != null)
                {
                    sr.Close();
                }
            }
            ExecItemRefresh();
        }