Search This Blog

Batch file to create oracle dump automatically in windows

Create a .bat file in windows and write the following lines in it.


set DateStamp=%date:~-4,4%%date:~4,2%%date:~7,2%
set file_dump=fulldb_%DateStamp%.dmp
set file_log=log_%DateStamp%.log
set backup_folder=D:\autobackup
exp schema/password@localhost:1521/db19c owner=schema1 file=%backup_folder%\%file_dump% log=%backup_folder%\%file_log%


Moreover we can use windows task scheduler to run this bat file automatically and repeatedly

Serenity Using SERGEN generated Grid in a Dialog

Suppose we generated code using SERGEN for 2 tables (Region,Territories) of NorthWind Sample DataBase. DDL Statements of these tables are
		CREATE TABLE region (
region_id smallint NOT NULL PRIMARY KEY,
region_description bpchar NOT NULL
);
CREATE TABLE territories (
territory_id character varying(20) NOT NULL PRIMARY KEY,
territory_description bpchar NOT NULL,
region_id smallint NOT NULL,
FOREIGN KEY (region_id) REFERENCES region
);


Create following function in file TerritoriesGrid.ts

        public set_Filter(value: string): void {
            //We created the QuickFilter on TerritoriesRow.Fields.RegionDescription in 
            //file TerritoriesRow.cs using [QuickFilter] attribute
            //We are just setting that QuickFilter with below statement		
            this.findQuickFilter(Serenity.StringEditor,
                TerritoriesRow.Fields.RegionDescription).value = value;
        }
Add the grid property in RegionDialog.ts file.

	private myGrid: TerritoriesGrid;
Create following function in RegionDialog.ts file.

	protected afterLoadEntity() {
            super.afterLoadEntity();
            $('.s-DialogContent').append('<div id="MyGrid"></div>');
            this.myGrid = new TerritoriesGrid($('#MyGrid'));
            this.myGrid.set_Filter(this.entity.Regiondescription);
            this.myGrid.refresh();
        }
Furthermore, we can remove buttons,toolbars and columns or fields from TerritoriesGrid and RegionDialog as per our requirement.


Serenity Make The Dialog Maximizable

Add the following attributes above the dialog class in classDialog.ts file.

    @Serenity.Decorators.resizable()
   @Serenity.Decorators.maximizable()

We can add the following function in classDialog.ts file to make the dialog maximized by default.

        protected onDialogOpen() 
        {            
                $(".ui-dialog-titlebar-maximize").click();
                super.onDialogOpen();            
        }


Serenity Date Input Formatter for Inline Editing in Grids

Inline editing in grids is not recommended in Serenity by its owner. However he demonstrated serenity inline editing in an example with some warnings. There is no date input formatter in this example. We may use the following date input formatter and call this formatter from getColumns function in grid file.

private dateInputFormatter(ctx) {
            var klass = 'edit s-DateEditor';
            var item = ctx.item as StockVerificationDetailRow;
            var pending = this.pendingChanges[item.RecId];
            var column = ctx.column as Slick.Column;

            if (pending && pending[column.field] !== undefined) {
                klass += ' dirty';
            }

            var value;
            if (item[column.field] == null)
                value = item[column.field];
            else
                value = Q.parseDate(item[column.field]).toLocaleDateString();

            return "<input type='text' class='" + klass +
                "' data-field='" + column.field +
                "' value='" + value +
                "' maxlength='" + column.sourceItem.maxLength + "' />" +
                "<script>$('.s-DateEditor').datepicker(); </script>" +
                "<script>$('.s-DateEditor').each(function(){    var value = $(this).val();   var size = value.length;   size = size * 4;       $(this).css('width', size * 3);        });       </script>" +
                "<script>$('.ui-datepicker-trigger').css({'padding-bottom': '4px','height': '24px'}); </script>";
        }
And the following date input inline formatter is working for html 5 datepicker.
private dateInputFormatter(ctx) {
            var klass = 'edit';
            var item = ctx.item as AgentsRow;
            var pending = this.pendingChanges[item.AgentCode];
            var column = ctx.column as Slick.Column;

            if (pending && pending[column.field] !== undefined) {
                klass += ' dirty';
            }

         
            var value;
            if (item[column.field] == null)
                value = item[column.field];
            else
                value = Q.parseDate(item[column.field]).toLocaleDateString();  

            return "<input type='date' class='" + klass +
                "' data-field='" + column.field +
                "' value='" + value +               
                "' maxlength='" + column.sourceItem.maxLength + "'/>";
        }

Create Custom QuickFilter which selects distinct values of same table/view columns

