移交Instrumentation表格

This commit is contained in:
潘鸿锋 2024-01-26 11:30:01 +08:00
parent 0e2aa3bb4c
commit e65e820da1
10 changed files with 1097 additions and 1 deletions

2
.gitignore vendored
View File

@ -31,3 +31,5 @@
/SGGL/BLL/obj
/SGGL/FineUIPro.Web/obj
/SGGL/Model/obj
/SGGL/FineUIPro.Web/web.config
/SGGL/FineUIPro.Web/ErrLog.txt

View File

@ -1826,6 +1826,8 @@
<Content Include="TestRun\TestRunManage\TailTermHandleList.aspx" />
<Content Include="TestRun\TestRunManage\TestRunRecordUpload.aspx" />
<Content Include="TestRun\TestRunManage\TestRunRecordUploadList.aspx" />
<Content Include="Transfer\Instrumentation.aspx" />
<Content Include="Transfer\InstrumentationDataIn.aspx" />
<Content Include="Transfer\ProjectSetup.aspx" />
<Content Include="Video\Video.aspx" />
<Content Include="ZHGL\DataIn\AccidentCauseReportBar.aspx" />
@ -16298,6 +16300,20 @@
<Compile Include="TestRun\TestRunManage\TestRunRecordUploadList.aspx.designer.cs">
<DependentUpon>TestRunRecordUploadList.aspx</DependentUpon>
</Compile>
<Compile Include="Transfer\Instrumentation.aspx.cs">
<DependentUpon>Instrumentation.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Transfer\Instrumentation.aspx.designer.cs">
<DependentUpon>Instrumentation.aspx</DependentUpon>
</Compile>
<Compile Include="Transfer\InstrumentationDataIn.aspx.cs">
<DependentUpon>InstrumentationDataIn.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Transfer\InstrumentationDataIn.aspx.designer.cs">
<DependentUpon>InstrumentationDataIn.aspx</DependentUpon>
</Compile>
<Compile Include="Transfer\ProjectSetup.aspx.cs">
<DependentUpon>ProjectSetup.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<LastActiveSolutionConfig>Release|Any CPU</LastActiveSolutionConfig>
<LastActiveSolutionConfig>Debug|Any CPU</LastActiveSolutionConfig>
<UseIISExpress>true</UseIISExpress>
<Use64BitIISExpress>false</Use64BitIISExpress>
<IISExpressSSLPort />

View File

