Beispiel #1
0
        //protected void BtnExport_Click(object sender, EventArgs e)
        //{
        //    Excel.Application app = null;
        //    Excel.Workbook workbook = null;
        //    Excel.Worksheet worksheet = null;
        //    Excel.Range workSheet_range = null;

        //    //设置内容数据
        //    try
        //    {
        //        app = new Excel.Application();
        //        app.Visible = true;
        //        workbook = app.Workbooks.Add(1);//创建workbook
        //        worksheet = (Excel.Worksheet)workbook.Sheets[1];//创建worksheet
        //        worksheet.Columns.EntireColumn.AutoFit();//列宽自适应。
        //        int rows = 0;
        //        //第一行设置格式及内容
        //        Excel.Range workSheet_range2 = null;
        //        workSheet_range2 = worksheet.get_Range("A1", "I1");
        //        workSheet_range2.Merge();//合并单元格
        //        workSheet_range2.Font.Bold = true;//粗体
        //        workSheet_range2.Font.Size = 16;//字号
        //        workSheet_range2.Font.Color = (0 << 16) | (0 << 8) | 0;//字体颜色
        //        workSheet_range2.Interior.Color = (255 << 16) | (255 << 8) | 255;//背景色
        //        workSheet_range2.HorizontalAlignment = Excel.Constants.xlCenter;//居中
        //        workSheet_range2.RowHeight = 30;//行高
        //        workSheet_range2.Borders.Color = System.Drawing.Color.Black.ToArgb();//边框
        //        worksheet.Cells[1, 1] = "固定资产盘点结果";

        //        //第二标题行设置格式及内容
        //        worksheet.Cells[2, 1] = "序号";
        //        worksheet.Cells[2, 2] = "条形码";
        //        worksheet.Cells[2, 3] = "资产编码";
        //        worksheet.Cells[2, 4] = "扫描结果";
        //        worksheet.Cells[2, 5] = "说明";
        //        worksheet.Cells[2, 6] = "资产名称";
        //        worksheet.Cells[2, 7] = "资产状态";
        //        worksheet.Cells[2, 8] = "使用部门";
        //        worksheet.Cells[2, 9] = "使用者";
        //        Excel.Range workSheet_range3 = null;
        //        workSheet_range3 = worksheet.get_Range("A2", "I2");
        //        workSheet_range3.Font.Bold = true;//粗体
        //        workSheet_range3.Font.Size = 14;//字号
        //        workSheet_range3.Font.Color = (255 << 16) | (255 << 8) | 255;//字体颜色
        //        workSheet_range3.Interior.Color = (0 << 16) | (0 << 8) | 0;//背景色
        //        workSheet_range3.HorizontalAlignment = Excel.Constants.xlCenter;//居中
        //        workSheet_range3.Borders.Color = System.Drawing.Color.Black.ToArgb();//边框
        //        //设置列宽
        //        (worksheet.get_Range(worksheet.Cells[2, 1], worksheet.Cells[2, 1])).ColumnWidth = 6;
        //        (worksheet.get_Range(worksheet.Cells[2, 2], worksheet.Cells[2, 2])).ColumnWidth = 10;
        //        (worksheet.get_Range(worksheet.Cells[2, 3], worksheet.Cells[2, 3])).ColumnWidth = 10;
        //        (worksheet.get_Range(worksheet.Cells[2, 4], worksheet.Cells[2, 4])).ColumnWidth = 15;
        //        (worksheet.get_Range(worksheet.Cells[2, 5], worksheet.Cells[2, 5])).ColumnWidth = 25;
        //        (worksheet.get_Range(worksheet.Cells[2, 6], worksheet.Cells[2, 6])).ColumnWidth = 25;
        //        (worksheet.get_Range(worksheet.Cells[2, 7], worksheet.Cells[2, 7])).ColumnWidth = 10;
        //        (worksheet.get_Range(worksheet.Cells[2, 8], worksheet.Cells[2, 8])).ColumnWidth = 15;
        //        (worksheet.get_Range(worksheet.Cells[2, 9], worksheet.Cells[2, 9])).ColumnWidth = 10;

        //        //循环导出盘点结果
        //        DataSet userDs = dal.GetList(strWhere);
        //        DataTable dt = userDs.Tables[0];
        //        rows = 2 + dt.Rows.Count;
        //        for (int i = 0; i < dt.Rows.Count; i++)
        //        {
        //            worksheet.Cells[2 + (i + 1), 1] = (i + 1)+"";
        //            DataRow dr = dt.Rows[i];
        //            worksheet.Cells[2 + (i + 1), 2] = dr["BARCODE"].ToString();
        //            worksheet.Cells[2 + (i + 1), 3] = dr["ASSETCODE"].ToString();
        //            if (dr["RESULT"].ToString().Equals("-1"))
        //            {
        //                worksheet.Cells[2 + (i + 1), 4] = "资产不存在";
        //            }
        //            else if (dr["RESULT"].ToString().Equals("0"))
        //            {
        //                worksheet.Cells[2 + (i + 1), 4] = "资产信息有误";
        //            }
        //            else if (dr["RESULT"].ToString().Equals("1"))
        //            {
        //                worksheet.Cells[2 + (i + 1), 4] = "资产信息正确";
        //            }
        //            else
        //            {
        //                worksheet.Cells[2 + (i + 1), 4] = "";
        //            }
        //            worksheet.Cells[2 + (i + 1), 5] = dr["COMMENTS"].ToString();
        //            FIXEDASSETINFODal assetDal = new FIXEDASSETINFODal();
        //            String assetCode = dr["ASSETCODE"].ToString().Trim();
        //            FIXEDASSETINFOModel assetModel = assetDal.GetModel(assetCode);
        //            if (assetCode.Length > 0 && assetModel != null)
        //            {
        //                worksheet.Cells[2 + (i + 1), 6] = assetModel.ASSETNAME;
        //                if (assetModel.ZICHANZHUANGTAI != null && assetModel.ZICHANZHUANGTAI.ToString().Length > 0 && ztHt[assetModel.ZICHANZHUANGTAI.ToString()] != null)
        //                {
        //                    worksheet.Cells[2 + (i + 1), 7] = (ztHt[assetModel.ZICHANZHUANGTAI.ToString()] == null ? "" : ztHt[assetModel.ZICHANZHUANGTAI.ToString()].ToString().Trim());
        //                }
        //                else
        //                {
        //                    worksheet.Cells[2 + (i + 1), 7] = "";
        //                }
        //                if (assetModel.SHIYONGBUMEN != null && assetModel.SHIYONGBUMEN.ToString().Length > 0 && deptHt[assetModel.SHIYONGBUMEN.ToString()] != null)
        //                {
        //                    worksheet.Cells[2 + (i + 1), 8] = (deptHt[assetModel.SHIYONGBUMEN.ToString()] == null ? "" : deptHt[assetModel.SHIYONGBUMEN.ToString()].ToString().Trim());
        //                }
        //                else
        //                {
        //                    worksheet.Cells[2 + (i + 1), 8] = "";
        //                }
        //                if (assetModel.GUYUANBIANHAO != null && assetModel.GUYUANBIANHAO.ToString().Length > 0 && emplHt[assetModel.GUYUANBIANHAO.ToString()] != null)
        //                {
        //                    worksheet.Cells[2 + (i + 1), 9] = (emplHt[assetModel.GUYUANBIANHAO.ToString()] == null ? "" : emplHt[assetModel.GUYUANBIANHAO.ToString()].ToString().Trim());
        //                }
        //                else
        //                {
        //                    worksheet.Cells[2 + (i + 1), 9] = "";
        //                }
        //            }
        //            else
        //            {
        //                worksheet.Cells[2 + (i + 1), 6] = "";
        //                worksheet.Cells[2 + (i + 1), 7] = "";
        //                worksheet.Cells[2 + (i + 1), 8] = "";
        //                worksheet.Cells[2 + (i + 1), 9] = "";
        //            }
        //        }
        //        workSheet_range = worksheet.get_Range("A3", "I" + rows);
        //        workSheet_range.Borders.Color = System.Drawing.Color.Black.ToArgb();

        //        workbook.SaveCopyAs(@"D:/aa.xls");
        //    }
        //    catch (Exception ee)
        //    {
        //        Log.WriteLog("", "导出异常:"+ee.ToString());
        //        MessageBox.Show("盘点结果导出失败,请重新导出。","",MessageBoxButtons.OK,MessageBoxIcon.None,MessageBoxDefaultButton.Button1,MessageBoxOptions.ServiceNotification);
        //    }
        //    finally
        //    {
        //        app.Quit();
        //    }
        //}

        //选择数据
        protected void MyDataGrid_SelectedIndexChanged(object sender, EventArgs e)
        {
            int X = MyDataGrid.SelectedIndex;
            FIXEDASSETINFODal assetDal  = new FIXEDASSETINFODal();
            String            assetCode = MyDataGrid.Items[X].Cells[1].Text.Trim();

            if (MyDataGrid.Items[X].Cells[7].Text.Trim().Equals("-1"))
            {
                txtAssetcode2.Text = assetCode;
                txtAssetName.Text  = "";
                txtZhuangtai.Text  = "";
                txtDept.Text       = "";
                txtEmployee.Text   = "";
            }
            else
            {
                FIXEDASSETINFOModel assetModel = assetDal.GetModel(assetCode);
                txtAssetcode2.Text = assetCode;
                txtAssetName.Text  = assetModel.ASSETNAME;
                if (assetModel.ZICHANZHUANGTAI != null && assetModel.ZICHANZHUANGTAI.ToString().Length > 0)
                {
                    txtZhuangtai.Text = ztHt[assetModel.ZICHANZHUANGTAI.ToString()] == null ? "" : ztHt[assetModel.ZICHANZHUANGTAI.ToString()].ToString();
                }
                else
                {
                    txtZhuangtai.Text = "";
                }
                if (assetModel.SHIYONGBUMEN != null && assetModel.SHIYONGBUMEN.ToString().Length > 0)
                {
                    txtDept.Text = deptHt[assetModel.SHIYONGBUMEN.ToString()] == null ? "" : deptHt[assetModel.SHIYONGBUMEN.ToString()].ToString();
                }
                else
                {
                    txtDept.Text = "";
                }
                if (assetModel.GUYUANBIANHAO != null && assetModel.GUYUANBIANHAO.ToString().Length > 0)
                {
                    txtEmployee.Text = emplHt[assetModel.GUYUANBIANHAO.ToString()] == null ? "" : emplHt[assetModel.GUYUANBIANHAO.ToString()].ToString();
                }
                else
                {
                    txtEmployee.Text = "";
                }
            }
        }
