//主要方法 private void LogUploadMain() { //数据初始化 setRichtexBox("---------开始LOG日志上传----------"); ClearRichText(); //第一步 查看是否填写日志目录 Boolean tt_flag1 = false; string tt_frompath = ""; if (!this.textBox6.Text.Equals("")) { PutListViewData("第一步:已选择LOG存储目录,goon"); tt_flag1 = true; } else { PutListViewData("第一步:没有选择LOG存储目录,over"); } //第二步 查看是否存在bak目录,不存在就创建一个目录 Boolean tt_flag2 = false; string tt_bpath = this.textBox6.Text + @"\log"; if (tt_flag1) { if (!Directory.Exists(tt_bpath)) { Directory.CreateDirectory(tt_bpath); PutListViewData("第二步:没有log目录,新建一个目录"); } else { PutListViewData("第二步:已存在log目录"); } tt_flag2 = true; } //第三步获取带上传目录信息 Boolean tt_flag3 = false; if (tt_flag1 && tt_flag2) { string tt_filenumber = GetLogText(); tt_flag3 = true; PutListViewData("第三步:获取到上传文件数目:" + tt_filenumber); } //第四步获取上传目录 Boolean tt_flag4 = false; string tt_sevicepath = ""; string tt_taskscode = ""; if (tt_flag1 && tt_flag2 && tt_flag3) { //tt_sevicepath = GetUploadPath(); tt_sevicepath = GetUploadPath2(tt_pcname); tt_taskscode = this.textBox5.Text.Trim(); tt_flag4 = true; PutListViewData("第四步:获取到上传文件目录名:" + tt_sevicepath); PutListViewData("工单号:" + tt_taskscode); } //第五步在在目录中循环 Boolean tt_flag5 = false; string tt_task = this.textBox5.Text; int tt_loadsuccess = 0; int tt_logtosave = 0; //LOG数据保存的数据库成功数量 int tt_movefile = 0; if (tt_flag1 && tt_flag2 && tt_flag3 && tt_flag4) { PutListViewData("第五步:开始数据文件上传操作"); string tt_logpath; string tt_newname; string tt_file; string tt_path = this.textBox6.Text; int tt_textnumber = 0; DirectoryInfo folder = new DirectoryInfo(tt_path); foreach (FileInfo file in folder.GetFiles("*.csv")) { setRichtexBox("--- " + tt_textnumber.ToString() + " ----"); //第1步,获取文件名及路径 tt_logpath = file.FullName; tt_frompath = tt_logpath; PutListViewData("1、文件路径:" + tt_logpath); //第2步 获取老的文件名 tt_file = file.Name; PutListViewData("2、老文件名:" + tt_file); //第3步 获取新的文件名 tt_newname = GetNewName(tt_file); PutListViewData("3、新文件名:" + tt_newname); //第4步 上传数据 //------以下加这个数据读取------- tt_dt = Csv2DataSet(tt_logpath); Boolean tt_saveflag = Dataset1.saveDataset2Database2(tt_dt, tt_taskscode, tt_newname, tt_conn); if (tt_saveflag) { tt_logtosave++; PutListViewData("4、数据上传成功."); } else { PutListViewData("4、数据保存上传失败-----!!!!"); } //第5步 上传文件 Boolean tt_uploadflag = false; if (tt_saveorup == "数据日志上传" && tt_saveflag) { tt_uploadflag = AutoUploadFile(sip, tt_logpath, tt_sevicepath, tt_newname); if (tt_uploadflag) { PutListViewData("5、该文件上传成功."); tt_loadsuccess++; } else { PutListViewData("5、该文件上传失败-----!!!!"); } } else { PutListViewData("5、该文件设定不需要上传."); } //第6步 记录数据 if (tt_uploadflag) { string tt_sql = "insert odc_logupload (Ftaskcode,Flogname,Fnewname,Fpath,Fdate) " + "values( '" + tt_task + "','" + tt_file + "','" + tt_newname + "','" + tt_sevicepath + "',getdate() )"; int tt_dbrecord = Dataset1.ExecCommand(tt_sql, tt_conn); if (tt_dbrecord > 0) { PutListViewData("6、该记录到数据库成功"); } else { PutListViewData("6、该记录到数据库失败"); } } //第7步获取转移路径及文件名 string tt_movepath = tt_bpath + @"\" + tt_file; if (tt_uploadflag) { PutListViewData("7、转移的文件路径名:" + tt_movepath); } //第8步 将数据移到log目录中 if (tt_saveflag) { Boolean tt_moveflag = fileMove(tt_frompath, tt_movepath); if (tt_moveflag) { PutListViewData("8、文件转移成功:"); tt_movefile++; } else { PutListViewData("8、文件转移不成功:"); } } tt_textnumber++; } if (tt_textnumber == tt_loadsuccess || tt_textnumber == tt_logtosave) { tt_flag5 = true; PutListViewData("第五步、数据全部上传成功"); } else { PutListViewData("第五步、数据没有全部上传成功,请检查"); } } //最后总结 if (tt_flag1 && tt_flag2 && tt_flag3 && tt_flag4 && tt_flag5) { this.label15.Text = tt_loadsuccess.ToString(); this.label23.Text = tt_movefile.ToString(); this.label33.Text = tt_logtosave.ToString(); GetLogUploadFile(); this.listView1.BackColor = Color.Chartreuse; //this.richTextBox2.BackColor = Color.Chartreuse; } else { this.label15.Text = tt_loadsuccess.ToString(); this.label23.Text = tt_movefile.ToString(); this.label33.Text = tt_logtosave.ToString(); this.listView1.BackColor = Color.Red; //this.richTextBox2.BackColor = Color.Red; } }