Learn Extjs5 with me (40--add a custom module [1 Build table and Bean file])

Source: Internet
Author: User

Learn Extjs5 with me (40--add a custom module [1 Build table and Bean file])
With the above work, a crud for a standalone module is ready to run, and to better see other custom functions, we make a custom standalone module that includes various data types.        Added a "Sales contract" of the standalone module, the module name is agreement, which includes 20 fields, the main field types are set, String type, integer, floating point, Amount, date, Boolean, percentage, also includes the calculated field. The SQL statement that establishes the 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] (a) COLLATE chinese_prc_ci_as not null,[tf_name] [nvarchar] (50) COLLATE chinese_prc_ci_as not null,[tf_customernme] [nvarchar] (a) COLLATE chinese_prc_ci_as not null,[tf_orderid] [int ] null,[tf_signdate] [datetime] not null,[tf_productname] [nvarchar] (a) COLLATE chinese_prc_ci_as not null,[tf_ Salesman] [nchar] (TEN) COLLATE chinese_prc_ci_as not Null,[tf_number] [int.] not null,[tf_alllength] [money] Null,[tf_ UnitPrice] [money] not null,[tf_unittext] [nvarchar] (Ten) COLLATE chinese_prc_ci_as Null,[tf_discount] [money] not NULL CO Nstraint [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_agreeme Nt_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]

First build the user's own bean package app under Com.jfok.server.hibernate, and then build the Java Bean file Agreement.java file,
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 for demonstrating all the custom properties of a single module * * @author JFOK * * 2014.10.16 * * * * @SuppressWarnings ("serial") @Entity @org.hibernate.annota tions. Entity (DynamicUpdate = True) @TableDefine (group = "Contract Management", id =, title = "Sales Contract") public class agreement implements Seria lizable {@Id @generatedvalue (generator = "increment") @GenericGenerator (name = "Increment", strategy = "increment") @  Fielddefine (title = "id", Number = ten, Hidden = true) private Integer Tf_agreementid; @FieldDefine (title = "Contract Code", Number = @Column (nullable = false, length =) Private String tf_code;//This field is the Namefields field of this module, You will be prompted to display the information for this field when you delete such actions @fielddefine (title = "Contract name ", NameField = true, Number = a) @Column (length =, nullable = False) private String tf_name;//because it is a monologue module, does not do the corresponding customer unit, The product name of the table to associate @fielddefine (title = "Customer Unit name", Number = +) @Column (length = $, nullable = False) Private String tf_customernme;@f  Ielddefine (title = "Ordinal", number =) Private Integer Tf_orderid, @FieldDefine (title = "Date Entered", Number =) @Column (nullable = False) private Date tf_signdate; @FieldDefine (title = "Product Name", Number = $) @Column (length = nullable = False) Private S Tring Tf_productname; @FieldDefine (title = "Salesperson", Number = N) @Column (length = ten, Nullable = False) Private String Tf_sales  Man; @FieldDefine (title = "Quantity", Number = SUM) @Column (nullable = False) private Integer Tf_number; @FieldDefine (title = "Total Length", Number = +) private double tf_alllength; @FieldDefine (title = "Unit Price", number = a, Money = true) Private double tf_unitpric e; @FieldDefine (title = "Unit of measure", Number = +) @Column (length = ten) 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 = $, Money = true, Remark = "Total Amount =  Volume * 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 = "Proportional", number = percent, = true, Remark = "scaled = Received Amount/Total Amount ") @Column (updatable = false, Insertable = False) private Double tf_receivedpercent; @FieldDefine (title =" Done ", Number = () private Boolean tf_finished; @FieldDefine (title = "Important", Number = Tf_isimportant) Private Boolean; @FieldD Efine (title = "Start Time", number = zero) private date tf_begindate; @FieldDefine (title = "End Time", Number = $) Private Date Tf_end Date, @FieldDefine (title = "Remark", Number = 290) Private String Tf_remark;public agreement () {}//getter and setter}
In the Hibernate.cfg.xml file, add
<!--contract management--><mapping class= "Com.jfok.server.hibernate.app.Agreement"/>



According to the final design goal of my system, add a module just do the above two steps on the line, then we come to concrete implementation of the process.The first step: Perform functions in the foreground, automatically generate records in _module,_modulefield based on annotations on agreement and annotations on individual fields, and generate a default list scheme and a form scheme.
We did this before, but we entered an address in the browser, and now we move the function to the foreground. Add a button to the Top.js toolbar and place it behind "search" to enter the module name and 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 add: ', function (btn, text) {if (btn = = ' OK ') {E Xt.  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/><br/> ' + response.responsetext,buttons: Ext.messagebox.ok,icon:ext.messagebox.error}); else {ext.toastinfo (' Add module ', ' module: ' + text+ ' definition and grid,form definition has been added to the system! ');}} , Failure:function () {window.alert (text + ' save failed! ')}})}})}}

It is now possible to import agreement information.
Once determined, the following prompt will appear if the import is successful:


Programs in the background are imported according to the module name. Data for _module tables

_modulefield's data



Learn Extjs5 with me (40--add a custom module [1 Build table and Bean file])

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.