Exemplo n.º 1
0
        private void Upload_Geo_Click(object sender, EventArgs e)
        {
            openFileDialog1.Multiselect = false;
            openFileDialog1.Title = "几何信息导入数据库";
            openFileDialog1.FileName = "几何信息模板.xlsx";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                ExcelCmd excelcmd = new ExcelCmd();
                excelcmd.CreateOrOpenExcelFile(false, openFileDialog1.FileName);
                excelcmd.SetActiveSheet(1);

                string[] column = Enum.GetNames(typeof(ColName_VehicleGeo));

                int ExcelRow = excelcmd.GetLastRow(1);

                progressBar.Minimum = 0;
                progressBar.Value = 0;
                progressBar.Maximum = ExcelRow - 1;

                for (int iLoop = 2; iLoop <= ExcelRow; ++iLoop)
                {
                    progressBar.Value++;
                    GeoInfo UpdataGeoInfo = new GeoInfo();

                    UpdataGeoInfo.视图 = (string)excelcmd.GetCell(iLoop, 6);
                    string path = (string)excelcmd.GetCell(iLoop, 5);
                    string filter = Path.GetExtension(path).Substring(1, Path.GetExtension(path).Length - 1);

                    UpdataGeoInfo.Ext = filter;
                    if (UpdataGeoInfo.Ext.ToUpper() == "TMPLT" ||
                            UpdataGeoInfo.Ext.ToUpper() == "LQB" ||
                            UpdataGeoInfo.Ext.ToUpper() == "BWF" ||
                            UpdataGeoInfo.Ext.ToUpper() == "PRT" ||
                            UpdataGeoInfo.Ext.ToUpper() == "STL" ||
                            UpdataGeoInfo.Ext.ToUpper() == "JPG")
                    {
                        UpdataGeoInfo.汽车ID = (string)excelcmd.GetCell(iLoop, 1);
                        UpdataGeoInfo.Car = (string)excelcmd.GetCell(iLoop, 2);
                        UpdataGeoInfo.Band = (string)excelcmd.GetCell(iLoop, 3);
                        UpdataGeoInfo.Factory = (string)excelcmd.GetCell(iLoop, 4);

                        string str = "select top 1 版本 from GeoInfo_" + UpdataGeoInfo.Ext +
                            " where 汽车ID = '" + UpdataGeoInfo.汽车ID + "' and 视图= '" + UpdataGeoInfo.视图 +
                            " 'order by 版本 desc";
                        DatabaseCmd datacmd = new DatabaseCmd();
                        MySqlDataReader myreader;
                        datacmd.SqlExecuteReader(str, out myreader);

                        UpdataGeoInfo.Version = (myreader.Read()) ? (UpdataGeoInfo.Version = myreader.GetInt32(0) + 1) : (1);
                        datacmd.SqlReaderClose();

                        UserFunction.FileToBinary(path, out UpdataGeoInfo.ByteData);
                        UpdataGeoInfo.IsModel = ((string)excelcmd.GetCell(iLoop, 7) == "是") ? (true) : (false);
                        UpdataGeoInfo.UpdateDate = UserFunction.GetServerDateTime();
                        UpdataGeoInfo.信息更新者工号 = ManagementMain.UserNum;
                        UpdataGeoInfo.信息更新者姓名 = ManagementMain.UserName;

                        if (UpdataGeoInfo.ByteData != null)
                        {
                            SqlUploadGeoInfo(column, UpdataGeoInfo, 5);
                        }
                    }
                    else
                    {
                        MessageBox.Show("请上传正确的数据文件");
                    }
                }
                excelcmd.ExitExcelApp();
                MessageBox.Show("导入成功");
                ManagementMain.refreshgeoinfo("", 1);
            }
        }