C#导入数据使用Task异步处理耗时任务

news2024/10/5 14:23:34

C#多线程中,我们可以使用async和await来异步处理耗时任务。

现在我们打开一个Excel表格,将Excel表格的每一行数据进行处理,并存储到数据库中

新建Windows应用程序DataImportDemo,.net framework 4.6.1

将默认的Form1重命名为FormDataImport,

窗体FormDataImport设计如图:

窗体FormDataImport设计器代码如下:

FormDataImport.Designer.cs文件


namespace DataImportDemo
{
    partial class FormDataImport
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要修改
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.dgvData = new System.Windows.Forms.DataGridView();
            this.btnSave = new System.Windows.Forms.Button();
            this.rtxtMessage = new System.Windows.Forms.RichTextBox();
            this.btnExport = new System.Windows.Forms.Button();
            this.dgvcCoreID = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.dgvcModuleBarcode = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.dgvcPoleCode = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.dgvcModuleCategory = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.progressBarImport = new System.Windows.Forms.ProgressBar();
            ((System.ComponentModel.ISupportInitialize)(this.dgvData)).BeginInit();
            this.SuspendLayout();
            // 
            // dgvData
            // 
            this.dgvData.AllowUserToAddRows = false;
            this.dgvData.AllowUserToDeleteRows = false;
            this.dgvData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dgvData.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.dgvcCoreID,
            this.dgvcModuleBarcode,
            this.dgvcPoleCode,
            this.dgvcModuleCategory});
            this.dgvData.Location = new System.Drawing.Point(12, 61);
            this.dgvData.Name = "dgvData";
            this.dgvData.ReadOnly = true;
            this.dgvData.RowTemplate.Height = 23;
            this.dgvData.Size = new System.Drawing.Size(627, 628);
            this.dgvData.TabIndex = 0;
            // 
            // btnSave
            // 
            this.btnSave.Font = new System.Drawing.Font("宋体", 16F);
            this.btnSave.Location = new System.Drawing.Point(67, 9);
            this.btnSave.Name = "btnSave";
            this.btnSave.Size = new System.Drawing.Size(233, 43);
            this.btnSave.TabIndex = 1;
            this.btnSave.Text = "打开Excel并导入数据";
            this.btnSave.UseVisualStyleBackColor = true;
            this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
            // 
            // rtxtMessage
            // 
            this.rtxtMessage.Location = new System.Drawing.Point(645, 61);
            this.rtxtMessage.Name = "rtxtMessage";
            this.rtxtMessage.Size = new System.Drawing.Size(621, 628);
            this.rtxtMessage.TabIndex = 2;
            this.rtxtMessage.Text = "";
            // 
            // btnExport
            // 
            this.btnExport.Font = new System.Drawing.Font("宋体", 16F);
            this.btnExport.Location = new System.Drawing.Point(336, 9);
            this.btnExport.Name = "btnExport";
            this.btnExport.Size = new System.Drawing.Size(122, 43);
            this.btnExport.TabIndex = 3;
            this.btnExport.Text = "导出模板";
            this.btnExport.UseVisualStyleBackColor = true;
            this.btnExport.Click += new System.EventHandler(this.btnExport_Click);
            // 
            // dgvcCoreID
            // 
            this.dgvcCoreID.HeaderText = "序号";
            this.dgvcCoreID.Name = "dgvcCoreID";
            this.dgvcCoreID.ReadOnly = true;
            // 
            // dgvcModuleBarcode
            // 
            this.dgvcModuleBarcode.HeaderText = "模组条码";
            this.dgvcModuleBarcode.Name = "dgvcModuleBarcode";
            this.dgvcModuleBarcode.ReadOnly = true;
            this.dgvcModuleBarcode.Width = 180;
            // 
            // dgvcPoleCode
            // 
            this.dgvcPoleCode.HeaderText = "极性编码";
            this.dgvcPoleCode.Name = "dgvcPoleCode";
            this.dgvcPoleCode.ReadOnly = true;
            // 
            // dgvcModuleCategory
            // 
            this.dgvcModuleCategory.HeaderText = "模组类型";
            this.dgvcModuleCategory.Name = "dgvcModuleCategory";
            this.dgvcModuleCategory.ReadOnly = true;
            this.dgvcModuleCategory.Width = 140;
            // 
            // progressBarImport
            // 
            this.progressBarImport.Location = new System.Drawing.Point(529, 15);
            this.progressBarImport.Name = "progressBarImport";
            this.progressBarImport.Size = new System.Drawing.Size(737, 23);
            this.progressBarImport.TabIndex = 4;
            // 
            // FormDataImport
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(1305, 710);
            this.Controls.Add(this.progressBarImport);
            this.Controls.Add(this.btnExport);
            this.Controls.Add(this.rtxtMessage);
            this.Controls.Add(this.btnSave);
            this.Controls.Add(this.dgvData);
            this.Name = "FormDataImport";
            this.Text = "数据导入使用async,await异步处理耗时任务";
            ((System.ComponentModel.ISupportInitialize)(this.dgvData)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.DataGridView dgvData;
        private System.Windows.Forms.Button btnSave;
        private System.Windows.Forms.RichTextBox rtxtMessage;
        private System.Windows.Forms.Button btnExport;
        private System.Windows.Forms.DataGridViewTextBoxColumn dgvcCoreID;
        private System.Windows.Forms.DataGridViewTextBoxColumn dgvcModuleBarcode;
        private System.Windows.Forms.DataGridViewTextBoxColumn dgvcPoleCode;
        private System.Windows.Forms.DataGridViewTextBoxColumn dgvcModuleCategory;
        private System.Windows.Forms.ProgressBar progressBarImport;
    }
}

