Beispiel #1
0
 private void LoadList()
 {
     //禁用列表的自动生成
     dgvList.AutoGenerateColumns = false;
     //调用方法获取数据,绑定到列表的数据源上
     dgvList.DataSource = miBll.GetList();
 }
Beispiel #2
0
 private void LoadList()
 {
     txtId.Text = "添加时无编号";
     //禁用列表的自动生成
     dgvList.AutoGenerateColumns = false;
     //调用方法,获取数据,绑定到列表的数据源上
     dgvList.DataSource = miBll.GetList();
 }
Beispiel #3
0
        //显示数据
        private void LoadList()
        {
            ManagerInfoBll bll = new ManagerInfoBll();

            //禁用列的自动生成
            dgvList.AutoGenerateColumns = false;
            dgvList.DataSource          = bll.GetList();
        }
Beispiel #4
0
        private void btnExcelExport_Click(object sender, EventArgs e)
        {
            ManagerInfoBll miBll = new ManagerInfoBll();
            var            list  = miBll.GetList();

            dataGridView1.DataSource = list;
            //创建Excel工作薄
            XSSFWorkbook workbook = new XSSFWorkbook();
            //创建单元格样式
            ICellStyle cellTitleStyle = workbook.CreateCellStyle();

            //设置单元格居中显示
            cellTitleStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
            //创建字体
            IFont font = workbook.CreateFont();

            //设置字体加粗显示
            font.IsBold = true;
            cellTitleStyle.SetFont(font);
            //创建Excel工作表
            ISheet sheet = workbook.CreateSheet("管理员");
            //创建Excel行
            IRow row = sheet.CreateRow(0);

            //创建Excel单元格
            NPOI.SS.UserModel.ICell cell = row.CreateCell(0);
            //设置单元格值
            cell.SetCellValue("管理员管理");
            //设置单元格合并
            sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(0, 0, 0, 3));
            cell.CellStyle = cellTitleStyle;
            for (int i = 0; i < list.Count; i++)
            {
                IRow rowDate = sheet.CreateRow(i + 1);
                Type t       = list[i].GetType();
                int  count   = 0;
                foreach (PropertyInfo pi in t.GetProperties())
                {
                    object value = pi.GetValue(list[i]);
                    string name  = pi.Name;
                    NPOI.SS.UserModel.ICell cellDate = rowDate.CreateCell(count);
                    if (i == 0)
                    {
                        cellDate.SetCellValue(name);
                    }
                    else
                    {
                        cellDate.SetCellValue(value.ToString());
                    }
                    sheet.AutoSizeColumn(count);
                    count++;
                }
            }
            using (FileStream fs = new FileStream(@"C:\Users\Saber\Desktop\Demo.xlsx", FileMode.OpenOrCreate))
            {
                workbook.Write(fs);
            }
        }
Beispiel #5
0
        //----------------------------------------------------------//

        /// <summary>
        /// 数据单元格,获得数据,并显示
        /// </summary>
        private void GetInfo()
        {
            //从BLL层拿数据,填充 数据列表

            dataGridView_店员管理.AutoGenerateColumns = false;

            List <ManagerInfo> list = new List <ManagerInfo>();

            list = MIBll.GetList();
            dataGridView_店员管理.DataSource = list;

            //编号不能修改,界面初始化 和 添加 后,更新内容,公司员工总数+1
            textBox_编号.Text = (list.Count + 1).ToString();
        }
