Exemple #1
0
        private void openExcel_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter          = "Excel文件(*.xls;*.xlsx)|*.xls;*.xlsx|所有文件|*.*";
            ofd.ValidateNames   = true;
            ofd.CheckPathExists = true;
            ofd.CheckFileExists = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string strFileName = ofd.FileName;
                try
                {
                    excelDt = NPOIExcel.readExcel(strFileName, true);
                    if (excelDt != null && excelDt.Rows.Count > 0)
                    {
                        LogRichTextBox.logMesg("文件『" + strFileName + "』读取成功!共读取【" + excelDt.Rows.Count.ToString() + "】条记录。");
                    }
                    else
                    {
                        LogRichTextBox.logMesg("文件『" + strFileName + "』读取失败!请检查EXCEL文件是否有数据。", 2);
                    }
                }
                catch (Exception ex)
                {
                    LogRichTextBox.logMesg("文件『" + strFileName + "』读取失败!失败原因为:" + ex.ToString(), 2);
                    return;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// 检查数据
        /// </summary>
        private bool checkExcelData()
        {
            try
            {
                LogRichTextBox.logMesg("正在检查导入数据的格式。。。");

                if (!excelDt.Columns.Contains("存货分类编码") || !excelDt.Columns.Contains("商品代码") || !excelDt.Columns.Contains("表面色") || !excelDt.Columns.Contains("金额"))
                {
                    LogRichTextBox.logMesg("EXCEL文件中缺少存货分类编码、商品代码、表面色和金额等关键列!数据完整性检查失败!请核对要导入的EXCEL文件。", 1);
                    return(false);
                }

                LogRichTextBox.logMesg("数据完整,可以导入。");
            }
            catch (Exception e)
            {
                LogRichTextBox.logMesg("数据完整性检查程序出错!错误原因:" + e.ToString(), 2);
                return(false);
            }
            return(true);
        }
Exemple #3
0
 private void impU8_Click(object sender, EventArgs e)
 {
     if (!checkBox1.Checked)
     {
         LogRichTextBox.logMesg("请确认产成品成本分配的会计期间后,再导入!", 1);
         return;
     }
     if (excelDt == null || excelDt.Rows.Count <= 0)
     {
         LogRichTextBox.logMesg("请确认已打开EXCEL文件且EXCEL文件中有数据后,再导入!", 1);
         return;
     }
     if (!checkExcelData())
     {
         return;
     }
     try
     {
         LogRichTextBox.logMesg("请等候,开始导入U8系统。。。");
         impU8.Enabled = false;
         if (initDatabase())
         {
             commitDatabase();
         }
         else
         {
             LogRichTextBox.logMesg("初始化导入环境出错,请联系系统管理员!", 2);
         }
         LogRichTextBox.logMesg("数据导入成功!共导入【" + count.ToString() + "】条记录!");
         excelDt.Rows.Clear();//导入成功,清空数据
     }
     catch (Exception ex)
     {
         LogRichTextBox.logMesg("程序出错!错误原因为:" + ex.ToString(), 2);
     }
     finally
     {
         impU8.Enabled = true;
     }
 }
Exemple #4
0
 private void 清除日志ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     LogRichTextBox.LogClear();
 }