php表单元素,PHP_表单设计器—HTML元素操作,表单设计器界面图为:    - phpStudy...

本文介绍了如何在表单设计器中通过枚举EditorMode切换设计和编码模式,展示了axDHTMLEdit控件的使用以及如何在不同模式下插入和管理HTML元素。重点讲解了DocumentHTML属性、IHTMLSelectionObject和IHTMLTxtRange在模式切换中的作用。
摘要由CSDN通过智能技术生成

表单设计器—HTML元素操作

表单设计器界面图为:

查看原图(大图)

主编辑区域的TabControl分为设计模式和编码模式两个页,设计模式页包含dhtml edit control,实例名称为:axDHTMLEdit;编码模式页包含多行文本框,实例名称为:txtCode。可以在设计模式和编码模式之间进行切换,来展示不同内容,类似于Dreamweaver的功能。

为了标识着两种模式,定义枚举类型EditorMode:

/// 

/// 编辑器的模式

/// 

public enum EditorMode { Design, Code}

模式之间切换代码为:

if (tabControl.SelectedIndex ==(int)EditorMode.Code)

{

GlobalStatus.CurrentMode = EditorMode.Code;

txtCode.Text = axDHTMLEdit.DocumentHTML;

}

else if (tabControl.SelectedIndex ==(int)EditorMode.Design)

{

GlobalStatus.CurrentMode = EditorMode.Design;

axDHTMLEdit.DocumentHTML = txtCode.Text;

}

可以在空白面板区点击鼠标,然后点击工具中的按钮,即可在空白面板上增加相应的HTML控件。相应的代码为:

/// 

/// 插入控件的处理函数

/// 1.如果是设计模式

/// 1.1如果当前焦点在控件上,那么不允许插入

/// 1.2如果当前焦点不在控件上

/// 1.2.1如果插入之前需要预设信息,那么弹出属性窗口进行设置,然后插入控件信息

/// 1.2.2如果插入之前不需要预设信息,直接插入控件信息

/// 2.如果是编辑模式,直接插入控件信息

/// 

/// 

private void insertControl(string type)

{

//设计模式

if (GlobalStatus.CurrentMode == EditorMode.Design)

{

IHTMLSelectionObject range = axDHTMLEdit.DOM.selection;

if (range.type == RangeType.CONTROL)

{

MessageBox.Show(ErrorMessage.E_FOCUS_ON_CONTROL_CANNOT_ADD_CONTROL);

}

else

{

IHTMLTxtRange obj = (IHTMLTxtRange)range.createRange();

//判断是否需要预设信息

if(NeedShowPropertyForm(type))

{

//根据元素类型获取html对象,类型为:button,text,password,table,checkbox,radio等

IHTMLElement element = HtmlControlFactory.getHtmlElement(type,axDHTMLEdit);

//获取元素的属性窗口并显示,待用户设置属性信息后生成html增加到设计视图中

Form propForm = getPropertyForm(element);

DialogResult result= propForm.ShowDialog();

if (result == DialogResult.OK)

{

obj.pasteHTML(HtmlControlFactory.getHtmlElementString(element));

}

}

else

{

obj.pasteHTML(HtmlControlFactory.getHtmlElementString(type,axDHTMLEdit));

}

}

}

else

{

txtCode.Paste(HtmlControlFactory.getHtmlElementString(type,axDHTMLEdit));

}

}

/// 

/// 点击增加控件按钮后,是否需要弹出属性窗口进行初始化设置

/// 

/// 控件类型

/// 是:需要进行初始化设置;否:不需要进行初始化设置

private bool NeedShowPropertyForm(string type)

{

if (HtmlControlType.TABLE == type) return true;

return false;

}

/// 

/// HTML控件类型

/// 

public class HtmlControlType

{

public const string BUTTON = "button";

public const string CHECK_BOX_LIST = "checkboxlist";

public const string SELECT = "select";

public const string DATE_TIME = "datetime";

public const string PICTURE = "picture";

public const string TABLE = "table";

public const string CHECK_BOX = "checkbox";

public const string RADIO_BOX = "radio";

public const string PASSWORD = "password";

public const string HIDDEN = "hidden";

public const string TEXT = "text";

public const string INPUT = "input";

}

/// 

