h1

Oracle basics

April 16, 2009

 

schema

 

Create foreign key

ALTER TABLE Schema.CONTRACT ADD
   CONSTRAINT FK_CONTRACT_PRODUCT
   FOREIGN KEY (PRODUCT_CODE)
   REFERENCES Schema.C_PRODUCT (PRODUCT_CODE)

Adding Grant to user

grant

select on C_PRODUCT to XXXACC

Must be called from XXX_DATA user, or other user which has privilagies to grant rules.

grant [select, update, delete,insert]  on C_PRODUCT to XXXACC

 

Create Sequence

create

sequence seq01 INCREMENT BY 1 MINVALUE 0 MAXVALUE 99999 START WITH 0;

 

Create Identity in Oracle 9i

First at all, create Sequence:

CREATE SEQUENCE seq01 INCREMENT BY 1 MINVALUE 0 MAXVALUE 99999 START WITH 0;

then you must create trigger, which gets new ID from sequence and than it fill Id attribute of new record before inserting.

CREATE

OR REPLACE TRIGGER [Schema].tg_bi_test
BEFORE
INSERT
ON [SCHEMA].SEQUENCEDTABLE

REFERENCING NEW AS New OLD AS
Old
FOR
EACH
ROW
DECLARE
tmpVar NUMBER
;

BEGIN
   tmpVar := 0;
   SELECT seq01.NEXTVAL INTO tmpVar FROM dual
;
   :NEW.id := tmpVar
;
   EXCEPTION
      WHEN OTHERS
THEN
      – Consider logging the error and then re-raise
      RAISE;
END
tg_bi_test;

Create stored procedure

CREATE

OR REPLACE PROCEDURE [SCHEMA].AddBank( Bank_Code CHAR,
 
Bank_Name CHAR,

  pCountry
CHAR

 
DEFAULT ‘XX’)

IS

BEGIN
INSERT INTO BANK (BankCode,BankName,Country)  VALUES(Bank_Code, Bank_Name,pCountry);
END
AddBank;


Call stored procedure

exec

ADDBANK(‘aaa’,‘bbb’);

(NHibernate call:)
var query =
session.CreateSQLQuery("call ADDBANK(:Bank_Code, :Bank_Name,:pCountry)");
query.SetString(
"Bank_Code", "0808");
query.SetString(
"Bank_Name", "Franklin’s bank");
query.SetString(
"pCountry", "XX");
var l = query.ExecuteUpdate();

 


h1

Loading image for Full PostBack

April 7, 2009

Loading image should be use, when user is waiting to performing “long time” server action.

When you will look to the internet, than you will probably find a lot of Ajax which will not work for full postback correctly (it is correctly working for update panels but not for whole page).

Solution

  • Use javascript, and set visibility style of animated gif to hidden
  • However you’ll press control which executes “long running” action, set visibility and timeout of animated gif
  • When processing finish, animated gif will be disabled again.

Links

h1

Telerik Reporting: Report with subreports and chart binded from ObjectdataSource

March 15, 2009

 

Following examaple  demonstrates easy report with subreports  (Master- Detail report). One of subreport contains chart. All repoerts are binded from one ObjectDataSource. And finally,  whole report is converted into the PDF file.  I dindn’t have a lot of time to investigate telerik reporting, but I am a bit disappointed, becouse 

  • I don’t know how to create charts without explicit binding of Chart-SeriesItems.
  • I have to handled ItemDataBinding or NeedDatasource events for binding subreports.
  • When I was creating Master-detail report, than I obtained  report with blank pages. There is solution.  I solved it in my sample too.

So, wipe it off and come up to example.  Following picture shows my test report.  Report is binded from class that contains few fielads and two lists.

reporting

And there is source code

Links

h1

Justice – stress

November 23, 2008

h1

Default values for FormView control in Insert mode

November 19, 2008

In many times we must assign default values to FormView in the insert mode. Problem is, that FW creates empty entity and this means empty FW.

Here is very short and powerful solution ;)

  • Add binding source to control which we want to set

    <asp:TextBox ID=”RateTextBox” runat=”server” Text=’<%# Bind(”Rate”) %> TabIndex=”24″ MaxLength=”5″ OnDataBinding=”InsertRateOnDataBinding />

  • Setting value to this control

    protected void InsertRateOnDataBinding(object sender, EventArgs e)
    {
      ((TextBox) sender).Text = RevertedOccupiedPercentage.ToString();
    }

h1

Regex designer tool

November 4, 2008

 

If you want to design and test your regular expressions, you should find any power  utility. There is one – Free Regular Expression Designer.

 

Links

h1

Percentage Regex

November 3, 2008

If you need percentage regex for positive percent numbers, you can use this:

  • ^0?[0-9]{0,2}(\,[0-9]{1,2})?$|^(100)(\,[0]{1,2})?$

Valid values: 100; 13,1; 001; 002,11; 100; 000; 0

Invalid values:  15.1; 15,x; 101; -2; -0

 

 

h1

Global resources for validations (ASP .NET)

October 31, 2008

If you want to reuse expressions, error messages etc. for validators, you should use app.config storage or resources.

I will show you how to use resources for storing adjustments of ExpressionValidator .

  • Create Global resource directory

    1

  • Create GlobalResources – Call them ValidationResources.resx
    2 
  • Fill resources by expression and error message

    3

  • Add meta attribute  with resource resource name into your @Page directive on the page where you want to use resource.

    4

  • Add RegularExpressionValidator from toolbox and set it to resource values.

    5

  • If you want you can skip last step and you can set it in the designer

    6

  • Now run the application and look whats happening ;)

     7

h1

Regex – Date validator for DD.MM.YYYY fromat

October 31, 2008

 

This regex really works.  It is used for validation of DD.MM.YYYY, DD-MM-YYYY date format together with leap year computing.

 

(((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))

 

It validates: 10.10.2008, 29.02.2008, 29.02.2008, 2.2.2008, 2-2.2008, 2-2-2008, 30.04.00, 01.1.01

Doesn’t  validate: 29.2.2007, 30.00.00, 0.1.01

Links

h1

e.Cancel and update page

October 30, 2008

First at all I solved this f***ng problem than I found this forum.  My problem was, that I used FomView default setted to FormViewMode.Edit.  If I changed mode to Insert mode ,calling FomView.CahngeMode(FormViewMode.Insert), than  it worked fine. However I made mistake in FormView (bad typed price etc…) I validated data on server . After bad validation which I made in Inserting handled method of Object DataSource I called called e.Cancel.

It’s good idea but  result is, that updating of page is stopped => FormView will be setted to Edit mode, not to in insert Mode (prepared to pass data about new customer again). My solution of this is to set flag and set values of components in overrided prerender method.

 

//method blocks processing of updating page
private
void BlockCommandProcessing(ObjectDataSourceMethodEventArgs e, string message)
{
 
OnError(message);
 
e.Cancel = true;
 
_formviewWillBeVisibleAndInInsertMode = true;
}

//is setted when e.Cancel is called => we lost settings of page
//I will set it again in prerender phase
private bool _formviewWillBeVisibleAndInInsertMode;

protected
override void OnPreRender(EventArgs e)
{
if (_formviewWillBeVisibleAndInInsertMode)
    SetVisibilityOfItems(ControlStates.InsertClicked);
base.OnPreRender(e);
}

SetVisibility method sets FormView mode and visibilities of controls in depends of ControlState.

 

Links