Beispiel #1
0
 private void InportDataSource(DataTable tableResult, DataGridView dataGridView)
 {
     if (tableResult != null)
     {
         if (tableResult.Columns.Contains("EPC") || tableResult.Columns.Contains("RFU") || tableResult.Columns.Contains("USER"))
         {
             cmaxPage        = tableResult.Rows.Count / csize;
             cminPage        = 0;
             tableCollection = tableResult;
             cfixColumn      = tableCollection.Columns.Count;
             tables          = new DataTable[cmaxPage + 1];
             for (int i = cminPage; i < cmaxPage + 1; i++)
             {
                 tables[i] = PageFun.PageDataTableClone(tableCollection, i, csize);
             }
             dataGridView.DataSource = tables[cminPage];
             // m_SyncContext.Post(UpdataDataGrid, PageFun.PageDataTableClone(tableCollection, minPage, size));
             UpdateGridviewHeader(cminPage, csize);
             label1.Text = ccurrentPage.ToString();
             label3.Text = cmaxPage.ToString();
         }
         else
         {
             MessageBox.Show(importErrorMsgStr);
         }
     }
 }
Beispiel #2
0
        private void CompleteDataToolStripMenuItem_Click(object sender, EventArgs e)
        {
            InportDataSource(PageFun.GetTables(), this.dataGridView1);
            Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            cfa.AppSettings.Settings["Mode"].Value = "2";
            cfa.Save();
        }
Beispiel #3
0
        private void AreaCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            byte sample = 1;

            switch (AreaCB.SelectedIndex)
            {
            case 0:
                if (WriteTagDataFormat.tables.ContainsKey("RFU"))
                {
                    startStrTb.Text       = PageFun.AddSpace(WriteTagDataFormat.tables["RFU"].startStr);
                    stepTb.Text           = WriteTagDataFormat.tables["RFU"].step.ToString();
                    startAddSampleTb.Text = PageFun.AddSpace(string.Format("{0}", sample.ToString("D" + WriteTagDataFormat.tables["RFU"].len * 4)));
                    areaSampleL.Text      = "";
                }
                else
                {
                    areaSampleL.Text = NoArea;
                }
                break;

            case 1:
                if (WriteTagDataFormat.tables.ContainsKey("EPC"))
                {
                    startStrTb.Text       = PageFun.AddSpace(WriteTagDataFormat.tables["EPC"].startStr);
                    stepTb.Text           = WriteTagDataFormat.tables["EPC"].step.ToString();
                    startAddSampleTb.Text = PageFun.AddSpace(string.Format("{0}", sample.ToString("D" + WriteTagDataFormat.tables["EPC"].len * 4)));
                    areaSampleL.Text      = "";
                }
                else
                {
                    areaSampleL.Text = NoArea;
                }
                break;

            case 2:
                if (WriteTagDataFormat.tables.ContainsKey("USER"))
                {
                    startStrTb.Text       = PageFun.AddSpace(WriteTagDataFormat.tables["USER"].startStr);
                    stepTb.Text           = WriteTagDataFormat.tables["USER"].step.ToString();
                    startAddSampleTb.Text = PageFun.AddSpace(string.Format("{0}", sample.ToString("D" + WriteTagDataFormat.tables["USER"].len * 4)));
                    areaSampleL.Text      = "";
                }
                else
                {
                    areaSampleL.Text = NoArea;
                }
                break;

            default:
                break;
            }
        }
Beispiel #4
0
        private void StepToolToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ImportForm importForm = new ImportForm(rm, number);

            if (importForm.ShowDialog() == DialogResult.OK)
            {
                number = importForm.Number;
                InportDataSource(PageFun.GetTables(WriteTagDataFormat.tables, number), this.dataGridView1, WriteTagDataFormat.tables);
                Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                cfa.AppSettings.Settings["Number"].Value = number.ToString();
                cfa.AppSettings.Settings["Mode"].Value   = "1";
                cfa.Save();
            }
        }