/// DHTML控件选中区域类型

/// 

public class RangeType

{

/// 

/// 选中控件

/// 

public const string CONTROL = "Control";

/// 

/// 未选中

/// 

public const string NONE = "None";

}

主要知识点:

axDHTMLEdit.DocumentHTML:将一段Html文档赋值给该属性,DHTMLEdit控件可以显示控件布局,即设计模式视图;同时也可以从该属性获取设计模式视图的HTML代码。

IHTMLSelectionObject 对象获取当前控件选中区域的类型,该对象可以通过axDHTMLEdit的DOM属性的selection属性获取。 IHTMLSelectionObject包含一个type属性,type的属性值有Control、Text、None三种分别代表选中控件,文本,未选中任何对象。

IHTMLTxtRange 对象,该对象表示与当前选中区域(selection)相关的文本域对象,可以通过、 range.createRange()来获取该对象。可以通过text、htmlText属性获取该区域中的文本字符串;或者通过 pasteHTML(string)方法将一段HTML文本字符串添加到当前选中的文本区域中,再设计模式下向编辑区增加控件即是通过该方法完成的。

IHTMLElement类型是HTML控件的基类型,通过属性outerHTML可以获取对象的HTML内容相关阅读:

在Linux环境下安装JSP

对于访问IIS元数据库失败的解决

第6课:学习更多元素

Windows7操作系统无法玩魔兽3的问题

不支持fsockopen但支持culr环境下下ucenter与modoer通讯问题

掌握XML实例演练ASP+XML编程

B/S开发中常用javaScript技术与代码

Oracle的dual虚拟表介绍

php引用地址改变变量值的问题

简洁的一个实现网页全屏代码

不用组件实现Ajax效果

关于分页查询和性能问题

php5 mysql分页实例代码

php 各种应用乱码问题的解决方法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<?php // 连接数据库 $conn = mysqli_connect("localhost", "tms", "123456", "nut"); // 检查连接是否成功 if (!$conn) { die("数据库连接失败: " . mysqli_connect_error()); }echo "111"; // 处理表单提交 if ($_SERVER["REQUEST_METHOD"] == "POST") { // 获取表单数据 $aoiStep = $_POST['aoi_step']; $defectType = $_POST['defect_type']; $layerCode = $_POST['layer_code']; $type = $_POST['type']; $dpet = $_POST['dpet']; $subcode = $_POST['subcode']; $codeDescription = $_POST['code_description']; $determinationRule = $_POST['determination_rule']; $imagePaths = []; // 存储图片路径的数组 // 处理上传的图片 for ($i = 1; $i <= 5; $i++) { $imageField = "image" . $i; $targetDir = "D:/phpstudy_pro/WWW/192.168.1.16/images"; // 设置上传目录的路径 $fileName = uniqid() . '_' . $_FILES[$imageField]["name"]; // 生成唯一文件名 $targetFile = $targetDir . '/' . basename($fileName); // 将反斜杠替换为正斜杠 $targetFile = str_replace('\', '/', $targetFile); if (isset($_FILES[$imageField]) && $_FILES[$imageField]["error"] == UPLOAD_ERR_OK && move_uploaded_file($_FILES[$imageField]["tmp_name"], $targetFile)) { $imagePath = $targetFile; } else { $imagePath = ""; } $imagePaths[] = $imagePath; } // 其他图片的处理代码,类似上面的处理方式 $stmt = $conn->prepare("INSERT INTO tms (aoi_step, defect_type, layer_code, type, dpet, subcode, code_description, image1_path, image2_path, image3_path, image4_path, image5_path, determination_rule) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); if (!$stmt) { die("预处理失败: " . $conn->error); } $stmt->bind_param("sssssssssssss", $aoiStep, $defectType, $layerCode, $type, $dpet, $subcode, $codeDescription, $imagePaths[0], $imagePaths[1], $imagePaths[2], $imagePaths[3], $imagePaths[4], $determinationRule); if ($stmt->execute()) { echo "数据插入成功"; } else { echo "数据插入失败: " . $stmt->error; } // 关闭数据库连接 mysqli_close($conn); } ?>在这个代码中,当我有多行数据时,只会上传最后一条,我需要怎么修改,才能将所有编辑的数据都进行上传
最新发布
07-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值