Beispiel #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            //查询数据,显示到表格上
            ManagerInfoBll miBll = new ManagerInfoBll();
            var            list  = miBll.GetList();

            dataGridView1.DataSource = list;

            //进行excel生成创建操作
            //1、创建workbook,不指定参数,表示创建一个新的工作本
            HSSFWorkbook workbook = new HSSFWorkbook();
            //2、创建sheet
            HSSFSheet sheet = workbook.CreateSheet("管理员");
            //3、创建row
            HSSFRow row = sheet.CreateRow(0);
            //4、创建cell
            HSSFCell cell0 = row.CreateCell(0);

            cell0.SetCellValue("管理员列表");
            //5、设置合并单元格
            sheet.AddMergedRegion(new NPOI.HSSF.Util.Region(0, 0, 0, 3));
            //6、设置单元格居中
            HSSFCellStyle styleTitle = workbook.CreateCellStyle();

            styleTitle.Alignment = 2;//居中
            cell0.CellStyle      = styleTitle;
            //6.1设置字体
            HSSFFont fontTitle = workbook.CreateFont();

            fontTitle.FontHeightInPoints = 14;
            styleTitle.SetFont(fontTitle);


            //7、创建标题行
            //7.1创建行
            HSSFRow rowTitle = sheet.CreateRow(1);
            //7.2创建单元格
            HSSFCell cellTitle0 = rowTitle.CreateCell(0);

            cellTitle0.SetCellValue("编号");
            cellTitle0.CellStyle = styleTitle;

            HSSFCell cellTitle1 = rowTitle.CreateCell(1);

            cellTitle1.SetCellValue("姓名");
            cellTitle1.CellStyle = styleTitle;

            HSSFCell cellTitle2 = rowTitle.CreateCell(2);

            cellTitle2.SetCellValue("密码");
            cellTitle2.CellStyle = styleTitle;

            HSSFCell cellTitle3 = rowTitle.CreateCell(3);

            cellTitle3.SetCellValue("类型");
            cellTitle3.CellStyle = styleTitle;

            //8、遍历集合,创建正文数据
            //8.1遍历集合
            int rowIndex = 2;

            foreach (var mi in list)
            {
                //8.2创建行
                HSSFRow rowData = sheet.CreateRow(rowIndex++);
                //8.3创建数据单元格
                HSSFCell cellData0 = rowData.CreateCell(0);
                cellData0.SetCellValue(mi.MId);

                HSSFCell cellData1 = rowData.CreateCell(1);
                cellData1.SetCellValue(mi.MName);

                HSSFCell cellData2 = rowData.CreateCell(2);
                cellData2.SetCellValue(mi.MPwd);

                HSSFCell cellData3 = rowData.CreateCell(3);
                cellData3.SetCellValue(mi.MType == 1?"经理":"店员");
            }

            //保存工作本
            FileStream stream = new FileStream(@"C:\Users\q1\Desktop\t1.xls", FileMode.Create);

            workbook.Write(stream);
            stream.Close();
            stream.Dispose();
        }
Beispiel #7
0
 private void LoadList()
 {
     gv_ManagerInfoList.AutoGenerateColumns = false;
     gv_ManagerInfoList.DataSource          = miBll.GetList();
 }
Beispiel #8
0
 void LoadList()
 {
     dataGridView1.AutoGenerateColumns = false;
     dataGridView1.DataSource          = miBll.GetList();
 }
Beispiel #9
0
        private void button1_Click(object sender, EventArgs e)
        {
            //导出:将数据库中的数据,存储到一个Excel中
            //1、查询数据
            ManagerInfoBll miBll = new ManagerInfoBll();
            var            list  = miBll.GetList();
            //2、生成Excel
            //2.1 生成workbook
            //2.2 生成sheet
            //2.3 遍历集合,生成行
            //2.4 根据对象生成单元格
            //创建工作本
            HSSFWorkbook workbook = new HSSFWorkbook();
            //创建工作表
            HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet("管理员");
            //创建标题行
            HSSFRow row = (HSSFRow)sheet.CreateRow(0);
            //样式操作
            ICellStyle style = workbook.CreateCellStyle();

            style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.CENTER;
            //设置字体
            var font = workbook.CreateFont();

            font.FontHeightInPoints = 16;
            font.Boldweight         = 1;
            style.SetFont(font);
            //创建单元格
            HSSFCell cellId = (HSSFCell)row.CreateCell(0);

            cellId.CellStyle = style;
            cellId.SetCellValue("编号");
            HSSFCell cellName = (HSSFCell)row.CreateCell(1);

            cellName.SetCellValue("用户名");
            cellName.CellStyle = style;
            HSSFCell cellPwd = (HSSFCell)row.CreateCell(2);

            cellPwd.SetCellValue("密码");
            cellPwd.CellStyle = style;
            HSSFCell cellType = (HSSFCell)row.CreateCell(3);

            cellType.SetCellValue("类型");
            cellType.CellStyle = style;

            //遍历集合,生成行
            int index = 1;

            foreach (var item in list)
            {
                var row1  = sheet.CreateRow(index++);
                var cell0 = row1.CreateCell(0);
                cell0.SetCellValue(item.MId);
                var cell1 = row1.CreateCell(1);
                cell1.SetCellValue(item.MName);
                var cell2 = row1.CreateCell(2);
                cell2.SetCellValue(item.MPwd);
                var cell3 = row1.CreateCell(3);
                cell3.SetCellValue(item.MType == 0 ? "店员" : "经理");
            }

            FileStream file = new FileStream(@"D:\database\a.xls", FileMode.Create, FileAccess.Write);

            workbook.Write(file);
            file.Dispose();
            MessageBox.Show("OK");
        }
Beispiel #10
0
 /// <summary>
 /// 加载数据
 /// </summary>
 private void LoadList()
 {
     dgvList.AutoGenerateColumns = false;
     dgvList.DataSource          = bll.GetList();
 }
Beispiel #11
0
 /// <summary>
 /// 从业务逻辑层中得到管理者数据集合,并将视图绑定到显示控件上
 /// </summary>
 private void LoadList()
 {
     dgvList.AutoGenerateColumns = false;           //不自动新建行
     dgvList.DataSource          = miBll.GetList(); //绑定业务逻辑层返回的数据集合
     dgvList.ClearSelection();                      //清空选择
 }