コード例 #1
0
ファイル: SpecImport.aspx.cs プロジェクト: demonzhq/JLR
		protected void btnImport_Click(object sender, System.EventArgs e)
		{
			bool error = false;
			string copiedFileName = "";
			string submittedFileName = "";
			string message = "";
			string importMessage = "";
			DataSet importDS;

			uploadVersion = txtVersion.Text;

			if (txtFile.PostedFile.ContentLength > 0)
			{
				// Check content type - should only be an XLS file
				switch (txtFile.PostedFile.ContentType)
				{
					case "application/vnd.ms-excel" : case "application/octet-stream" : 
						submittedFileName = txtFile.PostedFile.FileName;
						try
						{
							// Copy the file to the server
							copiedFileName = CopyFile(submittedFileName);
							// Import the file
							if (int.Parse(cboSpecType.SelectedItem.Value) == (int)Constants.SpecType.T5 || int.Parse(cboSpecType.SelectedItem.Value) == (int)Constants.SpecType.Multican)
							{
								CCFSpreadsheet cs = new CCFSpreadsheet(copiedFileName);
								importDS = cs.Import(message, error);
							}
							else
							{
								EUCDSpreadsheet es = new EUCDSpreadsheet(copiedFileName);
								importDS = es.Import(message, error);
							}
							ParamSpec spec = new ParamSpec();
							spec.Fill(ref importDS, int.Parse(cboSpecType.SelectedItem.Value), ref importMessage);
							RenderTable(ref spec);
							Session["spec"] = spec;
							// Delete the file from the server
							DeleteFile(copiedFileName);
							// Show/hide various buttons
							tblImport.Visible = false;
							btnUpload1.Visible = true;
							btnUpload2.Visible = true;
							// Load the title control
							TitleControl ctlTitle = (TitleControl) LoadControl(Constants.TitleControl);
							ctlTitle.TitleText = "Import Review";
							plcTitle.Controls.Add(ctlTitle);
							lblWarning.Text = importMessage;

						}
						catch (System.Exception exception)
						{
							//Generate error and redirect
							Context.Items.Add("errorMessage", exception.Message);
							Context.Server.Transfer("~/Error.aspx");
						}
						break;
					case "text/plain" :
					{
						// No import for text files implemented yet
						Context.Items.Add("errorMessage", "Cannot Import.  Text import not yet available!");
						Context.Server.Transfer("~/Error.aspx");
						break;
					}
					default :
					{
						// File is invalid, raise an error
						Context.Items.Add("errorMessage", "Cannot Import.  Import file format invalid!");
						Context.Server.Transfer("~/Error.aspx");
						break;
					}
				}
			}
		}
コード例 #2
0
ファイル: SpecImport.aspx.cs プロジェクト: demonzhq/JLR
		/// <summary>
		/// Display Config results in a table
		/// </summary>
		private void RenderTable(ref ParamSpec spec)
		{
			string param;
			string rowCss = "";
			int paramCells = 3;
			string lastOptionGroup;

			int rowNo = 1;
			int optionCount; string optionCss; string optionGroup;
			int o;

			int optionVal; string optionValString;

			RenderHeader();
			DataView oView = spec.ss.Options.DefaultView;
			for(int i=0;i<spec.ss.Parameters.Rows.Count;i++)
			{
				DataRow row = spec.ss.Parameters.Rows[i];
				param = row["fldParameter"].ToString();

				rowCss = "mainrow"+rowNo;
				//				paramGroupId = Convert.ToInt32(row["fldGroup"]);

				// Create new row and add it to the table.
				TableRow tRow = new TableRow();
				tRow.CssClass = rowCss;
				tRow.BorderStyle = BorderStyle.Solid;
				tblList.Rows.Add(tRow);

				// Create new cells and add to the row.
				TableCell tCell = new TableCell();
				tCell.Text = row["fldFrame"].ToString();
				tRow.Cells.Add(tCell);

				tCell = new TableCell();
				tCell.Text = row["fldParameter"].ToString();
				tRow.Cells.Add(tCell);

				tCell = new TableCell();
				tCell.Text = row["fldName"].ToString();
				tRow.Cells.Add(tCell);

				optionCount = 1;
				lastOptionGroup = "";
				oView.RowFilter = "fldParameter = " + param.ToString();
				for (o=0;o<oView.Count;o++)
				{
					if (optionCount != 1)
					{
						// Create new row and add it to the table.
						tRow = new TableRow();
						tRow.CssClass = rowCss;
						tblList.Rows.Add(tRow);

						for (int c=1; c<=paramCells;c++)
						{
							// Tab the cells across to the correct place
							tCell = new TableCell();
							tCell.Text = "";
							tRow.Cells.Add(tCell);
						}
					}

					optionCss = Common.GetRowClass(rowNo, Convert.ToInt16(oView[o]["fldSplit"]));

					optionGroup = oView[o]["fldSplit"].ToString();
					// Create cells and add

					// Option Group
					tCell = new TableCell();
					if (optionGroup != lastOptionGroup)
					{
						tCell.Text = optionGroup;
					}
					tCell.CssClass = optionCss;
					tRow.Cells.Add(tCell);

					// Show the imported option value (convert from int to hex string)
					try
					{
						optionVal = Convert.ToInt32(oView[o]["fldValue"]);
						optionValString = "0x"+optionVal.ToString("X2");
					}
					catch
					{
						optionValString = oView[o]["fldValue"].ToString();
					}
					// Show the value
					tCell = new TableCell();
					tCell.Text = optionValString;
					tCell.CssClass = optionCss;
					tRow.Cells.Add(tCell);

					tCell = new TableCell();
					tCell.Text = oView[o]["fldDescription"].ToString();
					if (oView[o]["fldSubDesc"].ToString() != "") tCell.Text += " (" + oView[o]["fldSubDesc"].ToString() + ")";
					tCell.CssClass = optionCss;
					tRow.Cells.Add(tCell);

					tCell = new TableCell();
					tCell.Text = oView[o]["fldType"].ToString();
					tCell.CssClass = optionCss;
					tRow.Cells.Add(tCell);

					//					tCell = new TableCell();
					//					tCell.Text = optionRow["fldBitLength"].ToString();
					//					tCell.CssClass = optionCss;
					//					tRow.Cells.Add(tCell);

					tCell = new TableCell();
					tCell.Text = oView[o]["fldMask"].ToString();
					tCell.CssClass = optionCss;
					tRow.Cells.Add(tCell);

					tCell = new TableCell();
					tCell.Text = oView[o]["fldFormat"].ToString();
					tCell.CssClass = optionCss;
					tRow.Cells.Add(tCell);

					tCell = new TableCell();
					if (Convert.ToBoolean( oView[o]["fldError"]))
					{
						tCell.CssClass = "cellRed";
					}
					else
					{
						tCell.CssClass = "cellGreen";
					}
					tRow.Cells.Add(tCell);

					lastOptionGroup = optionGroup;
					optionCount++;

				}

			}
		}