Beispiel #2
0
        protected void BtnExport_Click(object sender, EventArgs e)
        {
            DataTable EmptyTable = new DataTable();

            EmptyTable.Columns.Add(new DataColumn("序号", typeof(string)));
            EmptyTable.Columns.Add(new DataColumn("条形码", typeof(string)));
            EmptyTable.Columns.Add(new DataColumn("资产编码", typeof(string)));
            EmptyTable.Columns.Add(new DataColumn("扫描结果", typeof(string)));
            EmptyTable.Columns.Add(new DataColumn("说明", typeof(string)));
            EmptyTable.Columns.Add(new DataColumn("资产名称", typeof(string)));
            EmptyTable.Columns.Add(new DataColumn("资产状态", typeof(string)));
            EmptyTable.Columns.Add(new DataColumn("使用部门", typeof(string)));
            EmptyTable.Columns.Add(new DataColumn("使用者", typeof(string)));
            EmptyTable.Columns.Add(new DataColumn("规格型号", typeof(string)));
            EmptyTable.Columns.Add(new DataColumn("资产设备码", typeof(string)));
            EmptyTable.Columns.Add(new DataColumn("序列号", typeof(string)));
            EmptyTable.Columns.Add(new DataColumn("管理部门", typeof(string)));
            EmptyTable.Columns.Add(new DataColumn("资产分类", typeof(string)));
            EmptyTable.Columns.Add(new DataColumn("扫描者", typeof(string)));
            EmptyTable.Columns.Add(new DataColumn("扫描时间", typeof(string)));

            //循环导出盘点结果
            DataSet   userDs = dal.GetList(strWhere);
            DataTable dt     = userDs.Tables[0];

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dr    = dt.Rows[i];
                DataRow drNew = EmptyTable.NewRow();

                drNew[0] = i + 1 + "";
                drNew[1] = dr["BARCODE"].ToString();
                drNew[2] = dr["ASSETCODE"].ToString();
                if (dr["RESULT"].ToString().Equals("-1"))
                {
                    drNew[3] = "资产不存在";
                }
                else if (dr["RESULT"].ToString().Equals("0"))
                {
                    drNew[3] = "资产信息有误";
                }
                else if (dr["RESULT"].ToString().Equals("1"))
                {
                    drNew[3] = "资产信息正确";
                }
                else
                {
                    drNew[3] = "";
                }
                drNew[4] = dr["COMMENTS"].ToString();
                FIXEDASSETINFODal   assetDal   = new FIXEDASSETINFODal();
                String              assetCode  = dr["ASSETCODE"].ToString().Trim();
                FIXEDASSETINFOModel assetModel = assetDal.GetModel(assetCode);
                if (assetCode.Length > 0 && assetModel != null)
                {
                    drNew[5] = assetModel.ASSETNAME;
                    if (assetModel.ZICHANZHUANGTAI != null && assetModel.ZICHANZHUANGTAI.ToString().Length > 0 && ztHt[assetModel.ZICHANZHUANGTAI.ToString()] != null)
                    {
                        drNew[6] = (ztHt[assetModel.ZICHANZHUANGTAI.ToString()] == null ? "" : ztHt[assetModel.ZICHANZHUANGTAI.ToString()].ToString().Trim());
                    }
                    else
                    {
                        drNew[6] = "";
                    }
                    if (assetModel.SHIYONGBUMEN != null && assetModel.SHIYONGBUMEN.ToString().Length > 0 && deptHt[assetModel.SHIYONGBUMEN.ToString()] != null)
                    {
                        drNew[7] = (deptHt[assetModel.SHIYONGBUMEN.ToString()] == null ? "" : deptHt[assetModel.SHIYONGBUMEN.ToString()].ToString().Trim());
                    }
                    else
                    {
                        drNew[7] = "";
                    }
                    if (assetModel.GUYUANBIANHAO != null && assetModel.GUYUANBIANHAO.ToString().Length > 0 && emplHt[assetModel.GUYUANBIANHAO.ToString()] != null)
                    {
                        drNew[8] = (emplHt[assetModel.GUYUANBIANHAO.ToString()] == null ? "" : emplHt[assetModel.GUYUANBIANHAO.ToString()].ToString().Trim());
                    }
                    else
                    {
                        drNew[8] = "";
                    }
                    drNew[9]  = assetModel.GUIGEXINGHAO;
                    drNew[10] = assetModel.ZICHANSHIBEIMA;
                    drNew[11] = assetModel.XULIEHAO;
                    drNew[12] = assetModel.ADMINDEPT;
                    drNew[13] = assetModel.ASSETCLASSIFY;
                }
                else
                {
                    drNew[5]  = "";
                    drNew[6]  = "";
                    drNew[7]  = "";
                    drNew[8]  = "";
                    drNew[9]  = "";
                    drNew[10] = "";
                    drNew[11] = "";
                    drNew[12] = "";
                    drNew[13] = "";
                }
                drNew[14] = dr["SCANPERSON"].ToString();
                drNew[15] = dr["SCANTIME"].ToString();
                EmptyTable.Rows.Add(drNew);
            }
            this.TableExportExcel(EmptyTable, "ScanResultList");
        }
        protected void BtnUpload_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            string filepath = Server.MapPath("./"); //当前路径
            string fileName = FileUpload1.FileName;

            if (fileName.Length > 0)
            {
                filepath += fileName;
                FileUpload1.SaveAs(filepath);

                try
                {
                    string          strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + filepath + ";" + "Extended Properties=\"Excel 8.0;\"";
                    OleDbConnection conn    = new OleDbConnection(strConn);
                    conn.Open();
                    string           strExcel  = "";
                    OleDbDataAdapter myCommand = null;
                    DataSet          ds        = null;
                    strExcel  = "select * from [sheet1$]";
                    myCommand = new OleDbDataAdapter(strExcel, strConn);
                    ds        = new DataSet();
                    myCommand.Fill(ds, "table1");
                    conn.Close();
                    conn.Dispose();
                    int count = 0;
                    //不存在的资产编码
                    string noexitCode = "";
                    //已经导入条码的资产编码
                    string existCode = "";
                    //不存在的资产分类
                    string noexistClassify = "";
                    //条形码长度不等于9
                    string lengtherror = "";
                    if (ds != null && ds.Tables[0].Rows.Count > 0)
                    {
                        FIXEDASSETINFODal   assetDal   = new FIXEDASSETINFODal();
                        FIXEDASSETINFOModel assetModel = new FIXEDASSETINFOModel();
                        BARCODESETTINGDal   setDal     = new BARCODESETTINGDal();
                        BARCODESETTINGModel setModel   = new BARCODESETTINGModel();
                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            DataRow dr = ds.Tables[0].Rows[i];
                            assetModel = assetDal.GetModel(dr[0].ToString().Trim());
                            if (assetModel != null)
                            {
                                string barcode = dr[1].ToString().Trim();
                                if (barcode.Length == 9)
                                {
                                    setModel = setDal.GetModelDueCode(barcode.Substring(0, 3));
                                    if (setModel != null)
                                    {
                                        if (assetModel.BARCODE != null && assetModel.BARCODE.Length > 0 &&
                                            assetModel.ADMINDEPT != null && assetModel.ADMINDEPT.Length > 0 &&
                                            (!assetModel.ADMINDEPT.Equals(setModel.DEPTCODE)))
                                        {
                                            if (existCode.Length > 0)
                                            {
                                                existCode = existCode + "," + dr[0].ToString().Trim();
                                            }
                                            else
                                            {
                                                existCode = dr[0].ToString().Trim();
                                            }
                                        }
                                        else
                                        {
                                            assetModel.BARCODE = barcode;
                                            if (setModel != null)
                                            {
                                                assetModel.ADMINDEPT     = setModel.DEPTCODE;
                                                assetModel.ASSETCLASSIFY = setModel.ASSETCLASSIFY;
                                            }
                                            assetDal.Update(assetModel);

                                            int maxcode = int.Parse(barcode.Substring(3));
                                            if (setModel.MAXCODE < maxcode)
                                            {
                                                setModel.MAXCODE = maxcode;
                                                setDal.Update(setModel);
                                            }
                                            count++;
                                        }
                                    }
                                    else
                                    {
                                        if (noexistClassify.Length > 0)
                                        {
                                            noexistClassify = noexistClassify + "," + dr[0].ToString().Trim();
                                        }
                                        else
                                        {
                                            noexistClassify = dr[0].ToString().Trim();
                                        }
                                    }
                                }
                                else
                                {
                                    if (lengtherror.Length > 0)
                                    {
                                        lengtherror = lengtherror + "," + dr[0].ToString().Trim();
                                    }
                                    else
                                    {
                                        lengtherror = dr[0].ToString().Trim();
                                    }
                                }
                            }
                            else
                            {
                                if (noexitCode.Length > 0)
                                {
                                    noexitCode = noexitCode + "," + dr[0].ToString().Trim();
                                }
                                else
                                {
                                    noexitCode = dr[0].ToString().Trim();
                                }
                            }
                        }
                        string strMsg = "";
                        if (noexitCode.Length > 0)
                        {
                            strMsg = strMsg + @"系统中不存在资产编码[" + noexitCode + "]。";
                        }
                        if (lengtherror.Length > 0)
                        {
                            if (strMsg.Length > 0)
                            {
                                strMsg = strMsg + @"\n\n";
                            }
                            strMsg = strMsg + @"资产编码[" + lengtherror + "]的条形码长度不是9,所以不能导入。";
                        }
                        if (existCode.Length > 0)
                        {
                            if (strMsg.Length > 0)
                            {
                                strMsg = strMsg + @"\n\n";
                            }
                            strMsg = strMsg + @"资产编码[" + existCode + "]已经存在条形码,且资产管理部门为其他部门,所以不能导入。";
                        }
                        if (noexistClassify.Length > 0)
                        {
                            if (strMsg.Length > 0)
                            {
                                strMsg = strMsg + @"\n\n";
                            }
                            strMsg = strMsg + @"资产编码[" + noexistClassify + "]对应的资产分类不存在,请在条形码设置画面添加分类后再进行导入操作。";
                        }
                        if (strMsg.Length > 0)
                        {
                            strMsg = strMsg + @"\n\n";
                        }
                        strMsg = strMsg + @"共有" + count + "个资产的条形码信息成功导入。";
                        baseoperation.ShowErrorMessage(this.Page, @strMsg);
                    }
                    else
                    {
                        baseoperation.ShowErrorMessage(this.Page, "该文件为空,没有进行资产的条形码信息更新。");
                    }
                }
                catch (Exception ee) {
                    Log.WriteLog("", ee.ToString());
                    baseoperation.ShowErrorMessage(this.Page, "上传条形码信息出错,请重新操作。");
                }
            }
            else
            {
                baseoperation.ShowErrorMessage(this.Page, "请选择上传文件。");
            }
        }