添加对NPOI框架的引用

添加对【NPOI.dll、NPOI.OOXML.dll、NPOI.OpenXml4Net.dll、NPOI.OpenXmlFormats.dll】类库的引用.

新建类NpoiExcelOperateUtil,用于【Excel表格与DataTable内存数据表的相互转换操作】

NpoiExcelOperateUtil.cs源程序:

using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataImportDemo
{
    /// <summary>
    /// Excel表格与DataTable内存数据表的相互转换操作类
    /// 斯内科 2023-08-08
    /// </summary>
    public static class NpoiExcelOperateUtil
    {
        /// <summary>
        /// Excel的第一个工作簿(Sheet)转化成DataTable
        /// 使用EXCEL的第一个工作簿,默认为Sheet1
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public static DataTable ExcelToTable(string file)
        {
            DataTable dt = new DataTable();
            IWorkbook workbook;
            string fileExt = Path.GetExtension(file).ToLower();
            using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
            {
                //XSSFWorkbook 适用XLSX格式,HSSFWorkbook 适用XLS格式
                if (fileExt == ".xlsx")
                {
                    workbook = new XSSFWorkbook(fs);
                }
                else if (fileExt == ".xls")
                {
                    workbook = new HSSFWorkbook(fs);
                }
                else
                {
                    return null;
                }
                //第一个工作簿
                ISheet sheet = workbook.GetSheetAt(0);
                if (sheet == null)
                {
                    return null;
                }
                return ExcelToTable(file, sheet.SheetName);
            }
        }
        /// <summary>
        /// Excel的指定Sheet转化成内存表
        /// </summary>
        /// <param name="file">路径</param>
        /// <param name="sheetName">sheet名称</param>
        /// <returns></returns>
        public static DataTable ExcelToTable(string file, string sheetName)
        {
            DataTable[] dataTables = ExcelToTable(file, new List<string>() { sheetName });
            if (dataTables != null && dataTables.Length > 0)
            {
                return dataTables[0];
            }
            return null;
        }

        /// <summary>
        /// 一个excel文件的多个Sheet转化成内存表数组,
        /// 每个Sheet都对应一个数据表
        /// </summary>
        /// <param name="file">路径</param>
        /// <param name="list_SheetName">sheet名称集合</param>
        /// <returns></returns>
        public static DataTable[] ExcelToTable(string file, List<string> list_SheetName)
        {
            int count = list_SheetName.Count;
            DataTable[] dtS = new DataTable[count];
            //===============================//
            IWorkbook workbook;
            string fileExt = Path.GetExtension(file).ToLower();
            using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
            {
                //XSSFWorkbook 适用XLSX格式,HSSFWorkbook 适用XLS格式
                if (fileExt == ".xlsx")
                {
                    workbook = new XSSFWorkbook(fs);
                }
                else if (fileExt == ".xls")
                {
                    workbook = new HSSFWorkbook(fs);
                }
                else
                {
                    return null;
                }
                ISheet[] sheetS = new ISheet[count];
                for (int k = 0; k < count; k++)
                {
                    dtS[k] = new DataTable(list_SheetName[k]);
                    sheetS[k] = workbook.GetSheet(list_SheetName[k]);
                    ISheet sheet = sheetS[k];
                    if (sheet == null)
                    {
                        continue;
                    }
                    DataTable dt = new DataTable(list_SheetName[k]);
                    //表头  
                    IRow header = sheet.GetRow(sheet.FirstRowNum);
                    List<int> columns = new List<int>();
                    for (int i = 0; i < header.LastCellNum; i++)
                    {
                        object obj = GetValueType(header.GetCell(i));
                        if (obj == null || obj.ToString() == string.Empty)
                        {
                            dt.Columns.Add(new DataColumn("Columns" + i.ToString()));
                        }
                        else
                            dt.Columns.Add(new DataColumn(obj.ToString()));
                        columns.Add(i);
                    }
                    //数据  
                    for (int i = sheet.FirstRowNum + 1; i <= sheet.LastRowNum; i++)
                    {
                        DataRow dr = dt.NewRow();
                        bool hasValue = false;
                        foreach (int j in columns)
                        {
                            dr[j] = GetValueType(sheet.GetRow(i).GetCell(j));
                            if (dr[j] != null && dr[j].ToString() != string.Empty)
                            {
                                hasValue = true;
                            }
                        }
                        if (hasValue)
                        {
                            dt.Rows.Add(dr);
                        }
                    }
                    dtS[k] = dt;
                }
            }
            return dtS;
        }

        /// <summary>
        /// Datable导出成Excel
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="file"></param>
        public static void TableToExcel(DataTable dt, string file)
        {
            IWorkbook workbook;
            string fileExt = Path.GetExtension(file).ToLower();
            if (fileExt == ".xlsx")
            {
                //workbook = new XSSFWorkbook();
                workbook = new HSSFWorkbook();
            }
            else if (fileExt == ".xls")
            {
                workbook = new HSSFWorkbook();
            }
            else
            {
                workbook = null;
            }
            if (workbook == null)
            {
                return;
            }
            ISheet sheet = string.IsNullOrEmpty(dt.TableName) ? workbook.CreateSheet("Sheet1") : workbook.CreateSheet(dt.TableName);
            //表头  
            IRow row = sheet.CreateRow(0);
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                ICell cell = row.CreateCell(i);
                cell.SetCellValue(dt.Columns[i].ColumnName);
            }

            //数据  
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                IRow row1 = sheet.CreateRow(i + 1);
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    ICell cell = row1.CreateCell(j);
                    cell.SetCellValue(dt.Rows[i][j].ToString());
                }
            }

            //转为字节数组  
            MemoryStream stream = new MemoryStream();
            workbook.Write(stream);
            var buf = stream.ToArray();

            //保存为Excel文件  
            using (FileStream fs = new FileStream(file, FileMode.Create, FileAccess.Write))
            {
                fs.Write(buf, 0, buf.Length);
                fs.Flush();
            }
        }

        /// <summary>
        /// 获取单元格类型
        /// </summary>
        /// <param name="cell"></param>
        /// <returns></returns>
        private static object GetValueType(ICell cell)
        {
            if (cell == null)
                return null;
            switch (cell.CellType)
            {
                case CellType.Blank: //BLANK:  
                    return null;
                case CellType.Boolean: //BOOLEAN:  
                    return cell.BooleanCellValue;
                case CellType.Numeric: //NUMERIC:  
                    return cell.NumericCellValue;
                case CellType.String: //STRING:  
                    return cell.StringCellValue;
                case CellType.Error: //ERROR:  
                    return cell.ErrorCellValue;
                case CellType.Formula: //FORMULA:  
                default:
                    return "=" + cell.CellFormula;
            }
        }
    }
}