@ -0,0 +1,117 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Instrumentation.aspx.cs" Inherits="FineUIPro.Web.Transfer.Instrumentation" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Instrumentation</title>
</head>
<body>
<form id="form1" runat="server">
<f:PageManager ID="PageManager1" runat="server" AutoSizePanelID="Panel1" />
<f:Panel ID="Panel1" runat="server" Margin="5px" BodyPadding="5px" ShowBorder="false"
ShowHeader="false" Layout="VBox" BoxConfigAlign="Stretch">
<Items>
<f:Grid ID="Grid1" ShowBorder="true" ShowHeader="false" EnableCollapse="true"
runat="server" BoxFlex="1" DataKeyNames="Id" AllowCellEditing="true" EnableColumnLines="true"
ClicksToEdit="2" DataIDField="Id" AllowSorting="true" SortField="Test_Package_START"
SortDirection="DESC" OnSort="Grid1_Sort"
AllowPaging="true" IsDatabasePaging="true" PageSize="10" OnPageIndexChange="Grid1_PageIndexChange"
EnableRowDoubleClickEvent="true" EnableTextSelection="true">
<Toolbars>
<f:Toolbar ID="ToolSearch" Position="Top" runat="server" ToolbarAlign="Left">
<Items>
<f:TextBox runat="server" ID="txtINSTRUMENTATION" Label="INSTRUMENTATION" LabelWidth="150px" LabelAlign="Right"></f:TextBox>
<f:DatePicker runat="server" Label="Test_Package_START" ID="txtStarTime" LabelAlign="Right" LabelWidth="150px"
Width="280px">
</f:DatePicker>
<f:Label ID="Label1" runat="server" Text="至">
</f:Label>
<f:DatePicker runat="server" ID="txtEndTime" LabelAlign="Right" Width="150px">
</f:DatePicker>
<f:Button ID="btnSearch" Icon="SystemSearch" EnablePostBack="true" runat="server" OnClick="btnSearch_Click" ToolTip="查询">
</f:Button>
<f:ToolbarFill runat="server"></f:ToolbarFill>
<%-- <f:Button ID="btnNew" Icon="Add" EnablePostBack="true" runat="server" OnClick="btnNew_Click" ToolTip="新增" Hidden="true">
</f:Button>--%>
<f:Button ID="btnImport" ToolTip="导入" Icon="PackageIn" runat="server" OnClick="btnImport_Click" Hidden="true">
</f:Button>
</Items>
</f:Toolbar>
</Toolbars>
<Columns>
<f:GroupField HeaderText="INSTRUMENTATION" TextAlign="Center" MinWidth="200px">
<Columns>
<f:BoundField Width="200px" TextAlign="Center" ColumnID="INSTRUMENTATION" DataField="INSTRUMENTATION" HeaderText="INSTRUMENTATION" />
</Columns>
</f:GroupField>
<f:GroupField HeaderText="SYSTEM AND TEST PACKAGE SELECTION" TextAlign="Center" MinWidth="450">
<Columns>
<f:BoundField Width="150px" ColumnID="SystemName" DataField="SystemName" HeaderText="SYSTEM" TextAlign="Center"/>
<f:BoundField Width="150px" ColumnID="Subsystem" DataField="Subsystem" HeaderText="Subsystem" TextAlign="Center"/>
<f:BoundField Width="150px" ColumnID="Test_Package" DataField="Test_Package" HeaderText="Test Package" TextAlign="Center"/>
</Columns>
</f:GroupField>
<f:GroupField HeaderText="Test Package Schedule" TextAlign="Center" MinWidth="400px">
<Columns>
<f:RenderField Width="200px" ColumnID="Test_Package_START" DataField="Test_Package_START" HeaderText="Test Package START" TextAlign="Center"
FieldType="Date" Renderer="Date" RendererArgument="yyyy-MM-dd"/>
<f:RenderField Width="200px" ColumnID="Test_Package_FINISH" DataField="Test_Package_FINISH" HeaderText="Test Package FINISH" TextAlign="Center"
FieldType="Date" Renderer="Date" RendererArgument="yyyy-MM-dd"/>
</Columns>
</f:GroupField>
<f:BoundField MinWidth="200px" ColumnID="FINAL_Status" DataField="FINAL_Status" HeaderText="FINAL Status" TextAlign="Center"/>
</Columns>
<Listeners>
<f:Listener Event="beforerowcontextmenu" Handler="onRowContextMenu" />
</Listeners>
<PageItems>
<f:ToolbarText ID="ToolbarText1" runat="server" Text="每页记录数:">
</f:ToolbarText>
<f:DropDownList runat="server" ID="ddlPageSize" Width="80px" AutoPostBack="true" OnSelectedIndexChanged="ddlPageSize_SelectedIndexChanged">
<f:ListItem Text="10" Value="10" />
<f:ListItem Text="15" Value="15" />
<f:ListItem Text="20" Value="20" />
<f:ListItem Text="25" Value="25" />
<f:ListItem Text="所有行" Value="100000" />
</f:DropDownList>
</PageItems>
</f:Grid>
</Items>
</f:Panel>
<f:Window ID="Window2" Title="弹出窗体" Hidden="true" EnableIFrame="true" EnableMaximize="true"
Target="Top" EnableResize="false" runat="server" OnClose="Window1_Close" IsModal="true"
Width="700px" Height="560px">
</f:Window>
<f:Menu ID="Menu1" runat="server">
<Items>
<%--<f:MenuButton ID="btnMenuModify" EnablePostBack="true" runat="server" Text="修改" Icon="Pencil" OnClick="btnMenuModify_Click" Hidden="true">
</f:MenuButton>--%>
<f:MenuButton ID="btnMenuDel" EnablePostBack="true" runat="server" Icon="Delete" Text="删除" ConfirmText="确定删除当前数据?"
OnClick="btnMenuDel_Click" Hidden="true">
</f:MenuButton>
</Items>
</f:Menu>
</form>
<script type="text/javascript">
var menuID = '<%= Menu1.ClientID %>';
// 返回false来阻止浏览器右键菜单
function onRowContextMenu(event, rowId) {
F(menuID).show(); //showAt(event.pageX, event.pageY);
return false;
}
</script>
</body>
</html>