We created a file MyTableClassLookup.cs for custom lookup. And change some fields name according to your requirement.
using ERP.MyModule.Entities;
using Serenity.ComponentModel;
using Serenity.Data;
using Serenity.Web;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
namespace ERP.MyModule
{
[LookupScript("MyModule.CustomLookup", Expiration = -1, Permission = "*")]
public class MyTableClassLookup : RowLookupScript<MyTableClassRow>
{
public MyTableClassLookup()
{
IdField = TextField = "Unit"; //where Unit is property in MyTableClassRow class
}

protected override void PrepareQuery(SqlQuery query)
{
var fld = MyTableClassRow.Fields;


query
.Distinct(true)
.Select(fld.Unit)
.Where(fld.Unit.IsNotNull());

}

protected override void ApplyOrder(SqlQuery query)
{
}

}
}
We add the attribue [LookupEditor(typeof(MyTableClassLookup))] in MyTableClassRow class for property unit.

Serenity Site Navigation Changes

site navigation files

Project_name.Web/Modules/yourModule/yourModuleNavigation.cs
Project_name.Web/Modules/Common/Navigation/NavigationItems.cs.

attribute for navigation

auto generated modules are displayed at the bottom of navigation menu. Navigation items are created with special assembly attributes 

[assembly: NavigationLink(int order, string path, Type controller, string icon = null, string action = "Index")]

e.g.
[assembly: NavigationLink(int.MaxValue, "ERP/Store", typeof(MyPages.StoreController), icon: null)]

first parameter is display order for this navigation item. 


second parameter is navigation title in "Section Title/Link Title" format. We can edit these.

third parameter is type controller, this is linked with our 

[assembly: NavigationMenu(int.MaxValue, "Store/Catalog", icon: "fa-folder-open-o")]

Serentiy Using Grid as an EditorType

Suppose we have 3 tables in DB.
1) Bill (Bill_id, Bill_Number)
2) Item (Item_id, Item_Name)
3) Bill_items (bill_items_id, bill_id,item_id, item_quantity )

and bill_id and item_id are foreign keys in table Bill_items

Generate Code using Sergen for every table in same module i.e. "Store".

Create a file named Modules/Store/BillItems/BillItemsEditor.ts with contents below

/// <reference path="../../Common/Helpers/GridEditorBase.ts" />
  namespace ERP.Store {
@Serenity.Decorators.registerEditor()
export class BillItemsEditor 
  extends Common.GridEditorBase<BillItemsRow> {
protected getColumnsKey() { return "Store.BillItems"; }
protected getDialogType() { return BillItemsEditDialog; } //We are linking our custom dialog here
protected getLocalTextPrefix() { return BillItemsRow.localTextPrefix; }
constructor(container: JQuery) {
super(container);
}

protected getAddButtonCaption() {
return "Add"; // this will rename the "New billItems" button
}
}
}


Note. We cannot bind SERGEN generated dialogs otherwise we will have issues in saving forms etc.

Create a file named Modules/Store/BillItems/BillItemsEditDialog.ts with contents below


/// <reference path="../../Common/Helpers/GridEditorDialog.ts" />
  namespace ERP.Store {
@Serenity.Decorators.registerClass()
export class BillItemsEditDialog extends 
  Common.GridEditorDialog<BillItemsRow> {
protected getFormKey() { return BillItemsForm.formKey; }
//protected getNameProperty() { return BillItemsRow.nameProperty; }
protected getLocalTextPrefix() { return BillItemsRow.localTextPrefix; }
protected form: BillItemsForm;
constructor() {
super();
this.form = new BillItemsForm(this.idPrefix);
}
}
}

Add the following field in BillForm.cs file.
  [BillItemsEditor, IgnoreName]
  public List<Entities.BillItemsRow> ItemList { get; set; }
Also the following in BillRow.cs in class BillRow
        [NotMapped]        
        public System.Collections.Generic.List<Entities.BillItemsRow> ItemList {
            get { return Fields.ItemList[this]; }
            set { Fields.ItemList[this] = value; }
        }

Also the following in BillRow.cs in class RowFields
public ListField<Entities.BillItemsRow> ItemList;

After the above mentioned steps, we will be able to see Grid in Bill Form or dialog.


Remove unnecessay Field i.e. billId from BillItemsForm.cs file. This field will be automatically taken from BillForm.

Remove unnecessay column i.e. BillItemsId,BillNumber from BillItemsColumns.cs file. These fields will not be shown in grid. 

Add the below code in file BillItemsEditor.ts to get values of colmuns 

protected validateEntity(row: BillItemsRow, id: number) {
if (!super.validateEntity(row, id))
return false;


row.ItemName = ItemRow.getLookup()  //edit this 
.itemById[row.ItemId].Name;


return true;
}

Add this attribute in BillRow.cs to ItemList field for save, retrive, update and deleting of records.
[MasterDetailRelation(foreignKey: "BillId", IncludeColumns = "ItemName")]

here the foreignKey, IncludeColumns values must be in billItemsRow.cs file.

We can include multiple columns as below from billItemsRow


[MasterDetailRelation(foreignKey: "BillId", IncludeColumns = "ItemName1,ItemName2")]
Web Statistics