窗体FormDataImport的异步耗时任务代码如下:

FormDataImport.cs文件

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DataImportDemo
{
    public partial class FormDataImport : Form
    {
        public FormDataImport()
        {
            InitializeComponent();
            rtxtMessage.ReadOnly = true;

            progressBarImport.Value = 0;
            dgvData.AutoGenerateColumns = false;
            dgvcCoreID.DataPropertyName = "序号";
            dgvcModuleBarcode.DataPropertyName = "模组条码";
            dgvcPoleCode.DataPropertyName = "极性编码";
            dgvcModuleCategory.DataPropertyName = "模组类型";
        }

        /// <summary>
        /// 显示推送消息
        /// </summary>
        /// <param name="msg"></param>
        private void DisplayMessage(string msg)
        {
            this.BeginInvoke(new Action(() =>
            {
                if (rtxtMessage.TextLength > 20480)
                {
                    rtxtMessage.Clear();
                }
                rtxtMessage.AppendText($"{DateTime.Now.ToString("HH:mm:ss.fff")}->{msg}\n");
                rtxtMessage.ScrollToCaret();
            }));
        }

        /// <summary>
        /// 一行一行的更新数据库【耗时任务】
        /// </summary>
        /// <param name="dtImport"></param>
        private Task<int> UpdateDatabase(DataTable dtImport)
        {
            int rowCount = dtImport.Rows.Count;
            progressBarImport.Maximum = rowCount;
            progressBarImport.Value = 0;//进度条清零
            DisplayMessage($"开始导入模组极柱数据,准备导入数据条数【{rowCount}】......");
            Task<int> task = Task.Run<int>(() =>
            {
                int cnt = 0;
                for (int i = 0; i < rowCount; i++)
                {
                    //更新进度条
                    this.BeginInvoke(new Action(() =>
                    {
                        if (this.IsHandleCreated)
                        {
                            progressBarImport.Value++;
                        }
                    }));

                    string ModuleBarcode = Convert.ToString(dtImport.Rows[i]["模组条码"]);
                    string PoleCode = Convert.ToString(dtImport.Rows[i]["极性编码"]);
                    string ModuleCategory = Convert.ToString(dtImport.Rows[i]["模组类型"]);
                    if (string.IsNullOrWhiteSpace(ModuleBarcode))
                    {
                        continue;
                    }
                    try
                    {
                        List<string> sqlCollection = new List<string>();
                        List<Dictionary<string, object>> dictCollection = new List<Dictionary<string, object>>();
                        sqlCollection.Add("delete from module_pole where ModuleBarcode=@ModuleBarcode");
                        sqlCollection.Add("insert into module_pole (ModuleBarcode,ModuleCategory,PoleCode,ProcessEndTime) values (@ModuleBarcode,@ModuleCategory,@PoleCode,@ProcessEndTime)");
                        dictCollection.Add(new Dictionary<string, object>() { { "ModuleBarcode", ModuleBarcode } });
                        dictCollection.Add(new Dictionary<string, object>() { { "ModuleBarcode", ModuleBarcode },
                            { "ModuleCategory", ModuleCategory }, { "PoleCode", PoleCode }, { "ProcessEndTime", DateTime.Now } });
                        ExecuteTransaction(sqlCollection, dictCollection);
                        DisplayMessage($"导入模组极柱数据成功,模组条码【{ModuleBarcode}】");
                        cnt++;
                    }
                    catch (Exception ex)
                    {
                        DisplayMessage($"导入模组极柱数据出错【{ex.Message}】,模组条码【{ModuleBarcode}】");
                    }
                }
                return cnt;
            });
            return task;
        }

        /// <summary>
        /// 这里执行事务
        /// </summary>
        /// <param name="sqlCollection"></param>
        /// <param name="dictCollection"></param>
        private void ExecuteTransaction(List<string> sqlCollection, List<Dictionary<string, object>> dictCollection) 
        {
            Random random = new Random((int)DateTime.Now.Ticks);
            int millisecondsTimeout = random.Next(100, 300);
            System.Threading.Thread.Sleep(millisecondsTimeout);
            DisplayMessage($"执行数据库事务,耗时【{millisecondsTimeout}】ms");
        }

        private async void btnSave_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "Excel文件|*.xls;*.xlsx";
            DialogResult dialog = openFileDialog.ShowDialog();
            if (dialog != DialogResult.OK)
            {
                return;
            }
            string fileName = openFileDialog.FileName;
            try
            {
                DataTable dtImport = NpoiExcelOperateUtil.ExcelToTable(fileName);
                if (!dtImport.Columns.Contains("序号"))
                {
                    MessageBox.Show($"必须包含列【序号】,请检查excel格式.路径\n【{fileName}】", "提示");
                    return;
                }
                if (!dtImport.Columns.Contains("模组条码"))
                {
                    MessageBox.Show($"必须包含列【模组条码】,请检查excel格式.路径\n【{fileName}】", "提示");
                    return;
                }
                if (!dtImport.Columns.Contains("极性编码"))
                {
                    MessageBox.Show($"必须包含列【极性编码】,请检查excel格式.路径\n【{fileName}】", "提示");
                    return;
                }
                if (!dtImport.Columns.Contains("模组类型"))
                {
                    MessageBox.Show($"必须包含列【模组类型】,请检查excel格式.路径\n【{fileName}】", "提示");
                    return;
                }

                //绑定网格数据
                dgvData.DataSource = dtImport;
                int rowCount = dtImport.Rows.Count;
                if (rowCount < 1)
                {
                    MessageBox.Show($"Excel不存在有效的上传数据配置行.路径\n【{fileName}】", "提示");
                    return;
                }
                Task<int> task = UpdateDatabase(dtImport);
                await task;
                DisplayMessage($"导入模组极柱数据成功,实际导入数据条数【{task.Result}】......");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"读取excel出现异常,请检查是否是标准的Excel文件.【{ex.Message}】路径\n【{fileName}】", "出错");
                return;
            }
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.FileName = DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".xls";
            saveFileDialog.Filter = "Excel文件|*.xls;*.xlsx";
            DialogResult dialog = saveFileDialog.ShowDialog();
            if (dialog != DialogResult.OK)
            {
                return;
            }
            string fileName = saveFileDialog.FileName;
            DataTable dt = new DataTable("TableToExcel");
            dt.Columns.Add("序号", typeof(int));
            dt.Columns.Add("模组条码", typeof(string));
            dt.Columns.Add("极性编码", typeof(string));
            dt.Columns.Add("模组类型", typeof(string));
            //最多保留3行
            for (int i = 0; i < Math.Min(dgvData.Rows.Count, 3); i++)
            {
                dt.Rows.Add(dgvData[0, i].Value, dgvData[1, i].Value, dgvData[2, i].Value, dgvData[3, i].Value);
            }
            try
            {
                NpoiExcelOperateUtil.TableToExcel(dt, fileName);
                MessageBox.Show($"保存示例模板成功,保存数据条数【{dt.Rows.Count}】.\n路径【{fileName}】", "提示");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"保存示例模板出现异常,请检查是否是标准的Excel文件.【{ex.Message}】路径\n【{fileName}】", "出错");
                return;
            }
        }
    }
}