View File

@ -0,0 +1,199 @@
using BLL;
using BLL.CQMS.Comprehensive;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
namespace FineUIPro.Web.Transfer
{
public partial class Instrumentation : PageBase
{
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetButtonPower();
BindGrid();
}
}
/// <summary>
/// 数据绑定
/// </summary>
public void BindGrid()
{
string strSql = @"select*from Transfer_Instrumentation
where ProjectId = @ProjectId";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
if (!string.IsNullOrEmpty(this.txtINSTRUMENTATION.Text.Trim()))
{
strSql += " AND INSTRUMENTATION like @INSTRUMENTATION";
listStr.Add(new SqlParameter("@INSTRUMENTATION", "%" + this.txtINSTRUMENTATION.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(txtStarTime.Text.Trim()))
{
strSql += " AND Test_Package_START >= @InspectionDateA";
listStr.Add(new SqlParameter("@InspectionDateA", Funs.GetNewDateTime(txtStarTime.Text.Trim())));
}
if (!string.IsNullOrEmpty(txtEndTime.Text.Trim()))
{
strSql += " AND Test_Package_START <= @InspectionDateZ";
listStr.Add(new SqlParameter("@InspectionDateZ", Funs.GetNewDateTime(txtEndTime.Text.Trim())));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
#endregion
#region
/// <summary>
/// 分页下拉
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
/// <summary>
/// 分页索引事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortField = e.SortField;
BindGrid();
}
#endregion
#region
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSearch_Click(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 右键删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDel_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
Model.Transfer_Instrumentation model = Funs.DB.Transfer_Instrumentation.FirstOrDefault(x=>x.Id==rowID);
if (model != null)
{
Funs.DB.Transfer_Instrumentation.DeleteOnSubmit(model);
Funs.DB.SubmitChanges();
}
}
BindGrid();
ShowNotify("删除数据成功!", MessageBoxIcon.Success);
}
}
#endregion
#region
/// <summary>
/// 导入按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("InstrumentationDataIn.aspx", "导入 - ")));
}
#endregion
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower()
{
if (Request.Params["value"] == "0")
{
return;
}
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.InstrumentationMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnAdd))
{
//this.btnNew.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnModify))
{
//this.btnMenuModify.Hidden = false;
this.Grid1.EnableRowDoubleClickEvent = true;
}
else
{
this.Grid1.EnableRowDoubleClickEvent = false;
}
if (buttonList.Contains(BLL.Const.BtnDelete))
{
this.btnMenuDel.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnSave))
{
this.btnImport.Hidden = false;
}
}
}
#endregion
}
}

View File

@ -0,0 +1,161 @@
//------------------------------------------------------------------------------
// <自动生成>
// 此代码由工具生成。
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// </自动生成>
//------------------------------------------------------------------------------
namespace FineUIPro.Web.Transfer
{
public partial class Instrumentation
{
/// <summary>
/// form1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlForm form1;
/// <summary>
/// PageManager1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.PageManager PageManager1;
/// <summary>
/// Panel1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Panel Panel1;
/// <summary>
/// Grid1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Grid Grid1;
/// <summary>
/// ToolSearch 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Toolbar ToolSearch;
/// <summary>
/// txtINSTRUMENTATION 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.TextBox txtINSTRUMENTATION;
/// <summary>
/// txtStarTime 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.DatePicker txtStarTime;
/// <summary>
/// Label1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Label Label1;
/// <summary>
/// txtEndTime 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.DatePicker txtEndTime;
/// <summary>
/// btnSearch 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnSearch;
/// <summary>
/// btnImport 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnImport;
/// <summary>
/// ToolbarText1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.ToolbarText ToolbarText1;
/// <summary>
/// ddlPageSize 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.DropDownList ddlPageSize;
/// <summary>
/// Window2 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Window Window2;
/// <summary>
/// Menu1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Menu Menu1;
/// <summary>
/// btnMenuDel 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.MenuButton btnMenuDel;
}
}

