Learn extjs5 with me (40 -- add a custom module [1 create a table and bean file]), extjs540 --

Source: Internet
Author: User

Learn extjs5 with me (40 -- add a custom module [1 create a table and bean file]), extjs540 --
Learn extjs5 with me (40 -- add a custom module [1 create a table and bean file])
After the above work, CRUD of an independent module can be run. To better see other custom functions, we create a custom independent module, this module includes various data types. Add an independent "Sales Contract" module named Agreement, which contains more than 20 fields and sets the main field types, including string, integer, and floating point, amount, date, Boolean, percentage, and calculation fields. The SQL statement for creating a table is as follows:

/***** Object: Table [dbo]. [Agreement] script Date: 10/16/2014 14:13:11 ******/create table [dbo]. [Agreement] ([tf_agreementId] [int] not null, [tf_code] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS not null, [tf_name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS not null, [tf_customerNme] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS not null, [tf_orderId] [int] NULL, [tf_signDate] [datetime] NOT NULL, [tf_productName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS not null, [tf_salesman] [nchar] (10) COLLATE Chinese_PRC_CI_AS not null, [tf_number] [int] not null, [tf_allLength] [money] NULL, [tf_unitPrice] [money] not null, [tf_unitText] [nvarchar] (10) COLLATE Chinese_PRC_CI_AS NULL, [tf_discount] [money] not null constraint [DF_Agreement_tf_discount] DEFAULT (1), [tf_amount] AS (round ([tf_number] * [tf_unitPrice]) * [tf_discount], (2), [tf_receivedPrice] [money] NULL, [tf_receivedPercent] AS (case when ([tf_number] * [tf_unitPrice]) * [tf_discount] <> (0) then [tf_receivedPrice]/round ([tf_number] * [tf_unitPrice]) * [tf_discount], (2) else (0) end), [tf_finished] [bit] NULL, [tf_isImportant] [bit] NULL, [tf_beginDate] [datetime] NULL, [tf_endDate] [datetime] NULL, [tf_remark] [nvarchar] (max) COLLATE Chinese_PRC_CI_AS NULL, CONSTRAINT [PK_Agreement] primary key clustered ([tf_agreementId] ASC) WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]) ON [PRIMARY] GO/***** object: index [IX_Agreement_tf_name] script Date: 10/16/2014 14:13:53 ******/create unique nonclustered index [IX_Agreement_tf_name] ON [dbo]. [Agreement] ([tf_name] ASC) WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]

Create your own bean package app under com. jfok. server. hibernate, and then create the java bean file Agreement. java,
Package com. jfok. server. hibernate. app; import java. io. serializable; import java. util. date; import javax. persistence. column; import javax. persistence. entity; import javax. persistence. generatedValue; import javax. persistence. id; import org. hibernate. annotations. genericGenerator; import com. jfok. server. common. annotation. fieldDefine; import com. jfok. server. common. annotation. tableDefine;/*** a class used to demonstrate all custom attributes of a single module ** @ author jfok ** 2014.10.16 **/@ SuppressWarnings ("serial ") @ Entity@org.hibernate.annotations.Entity (dynamicUpdate = true) @ TableDefine (group = "Contract Management", id = 2010, title = "Sales Contract ") public class Agreement implements Serializable {@ Id @ GeneratedValue (generator = "increment") @ GenericGenerator (name = "increment", strategy = "increment ") @ FieldDefine (title = "ID", number = 10, hidden = true) private Integer tf_agreementId; @ FieldDefine (title = "Contract Code", number = 20) @ Column (nullable = false, length = 20) private String tf_code; // This field is the namefields field of this module, the message @ FieldDefine (title = "contract name", nameField = true, number = 30) @ Column (length = 50, nullable = false) private String tf_name; // The table of the product name is associated with @ FieldDefine (title = "", number = 40) @ Column (length = 50, nullable = false) private String tf_customerNme; @ FieldDefine (title = "Sn", number = 50) private Integer tf_orderId; @ FieldDefine (title = "signing Date", number = 60) @ Column (nullable = false) private Date tf_signDate; @ FieldDefine (title = "Product Name", number = 70) @ Column (length = 50, nullable = false) private String tf_productName; @ FieldDefine (title = "salesman", number = 80) @ Column (length = 10, nullable = false) private String tf_salesman; @ FieldDefine (title = "quantity", number = 90) @ Column (nullable = false) private Integer tf_number; @ FieldDefine (title = "total length ", number = 100) private Double tf_allLength; @ FieldDefine (title = "unit price", number = 110, money = true) private Double tf_unitPrice; @ FieldDefine (title = "unit of measurement ", number = 120) @ Column (length = 10) private String tf_unitText; // The default discount is 1.00, that is, no discount @ FieldDefine (title = "discount", number = 130, percent = true) private Double tf_discount = 1.0; @ FieldDefine (title = "total amount", number = 140, money = true, remark = "total amount = Quantity * unit price * discount ") @ Column (updatable = false, insertable = false) private Double tf_amount; @ FieldDefine (title = "received amount", number = 150, money = true) private Double tf_receivedPrice; @ FieldDefine (title = "percentage received", number = 160, percent = true, remark = "percentage received = amount received/total amount") @ Column (updatable = false, insertable = false) private Double tf_receivedPercent; @ FieldDefine (title = "completed", number = 170) private Boolean tf_finished; @ FieldDefine (title = "important", number = 180) private Boolean tf_isImportant; @ FieldDefine (title = "Start time", number = 190) private Date tf_beginDate; @ FieldDefine (title = "End Time", number = 200) private Date tf_endDate; @ FieldDefine (title = "Remarks", number = 290) private String tf_remark; public Agreement () {}// getter and setter}
Add the following content to the hibernate. cfg. xml file:
<! -- Contract Management --> <mapping class = "com. jfok. server. hibernate. app. Agreement"/>



According to the final design goal of my system, we only need to add a module to do the above two steps. Then let's take a look at the specific implementation process. Step 1: Execute the function on the foreground, and automatically generate a record in _ Module, _ ModuleField according to the Annotation on Agreement and Annotation on each field, and generate a default list scheme and a form scheme.
We have also done this function before, but it is implemented by entering an address in the browser. Now we move this function to the front-end. Add a button to the toolbar of Top. js and put it behind "Search" to enter the module name. Then, add the module definition and field definition to each table.
{Text: 'import', handler: function () {Ext. messageBox. prompt ('add module ',' enter the Class Name of the module to be added: ', function (btn, text) {if (btn =' OK ') {Ext. ajax. request ({scope: this, url: 'systemframe/addmodule. do ', params: {moduleName: text}, success: function (response) {if (response. responseText) Ext. messageBox. show ({title: 'import failed', msg: 'import module failed <br/> '+ response. responseText, buttons: Ext. messageBox. OK, icon: Ext. message Box. ERROR}); else {Ext. toastInfo ('add module ', 'module:' + text + 'definition and grid. form definition is already in the add system! ') ;}}, Failure: function () {window. alert (text +' failed to save! ')}})}})}}

Now you can import the Agreement information.
If the import is successful, the following prompt is displayed:


The background program imports data according to the module name. _ Module table data

_ ModuleField data






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.