程序运行如图:

 

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/860277.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

js防止F12扒数据

添加 js 代码防止F12扒数据 ((function() {var callbacks [],timeLimit 50,open false;setInterval(loop, 1);return {addListener: function(fn) {callbacks.push(fn);},cancleListenr: function(fn) {callbacks callbacks.filter(function(v) {return v ! fn;});}}funct…

面试八股文Mysql:(1)事务实现的原理

1. 什么是事务 事务就是一组数据库操作&#xff0c;这些操作是一个atomic&#xff08;原子性的操作&#xff09; &#xff0c;不可分割&#xff0c;要么都执行&#xff0c;要么回滚&#xff08;rollback&#xff09;都不执行。这样就避免了某个操作成功某个操作失败&#xff0…

藏语翻译器:藏语翻译小助手

这是一款翻译功能齐全的翻译软件&#xff0c;主打藏语翻译功能&#xff0c;同时具备文字翻译、图片翻译、音频翻译、视频翻译、文档翻译等热门功能&#xff0c;支持将翻译结果导出为可编辑的文本文档&#xff0c;方便后续编辑整理。支持朗读原文和译文&#xff0c;帮助我们学习…

LeetCode209. 长度最小的子数组

题目&#xff1a;LeetCode209. 长度最小的子数组 描述&#xff1a; 给定一个含有 n 个正整数的数组和一个正整数 target 。 找出该数组中满足其和 ≥ target 的长度最小的 连续子数组 [numsl, numsl1, …, numsr-1, numsr] &#xff0c;并返回其长度。如果不存在符合条件的子…

Grafana Prometheus 通过JMX监控kafka

第三方kafka exporter方案 目前网上关于使用Prometheus 监控kafka的大部分资料都是使用一个第三方的 kafka exporter&#xff0c;他的原理大概就是启动一个kafka客户端&#xff0c;获取kafka服务器的信息&#xff0c;然后提供一些metric接口供Prometheus使用&#xff0c;随意它…

【React学习】—函数式组件(四)

【React学习】—函数式组件&#xff08;四&#xff09; <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8" /><meta name"viewport" content"widthdevice-width, initial-scale1.0" /><ti…

17.电话号码的字母组合(回溯)

目录 一、题目 二、代码 一、题目 17. 电话号码的字母组合 - 力扣&#xff08;LeetCode&#xff09; 二、代码 class Solution {const char*data[10]{"","","abc","def","ghi","jkl","mno","pq…

解决nvm安装后,node生效但npm无效

问题描述 nvm安装后&#xff0c;node生效但npm无效 清除缓存 C:\Users\cc\AppData\Roaming cc是我的用户名改成你自己的就行删除 npm和npm-cache

pdf怎么删除不要的页面?这几种删除方法了解一下

pdf怎么删除不要的页面&#xff1f;在处理pdf文档时&#xff0c;我们经常会遇到需要删除某些页面的情况。一些多余或无关的页面可能会对文档的整体结构造成混乱&#xff0c;甚至会影响文档的可读性。此外&#xff0c;删除多余页面还可以减小文件大小&#xff0c;方便存储和传输…

B2B2C多用户商城系统--多店铺商城系统源码搭建

要搭建一个B2B2C多用户商城系统&#xff0c;需要以下几个步骤&#xff0c;包括系统设计、数据库设计、前端设计和后端设计。 1. 系统设计 在系统设计阶段&#xff0c;需要确定系统的基本架构和功能模块。以下是系统设计的一些要点&#xff1a; 采用敏捷开发流程&#xff0c;…

微服务03-RabbitMQ

1、简介 MQ,中文是消息中间件(队列)(MessageQueue),字面来看就是存放消息的队列。也就是事件驱动架构中的Broker。 简单来说,消息中间件就是指保存数据的一个容器(服务器),可以用于两个系统之间的数据传递。 几种常见MQ的对比: RabbitMQActiveMQRocketMQKafka公司…

1. CUDA编程手册中文版---CUDA简介

1.CUDA简介 1.1 我们为什么要使用GPU 更多精彩内容&#xff0c;请扫描下方二维码或者访问https://developer.nvidia.com/zh-cn/developer-program 来加入NVIDIA开发者计划 GPU&#xff08;Graphics Processing Unit&#xff09;在相同的价格和功率范围内&#xff0c;比CPU提供…

XShell7连接CentOS7并利用lrzsz上传文件

xshell连接centos7 第一步&#xff1a;开放Linux防火墙的22号端口号 firewall-cmd --zonepublic --add-port22/tcp --permanentfirewall-cmd --reload 通过&#xff1a;firewall-cmd --zonepublic --list-ports 验证22端口是否开放 第二步&#xff1a;查看Linux主机端口号 命…

Java高级应用

一、异常处理 异常处理就是针对程序可能出现的错误情况&#xff0c;进行抛出异常。要么终止程序&#xff0c;要么进行避免错误情况。就需要用到的语法是try&#xff08;避免&#xff09;。throws&#xff08;对可能出现的情况进行抛出&#xff09;。 在实际开发中&#xff0c…

Spring自动装配原理

如上图&#xff0c;Spring的自动装配&#xff0c;要从AutoConfigurationImportSelector类说起&#xff0c;一直在此类selectImports方法的内部底层&#xff0c;有一个loadSpringFactories()方法&#xff0c;此方法会查找MET-INF目录下的spring.factories文件。先将此文件中的值…

C++核心编程——函数高级、类和对象

3 函数提高 3.1 函数默认参数 在C中&#xff0c;函数的形参列表中的形参是可以有默认值的。 语法&#xff1a;返回值类型 函数名 &#xff08;参数默认值&#xff09;{} 注意事项&#xff1a; 1、如果函数的参数列表中某个参数已经有了默认参数&#xff0c;那么从这个参…

mysql索引的数据结构(Innodb)

首选要注意,这里的数据结构是存储在硬盘上的数据结构,不是内存中的数据结构,要重点考虑io次数. 一.不适合的数据结构: 1.Hash:不适合进行范围查询和模糊匹配查询.(有些数据库索引会使用Hash,但是只能精准匹配) 2.红黑树:可以范围查询和模糊匹配,但是和硬盘io次数比较多. 二…

QGIS开发五:使用UI文件

前面我们说了在创建项目时创建的是一个空项目&#xff0c;即不使用 Qt 提供的综合开发套件 Qt Creator&#xff0c;也不使用 Qt Visual Studio Tools 这类工具。 但是后面发现&#xff0c;如果我想要有更加满意的界面布局&#xff0c;还是要自己写一个UI文件&#xff0c;如果不…

大华智慧园区综合管理平台SQL注入漏洞复现(HW0day)

0x01 产品简介 “大华智慧园区综合管理平台”是一款综合管理平台&#xff0c;具备园区运营、资源调配和智能服务等功能。平台意在协助优化园区资源分配&#xff0c;满足多元化的管理需求&#xff0c;同时通过提供智能服务&#xff0c;增强使用体验。 0x02 漏洞概述 大华智慧园…