One line of code completes addition, deletion, modification, and query of Custom forms, and online form redesign requires no code writing

Source: Internet
Author: User

Recently, I was discussing with my friends the problem of customizing forms in the workflow system. These forms are used for data processing on process nodes. For example, designing a ticket in the leave process. To make the workflow highly flexible, you often need to customize the form for the customer. There are two ways to deal with this problem: programmers customize the development form for a customer, and customers design the form online. Obviously, the implementation cost of method 1 is high, and the development cost of method 2 is high, but the use cost is low. However, for software companies, once method 2 is used to develop a workflow system, it is very convenient for later implementation and customer use. Therefore, many workflow systems provide a "Form Designer ", to design workflow forms online. From another perspective, let's look at the differences between method 1 and method 2. We find that their differences are: method 1, which requires development, compilation, and deployment of programs; method 2, which does not require re-Compilation of programs; method 2 has obvious advantages, but it must first develop a "Form Designer". These designers are simple, complex, and complex. Take a closer look, the more you see the WinForm and WebForm design interfaces of VS, the design window, toolbar, and attribute window are available. So in my opinion, VS is the best Form Designer ". In the early stage of the system, it is good to use VS to design the basic interface of the form. For specific customers, it is to adjust the form style and modify the form field (it is common to add several new fields. At this time, it would be great if such adjustments can be used out of the VS development environment. I have been thinking about this for a long time. I found that most simple forms are used for data input, viewing, and modification, and there is not much logic. So for such requirements, we can bind the form control directly to the table fields of the database for rapid development. The WinForm \ WebForm controls of VS can be used in this way, but they need to be bound to a Typed DataSet (a strongly Typed DataSet) in advance, and this process is not easy to use. Because datasets are required, so it is impossible not to compile the program. We can change our mindset. If a form can automatically collect and populate the data in the form field, will it be automatically bound to the database? This function is a PDF file. NET Smart form controls are provided by the IDataControl interface, which defines the ing between controls and databases and object classes: [csharp] IDataControl /// <summary> // data ing control interface /// </summary> public interface IDataControl {/// <summary> // data item with the database associated data // </summary> string LinkProperty {get; set ;}//< summary> /// name of the table associated with the data /// </summary> string LinkObject {get; set ;} /// <summary> /// whether to verify by server the default value is true /// </summary> bool IsValid {get;} // <summary >/// Data type /// </summary> TypeCode policypecode {get; set ;} /// <summary> /// read-only mark /// </summary> bool ReadOnly {get; set ;} /// <summary> /// whether null values are allowed /// </summary> bool isNull {get; // set ;} /// <summary> /// whether it is a primary key /// </summary> bool PrimaryKey {get; set ;} /// <summary> /// set the value /// </summary> /// <param name = "obj"> </param> void SetValue (object value ); /// <summary> /// obtain the value /// </summary>/ // <Returns> </returns> object GetValue (); /// <summary> /// server verification /// </summary> /// <returns> </returns> bool Validate ();} In this interface, there are two important attributes: LinkObject: the name of the data table or object type related to the database LinkProperty: the attribute of the field or object class associated with the database data table. We will use common form controls: checkBox, DropDownList, Label, ListBox, RadioButton, and TextBox all inherit the IDataControl interface, so they can process data, such as loading data and obtaining data, it is automatically implemented through the form data collection and filling methods of the framework: [csharp] /// <summary> /// collect intelligent controls in the form, can be directly used for database insertion and The newly queried SQL statement // a form can simultaneously process data operations on multiple tables. // if the data attribute of the control is set to read-only, the value of the control is not updated to the database. If the data attribute of the control is set as the primary key, then the update statement will include the condition /// </summary> /// <returns> /// the members in the ArrayList are IBCommand objects, including specific crud SQL // </returns> public static List <IBCommand> GetIBFormData (ControlCollection Controls, CommonDB) based on this method, how to update and fill in form data: [csharp] /// <summary> /// automatically update the form data /// </summary> /// <param name = "Controls"> control set </param> /// <returns> </Returns> public List <IBCommand> AutoUpdateIBFormData (ControlCollection Controls ); /// <summary> /// automatically fill in the data of the smart form control /// </summary> /// <param name = "Controls"> the form control set to be filled in </param> public void AutoSelectIBForm (ControlCollection Controls ); OK. With these two methods, we can implement "update a form with one line of code! [Csharp] // Save the data List <IBCommand> ibCommandList = MyWebForm. instance. autoUpdateIBFormData (this. controls); // enter the data MyWebForm. instance. autoSelectIBForm (this. controls), but this is not the topic of this article. This article describes how to modify the form online without re-compiling the program. We use examples to illustrate this process: 1. First, go to PDF. NET open source project website to download a "supermarket management system" example program, 2, according to the instructions of the website, local configuration of Good Luck line environment, basically is to create a database, run the table creation script to compile and publish the script to an IIS Site. 3. Run the "supermarket management system" website and log on as an administrator (for details about the account, see the website Source Code) to perform operations such as employee management and device management and set basic data for the system. Steps 1, 2 and 3 can be omitted. You can directly log on to the website of the supermarket management system instance (http: // 221.123.142.196 ). 4. On the device management page, you will see: [design interface] [runtime] 5. Find the file GoodsManage \ StockInfo at the supermarket website in your local IIS. aspx, then add the following HTML code to the form, and add a "handled by" data control. In addition, the grid control and paging control also add the handled by information: [Figure] [HTML code] [html] ASPX <% @ Page Title = "" Language = "C #" MasterPageFile = "~ /Site1.Master "AutoEventWireup =" true "CodeBehind =" StockInfo. aspx. cs "Inherits =" SuperMarketWeb. goodsManage. stockInfo "%> <% @ Register assembly =" PWMIS. web "namespace =" PWMIS. web. <asp: Content ID = "Content1" ContentPlaceHolderID = "head" runat = "server"> <style type = "text/css">. style4 {height: 26px ;}</style> </asp: Content> <asp: Content ID = "Content2" ContentPlaceHolderID = "Con TentPlaceHolder1 "runat =" server "> <table style =" background-color: # DEBA84; border-color: # DEBA84; border-width: 1px; border-style: None; "id =" tbGoosBaseInfo "runat =" server "> <tr style =" color: #8C4510; background-color: # FFF7E7; "> <td> [inventory record number] * </td> <PC3: dataLabel ID = "dlCHJLH" runat = "server" DataFormatString = "" isNull = "True" LinkObject = "inventory info table" LinkProperty = "inventory record number" PrimaryKey = "True" ReadOnly = "True" Y PeCode = "Int32"> </PC3: DataLabel> </td> </tr> <tr style = "color: #8C4510; background-color: # FFF7E7; "> <td> [product name] </td> <PC3: dataDropDownList ID = "ddlGoodsNames" runat = "server" LinkObject = "" LinkProperty = "" yypecode = "String" AutoPostBack = "True" onselectedindexchanged = "success"> </C0: dataDropDownList> </td> </tr> <tr style = "color: #8C4510; background-color: # FFF7E7;"> <td cl Ass = "style4"> [Vendor] </td> <td class = "style4"> <PC3: dataDropDownList ID = "ddlManufacturer" runat = "server" LinkObject = "" LinkProperty = "" yypecode = "String"> <asp: listItem Selected = "True"> select </asp: ListItem> </105: DataDropDownList> <105: dataTextBox ID = "dtbSN" runat = "server" LinkObject = "inventory info table" LinkProperty = "barcode" yypecode = "String" Width = "78px" Type = "Currency" Visible = "False"> </PC3: dataTextBox> </td> </ Tr> <tr style = "color: #8C4510; background-color: # FFF7E7;"> <td> [price] </td> <PC3: dataTextBox ID = "DataTextBox3" runat = "server" LinkObject = "inventory info table" LinkProperty = "ypecode =" Decimal "Width =" 128px "Type =" Currency "OftenType =" floating Point Number "> </PC3: dataTextBox> </td> </tr> <tr style = "color: #8C4510; background-color: # FFF7E7; "> <td> [cost price] </td> <PC3: DataTextBox ID =" DataTextBox4 "runat =" server "LinkObject =" inventory letter Information table "LinkProperty =" cost price "SysTypeCode =" Decimal "width =" 128px "OftenType =" floating point number "> </105: dataTextBox> </td> </tr> <tr style = "color: #8C4510; background-color: # FFF7E7; "> <td> [date of production] </td> <PC3: dataCalendar ID = "DataCalendar3" runat = "server" LinkObject = "inventory info table" LinkProperty = "production date" ScriptPath = ".. /Calendar/"ReadOnly =" False "/> </td> </tr> <tr style =" color: #8C4510; background-color: # FFF7E7; "> <td> [import time] </td> <td> <PC3: DataCalendar ID = "DataCalendar2" runat = "server" LinkObject = "inventory info table" LinkProperty = "shipping time" ScriptPath = ".. /Calendar/"ReadOnly =" False "/> </td> </tr> <tr style =" color: #8C4510; background-color: # FFF7E7; "> <td> [inventory quantity] </td> <PC3: dataTextBox ID = "DataTextBox6" runat = "server" LinkObject = "inventory info table" LinkProperty = "inventory quantity" yypecode = "Int32" Type = "Integer" OftenType = "Integer"> </PC3: dataTextBox> </td> </tr> <tr styl E = "color: #8C4510; background-color: # FFF7E7;"> <td> </td> <asp: button ID = "btnSave" runat = "server" onclick = "btnSave_Click" Text = "save"/> <asp: button ID = "btnNew" runat = "server" onclick = "btnNew_Click" Text = "new"/> <asp: button ID = "btnDelete" runat = "server" onclick = "btnDelete_Click" Text = "delete"/> </td> </tr> </table> <p> <asp: label ID = "lblMsg" runat = "server" Text = ""> </asp: Label> </p> <asp: GridView I D = "GridView1" runat = "server" BackColor = "# DEBA84" BorderColor = "# DEBA84" BorderStyle = "None" BorderWidth = "1px" CellPadding = "3" CellSpacing =" 2 "onselectedindexchanged =" regular "> <RowStyle BackColor =" # FFF7E7 "ForeColor =" #8C4510 "/> <FooterStyle BackColor =" # F7DFB5 "ForeColor =" #8C4510 "/> <PagerStyle ForeColor = "#8C4510" HorizontalAlign = "Center"/> <SelectedRowStyle BackColor = "# 738A 9C "Font-Bold =" True "ForeColor =" White "/> <HeaderStyle BackColor =" # A55129 "Font-Bold =" True "ForeColor =" White "/> <Columns> <asp: buttonField CommandName = "Select" HeaderText = "Select" ShowHeader = "True" Text = "edit"/> </Columns> </asp: GridView> <cached: proPageToolBar ID = "ProPageToolBar1" runat = "server" BackColor = "# FFF7E7" BorderColor = "# DEBA84" BorderWidth = "1px" ForeColor = "#8C4510" PageSize = = "Tr Ue "AutoConfig =" True "AutoIDB =" True "BindToControl =" GridView1 "SQL =" SELECT [inventory record number], [barcode number], [price], [cost price], [production date], [import time], [inventory quantity] FROM [inventory info table] order by [inventory record number] desc "/> </asp: content> Save the changes to the page. 6. Add a "operator" field in the "inventory info table" of your database, which is of the string type and has a length of 50. 7. Refresh the webpage again. Is there an additional "handled person" information on the form interface? The result is as follows: is it successful to add or modify data in the form? 8. It's over. Haha, does this method enable your "online form modification without recompilation" function? If you develop a tool that allows users to modify form information in a graphical manner, it is a real online form modification tool. PS: PDF. NET's single data table feature is the earliest feature of the framework, but now popular MVC development, WebForm development does not seem to be popular, but I think there is still much to do in the enterprise development field, or, this article at least provides you with a solution to solve such problems, hoping to help you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.