Пример #1
0
        private string getData()
        {
            if (_selectedFieldsTitle.Count < 2)
            {
                _reprotState = false;
                return("");
            }
            _reprotState = true;
            string data = "";
            string flds = "";
            string t;

            _dataSet = (RMX_TOOLS.common.AbstractCommonData)MainForm.getDataSet();
            for (int i = 0; i < _dataSet.Tables[0].Rows.Count; i++)
            {
                t = Insurance.ExportToExcel.generalizeData(_selectedFields[0].ToString(), _dataSet.Tables[0].Rows[i][_selectedFields[0].ToString()].ToString().Trim());

                flds = "<Row>\n\t<Cell ss:Index=\"3\"><Data ss:Type=\"String\">" + t + "</Data></Cell>\n";
                for (int j = 1; j < _selectedFields.Count; j++)
                {
                    t     = ExportToExcel.generalizeData(_selectedFields[j].ToString(), _dataSet.Tables[0].Rows[i][_selectedFields[j].ToString()].ToString().Trim());
                    flds += "\t<Cell><Data ss:Type=\"String\">" + t + "</Data></Cell>\n";
                }
                data += flds + "</Row>\n";
            }
            return(data);
        }
Пример #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            //prepare fields
            ArrayList selectedFields      = new ArrayList();
            ArrayList selectedFieldsTitle = new ArrayList();

            //selectedFields.Add(ViewInsuranceInfoData.RADIF_FIELD);
            //selectedFieldsTitle.Add("ردیف");

            selectedFields.Add(ViewInsuranceInfoData.mobileNumber_FIELD);
            selectedFieldsTitle.Add("شماره موبایل");

            selectedFields.Add(ViewInsuranceInfoData.name_FIELD);
            selectedFieldsTitle.Add("نام");

            selectedFields.Add(ViewInsuranceInfoData.family_FIELD);
            selectedFieldsTitle.Add("نام خانوادگی");


            //selectedFields.Add(ViewInsuranceInfoData.insuranceNumber_FIELD);
            //selectedFieldsTitle.Add("شماره بیمه");
            selectedFields.Add("");
            selectedFieldsTitle.Add("شرکت/سازمان");

            selectedFields.Add("");
            selectedFieldsTitle.Add("ایمیل");

            selectedFields.Add("");
            selectedFieldsTitle.Add("نام مستعار");

            selectedFields.Add("");
            selectedFieldsTitle.Add("جنسیت");

            selectedFields.Add("");
            selectedFieldsTitle.Add("تلفن");

            selectedFields.Add("");
            selectedFieldsTitle.Add("فاکس");

            selectedFields.Add("");
            selectedFieldsTitle.Add("کد پستی");

            selectedFields.Add("");
            selectedFieldsTitle.Add("آدرس");

            selectedFields.Add("");
            selectedFieldsTitle.Add("توضیحات");

            selectedFields.Add("");
            selectedFieldsTitle.Add("متن اضافی");

            selectedFields.Add(ViewInsuranceInfoData.BirthDate_FIELD + "_SHAMSI");
            selectedFieldsTitle.Add("تاریخ تولد");

            selectedFields.Add(ViewInsuranceInfoData.endDate_FIELD + "_SHAMSI");
            selectedFieldsTitle.Add("تاریخ مناسبت");

            //Prepare template file
            String templateFile = Application.StartupPath + "\\" + "ReportTemplate.xml";
            String reportFile   = Application.StartupPath + "\\" + "ExportToExcelData.xml";

            TextReader tr      = new StreamReader(templateFile);
            String     fileStr = tr.ReadToEnd();


            for (int i = 0; i < _dataSource.Tables[0].Rows.Count; i++)
            {
                _dataSource.Tables[0].Rows[i][ViewInsuranceInfoData.endDate_FIELD + "_SHAMSI"] =
                    RMX_TOOLS.date.DateXFormer.gregorianToPersianString((DateTime)
                                                                        _dataSource.Tables[0].Rows[i][ViewInsuranceInfoData.endDate_FIELD]);
            }
            //
            string reportName = "";//no need
            string todayDate  = "";
            string title      = getTitles(selectedFields, selectedFieldsTitle);
            string allData    = ExportToExcel.getData(_dataSource, selectedFields, selectedFieldsTitle);

            //
            if (fileStr == null || fileStr.Length <= 0)
            {
                MessageBox.Show("در خواندن فایل ReportTemplate.xml مشکلی رخ داده ");
                return;
            }
            int row = _dataSource.Tables[0].Rows.Count + 4;

            fileStr = fileStr.Replace(_userNameTemplate, reportName);
            fileStr = fileStr.Replace(_DateTemplate, todayDate);
            fileStr = fileStr.Replace(_TitleTemplate, title);
            fileStr = fileStr.Replace(_DataTemplate, allData);
            fileStr = fileStr.Replace(_Row, row + "");

            System.IO.StreamWriter _excelDoc;
            _excelDoc = new System.IO.StreamWriter(reportFile);
            _excelDoc.Write(fileStr);
            _excelDoc.Close();
            string path = reportFile;

            // System.Diagnostics.Process.Start(path);
            Insurance.ExportToExcel.executeExcel(reportFile);
        }