Beispiel #5
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (mode == 0)                  //导入原始数据
     {
         InportDataSource(PageFun.GetTables(), this.dataGridView1, WriteTagDataFormat.tables);
     }
     else if (mode == 1)                //自动跳步方式
     {
         InportDataSource(PageFun.GetTables(WriteTagDataFormat.tables, number), this.dataGridView1, WriteTagDataFormat.tables);
     }
     else if (mode == 2)           //导入完整数据
     {
         InportDataSource(PageFun.GetTables(), this.dataGridView1);
     }
 }
Beispiel #6
0
        private void SaveData(DataTable source, string path, byte Mode)
        {
            string fileName     = "";
            string saveFileName = "";

            if (path == "")
            {
                SaveFileDialog saveDialog = new SaveFileDialog();
                saveDialog.DefaultExt = "xls";
                saveDialog.Filter     = "Excel2007|*.xlsx";
                saveDialog.FileName   = fileName;
                saveDialog.ShowDialog();
                saveFileName = saveDialog.FileName;
                if (saveFileName.IndexOf(":") < 0)
                {
                    return;                                //被点了取消
                }
                Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                cfa.AppSettings.Settings["FilePath"].Value = historyPath = saveDialog.FileName.Substring(0, saveDialog.FileName.LastIndexOf("\\"));
                cfa.Save();
            }
            else
            {
                saveFileName = path + "\\" + DateTime.Now.ToFileTime().ToString() + ".xlsx";
            }
            Microsoft.Office.Interop.Excel.Application xlApp =
                new Microsoft.Office.Interop.Excel.Application();
            if (xlApp == null)
            {
                MessageBox.Show(excelCreatErrorStr);
                return;
            }
            Microsoft.Office.Interop.Excel.Workbooks workbooks = xlApp.Workbooks;
            Microsoft.Office.Interop.Excel.Workbook  workbook  =
                workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
            Microsoft.Office.Interop.Excel.Worksheet worksheet =
                (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[1];        //取得sheet1
            //写入标题
            for (int i = 0; i < dataGridView1.ColumnCount; i++)
            {
                worksheet.Cells[1, i + 1] = dataGridView1.Columns[i].HeaderText;
            }
            //写入数值
            for (int r = 0; r < source.Rows.Count; r++)
            {
                for (int i = 0; i < dataGridView1.ColumnCount; i++)
                {
                    if (Mode == 0)
                    {
                        worksheet.Cells[r + 2, i + 1] = "'" + source.Rows[r][i];
                    }
                    else if (Mode == 1)
                    {
                        if (source.Rows[r][i].ToString() != null && source.Rows[r][i].ToString() != "")
                        {
                            worksheet.Cells[r + 2, i + 1] = PageFun.weigandStrTostr1(source.Rows[r][i].ToString());
                        }
                        else
                        {
                            worksheet.Cells[r + 2, i + 1] = null;
                        }
                    }
                    else if (Mode == 2)
                    {
                        if (source.Rows[r][i].ToString() != null && source.Rows[r][i].ToString() != "")
                        {
                            worksheet.Cells[r + 2, i + 1] = PageFun.weigandStrTostr2(source.Rows[r][i].ToString());
                        }
                        else
                        {
                            worksheet.Cells[r + 2, i + 1] = null;
                        }
                    }
                }
                System.Windows.Forms.Application.DoEvents();
            }
            worksheet.Columns.EntireColumn.AutoFit();//列宽自适应
            MessageBox.Show(fileName + excelSaveSuccessStr, tipStr, MessageBoxButtons.OK);
            // MessageBoxEx((IntPtr)0, excelSaveSuccessStr, tipStr, 0, 0);
            if (saveFileName != "")
            {
                try
                {
                    workbook.Saved = true;
                    workbook.SaveCopyAs(saveFileName);  //fileSaved = true;
                }
                catch (Exception ex)
                {//fileSaved = false;
                    MessageBox.Show(excelPathErrorStr);
                }
            }
            xlApp.Quit();
            GC.Collect();//强行销毁
        }