View File

@ -0,0 +1,68 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="InstrumentationDataIn.aspx.cs" Inherits="FineUIPro.Web.Transfer.InstrumentationDataIn" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<f:PageManager ID="PageManager1" AutoSizePanelID="SimpleForm1" runat="server" OnCustomEvent="PageManager1_CustomEvent" />
<f:Form ID="SimpleForm1" ShowBorder="false" ShowHeader="false" AutoScroll="true"
BodyPadding="10px" runat="server" RedStarPosition="BeforeText" LabelAlign="Right">
<Toolbars>
<f:Toolbar ID="Toolbar2" Position="Top" ToolbarAlign="Right" runat="server">
<Items>
<f:HiddenField ID="hdFileName" runat="server">
</f:HiddenField>
<f:Button ID="btnAudit" Icon="ApplicationEdit" runat="server" ToolTip="审核" ValidateForms="SimpleForm1" Text="审核"
OnClick="btnAudit_Click">
</f:Button>
<f:Button ID="btnImport" Icon="ApplicationGet" runat="server" ToolTip="导入" ValidateForms="SimpleForm1" Text="导入"
OnClick="btnImport_Click">
</f:Button>
<f:Button ID="btnDownLoad" runat="server" Icon="ApplicationGo" ToolTip="下载模板" OnClick="btnDownLoad_Click" Text="下载模板">
</f:Button>
<f:HiddenField ID="hdCheckResult" runat="server">
</f:HiddenField>
</Items>
</f:Toolbar>
</Toolbars>
<Rows>
<f:FormRow>
<Items>
<f:FileUpload runat="server" ID="fuAttachUrl" EmptyText="选择要导入的文件" Label="选择要导入的文件"
LabelWidth="150px">
</f:FileUpload>
</Items>
</f:FormRow>
<f:FormRow>
<Items>
<f:Grid ID="gvErrorInfo" ShowBorder="true" EnableAjax="false" ShowHeader="false" Title="人员报验" EnableCollapse="true"
runat="server" BoxFlex="1" AllowCellEditing="true" ClicksToEdit="2" AllowSorting="true"
SortDirection="DESC" EnableColumnLines="true" ForceFit="true" AllowPaging="true" IsDatabasePaging="true" PageSize="10"
EnableRowDoubleClickEvent="true" AllowFilters="true" EnableTextSelection="True">
<Columns>
<f:TemplateField ColumnID="tfPageIndex" Width="55px" HeaderText="序号" HeaderTextAlign="Center" TextAlign="Center"
EnableLock="true" Locked="False">
<ItemTemplate>
<asp:Label ID="lblPageIndex" runat="server" Text='<%# gvErrorInfo.PageIndex * gvErrorInfo.PageSize + Container.DataItemIndex + 1 %>'></asp:Label>
</ItemTemplate>
</f:TemplateField>
<f:BoundField DataField="Row" HeaderText="错误行号">
</f:BoundField>
<f:BoundField DataField="Column" HeaderText="错误列">
</f:BoundField>
<f:BoundField DataField="Reason" HeaderText="错误类型">
</f:BoundField>
</Columns>
</f:Grid>
</Items>
</f:FormRow>
</Rows>
</f:Form>
</form>
</body>
</html>

View File

