Esempio n. 1
0
        /// <summary>
        /// 导入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnImport_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbFileSavePath.Text))
            {
                MessageBox.Show("请选择保存文件的路径");
                return;
            }

            if (gvData.Rows.Count == 0)
            {
                MessageBox.Show("请先选择数据源文件");
            }
            else
            {
                toolStripProgressBar1.ProgressBar.Visible = true;
                toolStripProgressBar1.ProgressBar.Minimum = 0;
                toolStripProgressBar1.ProgressBar.Maximum = gvData.Rows.Count;
                int i        = 0;
                int okCount  = 0;
                int errCount = 0;
                foreach (DataGridViewRow dr in gvData.Rows)
                {
                    ImportDataInfo dInfo = DataRowToDataInfo(dr);
                    if (dInfo != null)
                    {
                        try
                        {
                            ImportXlsData import = new ImportXlsData(dInfo);
                            import.dataRowImportOk += new DataRowImportComplete(import_dataRowImportOk);
                            import.CurrentRow       = dr;
                            import.SavePath         = tbFileSavePath.Text + "\\";
                            import.Import();
                            okCount++;
                        }
                        catch (Exception ex)
                        {
                            errCount++;
                        }
                        toolStripStatusLabel1.Text = string.Format("成功导入{0}个,失败{1}个", okCount, errCount);
                    }
                    i++;
                    toolStripProgressBar1.ProgressBar.Value = i;
                }
                toolStripProgressBar1.ProgressBar.Visible = false;
                toolStripStatusLabel1.Text = toolStripStatusLabel1.Text.Insert(0, "完成导入,");
                btnImport.Enabled          = false;
            }
        }
Esempio n. 2
0
        private ImportDataInfo DataRowToDataInfo(DataGridViewRow dr)
        {
            ImportDataInfo info;

            try
            {
                info = new ImportDataInfo();
                if (dr.Cells[1] != null)
                {
                    info.Title = dr.Cells[1].Value as string;
                }
                if (dr.Cells[2] != null)
                {
                    info.FilePath = dr.Cells[2].Value as string;
                }
                if (dr.Cells[3] != null)
                {
                    info.Description = dr.Cells[3].Value as string;
                }
                if (dr.Cells[4] != null)
                {
                    info.Tags = dr.Cells[4].Value as string;
                }
                if (dr.Cells["Price"] != null)
                {
                    decimal r = 0;
                    decimal.TryParse(dr.Cells["Price"].FormattedValue as string, out r);
                    info.Price = r;
                }

                if (dr.Cells["CateId"] != null)
                {
                    int r = 0;
                    int.TryParse(dr.Cells["CateId"].FormattedValue as string, out r);
                    info.ClassId = r;
                }
            }
            catch (Exception ex)
            {
                info = null;
                dr.Cells["colStatus"].Value = "数据源转换错误";
            }
            return(info);
        }
Esempio n. 3
0
        private ImportDataInfo DataRowToDataInfo(DataGridViewRow dr)
        {
            ImportDataInfo info;
            try
            {
                info = new ImportDataInfo();
                if (dr.Cells[1] != null)
                {
                    info.Title = dr.Cells[1].Value as string;
                }
                if (dr.Cells[2] != null)
                {
                    info.FilePath = dr.Cells[2].Value as string;
                }
                if (dr.Cells[3] != null)
                {
                    info.Description = dr.Cells[3].Value as string;
                }
                if (dr.Cells[4] != null)
                {
                    info.Tags = dr.Cells[4].Value as string;
                }
                if (dr.Cells["Price"] != null)
                {
                    decimal r = 0;
                    decimal.TryParse(dr.Cells["Price"].FormattedValue as string, out r);
                    info.Price = r;
                }

                if (dr.Cells["CateId"] != null)
                {
                    int r = 0;
                    int.TryParse(dr.Cells["CateId"].FormattedValue as string, out r);
                    info.ClassId = r;
                }

            }
            catch(Exception ex)
            {
                info = null;
                dr.Cells["colStatus"].Value = "数据源转换错误";
            }
            return info;
        }
Esempio n. 4
0
 public ImportXlsData(ImportDataInfo doc)
 {
     this.docInfo = doc;
 }
Esempio n. 5
0
 public ImportXlsData(ImportDataInfo doc)
 {
     this.docInfo = doc;
 }