/// <summary> /// 修改 /// </summary> /// <param name="user"></param> public void UpdataVoucherFile(BloodUser user, string field) { StringBuilder sb = new StringBuilder("update voucherFile set "); sb.Append(field + "=@field ,"); sb.Append("done_settlement=@done_settlement "); sb.Append(" where HisID=@hisID"); cmd.CommandText = sb.ToString(); cmd.Parameters.Clear(); Type t = user.GetType(); PropertyInfo piName = t.GetProperty(field); //给Name属性赋值 string text = piName.GetValue(user).ToString(); cmd.Parameters.AddWithValue("@field", text); cmd.Parameters.AddWithValue("@done_settlement", user.done_settlement); cmd.Parameters.AddWithValue("@hisID", user.HisID); conn.Open(); cmd.ExecuteNonQuery();//执行SQL语句,并返回受影响的行 cmd.Dispose(); conn.Close(); }
private void GetFiles() { try { string baseDirectory = this.textBox1.Text; if (!string.IsNullOrEmpty(baseDirectory)) { var directory = Directory.GetDirectories(baseDirectory); foreach (var dir in directory) { string entrant = dir.Substring(dir.LastIndexOf('\\') + 1);//录入人 this.textBox3.Text = entrant; var files = Directory.GetFiles(dir); this.entrantCount.Text = files.Length.ToString(); int processedCount = 0; this.ProcessedCount.Text = processedCount.ToString(); foreach (var file in files) { FileInfo fileInfo = new FileInfo(file); string filename = fileInfo.Name; string fileNameNoSuffix = filename.Remove(filename.IndexOf('.')); var arrayofname = fileNameNoSuffix.Split('_'); var bmp = ReadImageFile(fileInfo.FullName); if (bmp != null) { List <BloodUser> list = dbf.SelectUserByName(arrayofname[0]); if (list != null) { BloodUser user = null; //判断图片的报销日期 if (!string.IsNullOrWhiteSpace(arrayofname[2])) { DateTime refund_date = StringToDate(arrayofname[2]); user = list.FirstOrDefault(x => x.Refund_date == refund_date); if (user == null) { user = list.FirstOrDefault(); } } else { user = list[0]; } if (user != null) { string his_ID = user.HisID; string oldName = filename; string prefix = NameConvert(arrayofname[1]); string newName = prefix + oldName; #region 保存文件 SavePic(bmp, prefix + oldName, his_ID, entrant); #endregion #region 保存数据库 Type t = user.GetType(); PropertyInfo piName = t.GetProperty(prefix); //给对应字段设置图片地址 piName.SetValue(user, "\\" + prefix + oldName, null); user.done_settlement = entrant; //判断voucherFile是否存在记录 if (dbf.ExistVoucherFile(user.HisID)) { dbf.UpdataVoucherFile(user, prefix); } else { dbf.InsertVoucherFile(user); } #endregion //删除原文件 fileInfo.Delete(); } } else { MessageBox.Show("未查询到图片姓名:" + arrayofname[0]); } } else { MessageBox.Show("图片读取失败,请检查路径"); } #region 更新已完成数量 processedCount++; this.ProcessedCount.Text = processedCount.ToString(); #endregion } } } MessageBox.Show("保存完成"); } catch (Exception e) { } }