@ -0,0 +1,408 @@
using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.Transfer
{
public partial class InstrumentationDataIn : PageBase
{
#region
/// <summary>
/// 上传预设的虚拟路径
/// </summary>
private string initPath = Const.ExcelUrl;
/// <summary>
/// 错误集合
/// </summary>
public static List<Model.ErrorInfo> errorInfos = new List<Model.ErrorInfo>();
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.hdCheckResult.Text = string.Empty;
this.hdFileName.Text = string.Empty;
if (errorInfos != null)
{
errorInfos.Clear();
}
}
}
#endregion
#region
/// <summary>
/// 审核
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAudit_Click(object sender, EventArgs e)
{
try
{
if (this.fuAttachUrl.HasFile == false)
{
ShowNotify("请您选择Excel文件", MessageBoxIcon.Warning);
return;
}
string IsXls = Path.GetExtension(this.fuAttachUrl.FileName).ToString().Trim().ToLower();
if (IsXls != ".xls")
{
ShowNotify("只可以选择Excel文件", MessageBoxIcon.Warning);
return;
}
if (errorInfos != null)
{
errorInfos.Clear();
}
string rootPath = Server.MapPath("~/");
string initFullPath = rootPath + initPath;
if (!Directory.Exists(initFullPath))
{
Directory.CreateDirectory(initFullPath);
}
this.hdFileName.Text = BLL.Funs.GetNewFileName() + IsXls;
string filePath = initFullPath + this.hdFileName.Text;
this.fuAttachUrl.PostedFile.SaveAs(filePath);
ImportXlsToData(rootPath + initPath + this.hdFileName.Text);
}
catch (Exception ex)
{
ShowNotify("'" + ex.Message + "'", MessageBoxIcon.Warning);
}
}
#region Excel提取数据
/// <summary>
/// 从Excel提取数据--》Dataset
/// </summary>
/// <param name="filename">Excel文件路径名</param>
private void ImportXlsToData(string fileName)
{
try
{
string oleDBConnString = String.Empty;
oleDBConnString = "Provider=Microsoft.Jet.OLEDB.4.0;";
oleDBConnString += "Data Source=";
oleDBConnString += fileName;
oleDBConnString += ";Extended Properties=Excel 8.0;";
OleDbConnection oleDBConn = null;
OleDbDataAdapter oleAdMaster = null;
DataTable m_tableName = new DataTable();
DataSet ds = new DataSet();
oleDBConn = new OleDbConnection(oleDBConnString);
oleDBConn.Open();
m_tableName = oleDBConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
if (m_tableName != null && m_tableName.Rows.Count > 0)
{
m_tableName.TableName = m_tableName.Rows[0]["TABLE_NAME"].ToString().Trim();
}
string sqlMaster;
sqlMaster = " SELECT * FROM [" + m_tableName.TableName + "]";
oleAdMaster = new OleDbDataAdapter(sqlMaster, oleDBConn);
oleAdMaster.Fill(ds, "m_tableName");
oleAdMaster.Dispose();
oleDBConn.Close();
oleDBConn.Dispose();
AddDatasetToSQL(ds.Tables[0], 7);
hdCheckResult.Text = "1";
}
catch (Exception exc)
{
Response.Write(exc);
//return null;
// return dt;
}
finally
{
}
}
#endregion
#region Dataset的数据导入数据库
/// <summary>
/// 将Dataset的数据导入数据库
/// </summary>
/// <param name="pds">数据集</param>
/// <param name="Cols">数据集行数</param>
/// <returns></returns>
private bool AddDatasetToSQL(DataTable pds, int Cols)
{
string result = string.Empty;
int ic, ir;
ic = pds.Columns.Count;
if (ic < Cols)
{
ShowNotify("导入Excel格式错误Excel只有" + ic.ToString().Trim() + "列", MessageBoxIcon.Warning);
return false;
}
ir = pds.Rows.Count;
if (pds != null && ir > 0)
{
var oldViewInfos = from x in Funs.DB.Comprehensive_InspectionEquipment
where x.ProjectId == this.CurrUser.LoginProjectId
select x;
var units = from x in Funs.DB.Base_Unit
join y in Funs.DB.Project_ProjectUnit on x.UnitId equals y.UnitId
where y.ProjectId == this.CurrUser.LoginProjectId
select x;
var cns = from x in Funs.DB.Base_CNProfessional select x;
for (int i = 0; i < ir; i++)
{
string row4 = pds.Rows[i][4].ToString();
if (!string.IsNullOrEmpty(row4))
{
try
{
DateTime date = Convert.ToDateTime(row4.Trim());
}
catch (Exception)
{
result += (i + 2).ToString() + "," + "Test Package START" + "," + "[" + row4 + "]错误!不是日期格式!" + "|";
}
}
string row5 = pds.Rows[i][5].ToString();
if (!string.IsNullOrEmpty(row4))
{
try
{
DateTime date = Convert.ToDateTime(row5.Trim());
}
catch (Exception)
{
result += (i + 2).ToString() + "," + "Test Package FINISH" + "," + "[" + row5 + "]错误!不是日期格式!" + "|";
}
}
}
if (!string.IsNullOrEmpty(result))
{
result = result.Substring(0, result.LastIndexOf("|"));
}
errorInfos.Clear();
if (!string.IsNullOrEmpty(result))
{
string results = result;
List<string> errorInfoList = results.Split('|').ToList();
foreach (var item in errorInfoList)
{
string[] errors = item.Split(',');
Model.ErrorInfo errorInfo = new Model.ErrorInfo();
errorInfo.Row = errors[0];
errorInfo.Column = errors[1];
errorInfo.Reason = errors[2];
errorInfos.Add(errorInfo);
}
if (errorInfos.Count > 0)
{
this.gvErrorInfo.DataSource = errorInfos;
this.gvErrorInfo.DataBind();
}
}
else
{
ShowNotify("审核完成,请点击导入!", MessageBoxIcon.Success);
}
}
else
{
ShowNotify("导入数据为空!", MessageBoxIcon.Warning);
}
return true;
}
#endregion
#endregion
#region
/// <summary>
/// 导入
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(hdCheckResult.Text))
{
if (errorInfos.Count <= 0)
{
string rootPath = Server.MapPath("~/");
ImportXlsToData2(rootPath + initPath + this.hdFileName.Text);
hdCheckResult.Text = string.Empty;
ShowNotify("导入成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
else
{
ShowNotify("请先将错误数据修正,再重新导入提交!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("请先审核要导入的文件!", MessageBoxIcon.Warning);
}
}
#region Excel提取数据
/// <summary>
/// 从Excel提取数据--》Dataset
/// </summary>
/// <param name="filename">Excel文件路径名</param>
private void ImportXlsToData2(string fileName)
{
try
{
string oleDBConnString = String.Empty;
oleDBConnString = "Provider=Microsoft.Jet.OLEDB.4.0;";
oleDBConnString += "Data Source=";
oleDBConnString += fileName;
oleDBConnString += ";Extended Properties=Excel 8.0;";
OleDbConnection oleDBConn = null;
OleDbDataAdapter oleAdMaster = null;
DataTable m_tableName = new DataTable();
DataSet ds = new DataSet();
oleDBConn = new OleDbConnection(oleDBConnString);
oleDBConn.Open();
m_tableName = oleDBConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
if (m_tableName != null && m_tableName.Rows.Count > 0)
{
m_tableName.TableName = m_tableName.Rows[0]["TABLE_NAME"].ToString().Trim();
}
string sqlMaster;
sqlMaster = " SELECT * FROM [" + m_tableName.TableName + "]";
oleAdMaster = new OleDbDataAdapter(sqlMaster, oleDBConn);
oleAdMaster.Fill(ds, "m_tableName");
oleAdMaster.Dispose();
oleDBConn.Close();
oleDBConn.Dispose();
AddDatasetToSQL2(ds.Tables[0], 7);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region Dataset的数据导入数据库
/// <summary>
/// 将Dataset的数据导入数据库
/// </summary>
/// <param name="pds">数据集</param>
/// <param name="Cols">数据集列数</param>
/// <returns></returns>
private bool AddDatasetToSQL2(DataTable pds, int Cols)
{
int ic, ir;
ic = pds.Columns.Count;
if (ic < Cols)
{
ShowNotify("导入Excel格式错误Excel只有" + ic.ToString().Trim() + "列", MessageBoxIcon.Warning);
}
string result = string.Empty;
ir = pds.Rows.Count;
if (pds != null && ir > 0)
{
List<Model.Transfer_Instrumentation> list = new List<Model.Transfer_Instrumentation>();
for (int i = 0; i < ir; i++)
{
Model.Transfer_Instrumentation model = new Model.Transfer_Instrumentation();
model.Id = Guid.NewGuid().ToString();
model.ProjectId = CurrUser.LoginProjectId;
model.INSTRUMENTATION= pds.Rows[i][0].ToString().Trim();
model.SystemName= pds.Rows[i][1].ToString().Trim();
model.Subsystem= pds.Rows[i][2].ToString().Trim();
model.Test_Package = pds.Rows[i][3].ToString().Trim();
DateTime t1, t2;
if (DateTime.TryParse(pds.Rows[i][4].ToString(), out t1) && !string.IsNullOrEmpty(pds.Rows[i][4].ToString()))
model.Test_Package_START = t1;
if (DateTime.TryParse(pds.Rows[i][5].ToString(), out t2) && !string.IsNullOrEmpty(pds.Rows[i][5].ToString()))
model.Test_Package_FINISH = t2;
model.FINAL_Status= pds.Rows[i][6].ToString().Trim();
list.Add(model);
}
if (list.Count > 0)
{
Funs.DB.Transfer_Instrumentation.InsertAllOnSubmit(list);
Funs.DB.SubmitChanges();
}
}
else
{
ShowNotify("导入数据为空!", MessageBoxIcon.Warning);
}
return true;
}
#endregion
#endregion
#region
/// <summary>
/// 下载模板按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDownLoad_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Confirm.GetShowReference("确定下载导入模板吗?", String.Empty, MessageBoxIcon.Question, PageManager1.GetCustomEventReference(false, "Confirm_OK"), PageManager1.GetCustomEventReference("Confirm_Cancel")));
}
/// <summary>
/// 下载导入模板
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void PageManager1_CustomEvent(object sender, CustomEventArgs e)
{
if (e.EventArgument == "Confirm_OK")
{
string rootPath = Server.MapPath("~/");
string uploadfilepath = rootPath + "File\\Excel\\DataIn\\Instrumentation导入模板.xls";
string filePath = "File\\Excel\\DataIn\\Instrumentation导入模板.xls";
string fileName = Path.GetFileName(filePath);
FileInfo info = new FileInfo(uploadfilepath);
long fileSize = info.Length;
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.ContentType = "excel/plain";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("Content-Length", fileSize.ToString().Trim());
Response.TransmitFile(uploadfilepath, 0, fileSize);
Response.End();
}
}
#endregion
}
}

View File

@ -0,0 +1,125 @@
//------------------------------------------------------------------------------
// <自动生成>
// 此代码由工具生成。
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// </自动生成>
//------------------------------------------------------------------------------
namespace FineUIPro.Web.Transfer
{
public partial class InstrumentationDataIn
{
/// <summary>
/// form1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlForm form1;
/// <summary>
/// PageManager1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.PageManager PageManager1;
/// <summary>
/// SimpleForm1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Form SimpleForm1;
/// <summary>
/// Toolbar2 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Toolbar Toolbar2;
/// <summary>
/// hdFileName 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.HiddenField hdFileName;
/// <summary>
/// btnAudit 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnAudit;
/// <summary>
/// btnImport 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnImport;
/// <summary>
/// btnDownLoad 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnDownLoad;
/// <summary>
/// hdCheckResult 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.HiddenField hdCheckResult;
/// <summary>
/// fuAttachUrl 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.FileUpload fuAttachUrl;
/// <summary>
/// gvErrorInfo 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Grid gvErrorInfo;
/// <summary>
/// lblPageIndex 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::System.Web.UI.WebControls.Label lblPageIndex;
}
}