lunes, 30 de junio de 2014

IIS - Permisions


IIS Permissions

To enable the Active Directory connection in the IIS, follow the next steps:

  1. Go to IIS
  2. Go to Application Pool
  3. Select your App Pool
  4. Select Advanced Settings in the right side
    1. In the section Process Model
    2. Select in Identity value the property "NetworkService"

You don´t need to restart your application



lunes, 28 de abril de 2014

AJAX - Tabs C#

I had a problem at the moment of hide a tab and after show (active) another tab. This cause me an error in javascript.

Solution

  • The first time the TabContainer is shown, ajax read the number of tabs and is all the tabs he knows.
    • In my case at the beginning show 2 tabs and hide other 2 tabs 
     
  •  In the aspx bind the method OnActiveTabChanged="TabContainerUpdate_ActiveTabChanged"
    • In the method TabContainerUpdate_ActiveTabChanged I add the condition: 
      • if (TabContainerUpdate.ActiveTabIndex != 0)
                    TabContainerUpdate.ActiveTabIndex = 1;
    • With this condition when I show another tab I assigned the new tab to the second index that ajax knows 
    • I prefer to use the ActiveTabIndex property instead of ActiveTab

 

Knowledge

  • The error is caused because at the beginning ajax only know that have 2 tabs, and when reload the page in an AutoPostback try to go to another tab with index bigger that 2

viernes, 18 de abril de 2014

Python - Basics

Download

python.org

Basics commands

dir(__builtins__)   
Show all the defined functions

help(function_name) 
Show function description

print(string_text)

(__name__)
print the scope in which the functionality is been executed

Define a function

  • Type word def follow by name function with the parameters
  • Type word return with the functionality
Ex:   def f(x):  return x**2

Testing

Inside your function description define the result expected inside the comments.

'''
>>> function_name(parameter_value)
result

>>> function_name(parameter_value_2)
result2

>>>
'''
To run the test cases type

import doctest
doctest.testmod()

You can also run the test cases after your return statement, so each time you include your function the test cases are executed.

Unittest

You can also use Unit Test 
  1. Import unittest
  2. Create a class inherits from unittest.TestCase
    • class TestMain(unittest.TestCase):
  3. Create your test case 
    • def test_name(self):
  4. Use self.assertEqual()
  5. Execute the test cases with unittest.main(exit=False)

Consideration for test cases

Take in consideration these cases:
  • Size
  • Dichotomies 
    • True/False
    • Even/Odd
  • Boundaries
  • Order

Define a class

  1. Type the name of the class and inside the parenthesis the class you want to import
  2. Define your default constructor
  3. Define your methods

class MyClass(str):

    def __init__(param1, param2):
        self.var1 = param1

    def paly(s):
        print (__name__)
        return len(s)

Define methods with default value in parameters

def method_name(param , param2=default_value):

Then you can call method in these ways:

  • method_name(2)  or 
  • method_name(2, 'aa')  

Algorithms 

Each function performs as one of the following functions
  • Lineal 
  • Exponential
  • Logarithmic
log2(n) is the number of times we divide n by 2 in order to reach 1

To evaluate a function python have the library cProfile


Exceptions 

Use the following syntaxis

try:

except  exceptionType:

except exceptionType as e:
   print (e)

As recommendation can use assert to verify preconditions 



miércoles, 19 de marzo de 2014

C# - Dates

How to parse a Date


DateTime tg2 = DateTime.Parse(txtTG2.Text, System.Globalization.CultureInfo.CreateSpecificCulture("en-US"));


How to parse date in a textBox using a calendar


 <asp:TextBox ID="txtTG4" runat="server" Text="" CssClass="capture" Style="width: 75px;" />
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator7" ControlToValidate="txtTG4" runat="server" ErrorMessage="*Required" CssClass="validator" ValidationGroup="save" />
                                    <ajaxCTK:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtTG4" PopupPosition="TopLeft" />
                                    <ajaxCTK:MaskedEditExtender ID="mskTg4" runat="server" Mask="99/99/9999" MaskType="Date" CultureName="en-US"
                                        TargetControlID="txtTG4" ErrorTooltipEnabled="true" AutoComplete="false">
                                    </ajaxCTK:MaskedEditExtender>
                                    <ajaxCTK:MaskedEditValidator ID="MaskedEditValidator5"
                                        runat="server" ValidationGroup="save"
                                        ControlExtender="mskTg4"
                                        ControlToValidate="txtTG4"
                                        InvalidValueMessage="Date is invalid"
                                        IsValidEmpty="True" />

jueves, 27 de febrero de 2014

SQL Server - Linked Server

How to import an Excel file using Linked Server

1.- Download the Microsoft Access Database Engine 

http://www.microsoft.com/en-us/download/details.aspx?id=13255

In my case I installed the x64 version, to avoid problems I did through the console.

  • Open a cmd console as Administrator
  • Change the path where is your AccessDatabaseEngine_x64.exe file
  • Execute the file adding at the end /passive, example: 
C:\Users\ERODVEL\Documents>AccessDatabaseEngine_x64.exe  /passive
2.- Open your SQL Server Management Studio

  • Review that the Provider has been installed
  • Select Microsoft.ACE.OLEDB.12.0 and right click in Properties, and review that the only selected option is "Allow inprocess".


  • Other form is by code    
EXEC sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1
GO


  • Add a new Linked Server using the following code
EXEC master.dbo.sp_addlinkedserver
    @server = 'ExcelServer2',
    @srvproduct=N'ACE 12.0',
    @provider = 'Microsoft.ACE.OLEDB.12.0',
    @datasrc = 'C:\Users\YOUR_USER\Documents\YOUR_EXCEL_FILE.xls',
    @provstr = 'Excel 12.0;HDR=YES;'


  • In the properties, configure the Security 
If not the error will be:
Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server 

Queries

To do a query
  • Reference the table as [Linked_Server_Name]...[Tab_name$]

Linked Server to another Sql Server Instance

  1. Create a New Linked Server
  2. In the General section
    • Type in Linked Server the name or IP of the sql server to connect
    • In Server Type: Select SQL Server,
  3. In the  Security Tab, select "Be made using this security context" 
  4. Type OK

Using XLSM

When create the Linked Server in the Provider String property @provstr  change to Excel 12.0 Macro, where Macro is the key

EXEC master.dbo.sp_addlinkedserver
    @server = 'ExcelServer2',
    @srvproduct=N'ACE 12.0',
    @provider = 'Microsoft.ACE.OLEDB.12.0',
    @datasrc = 'C:\Users\YOUR_USER\Documents\YOUR_EXCEL_FILE.xls',
    @provstr = 'Excel 12.0 Macro;HDR=YES;' 


Security

To configure the security add  to the script
 
 EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'Test',@useself=N'False',@locallogin=NULL,@rmtuser=NULL,@rmtpassword=NULL

Update 

    UPDATE DATA
    SET [Result] = @result
    FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
    'Excel 12.0 Macro;HDR=Yes;DATABASE=C:\\SRC\Period.xlsx',
    'SELECT [Result] FROM [Period$] WHERE [Result] IS NULL') AS DATA

References

http://akawn.com/blog/2012/01/query-and-update-an-excel-2010-spread-sheet-via-a-linked-server/


http://vogtland.ws/markedwardvogt/?p=991

http://www.excel-sql-server.com/excel-import-to-sql-server-using-linked-servers.htm


SQL Server - Tips

List All Tables of Database

 


USE [YourDBName]
GO 

SELECT 
*FROM sys.Tables
GO


Insert structure from one table to another


SELECT *
into new_table
FROM origin_table where 1 =2 

How to create a counter

Use the function ROW_NUMBER ( ), where the syntaxis is
 
ROW_NUMBER ( ) OVER ( FIELD order_by_clause )
 
Where FIELD  is the name of the column you want to use to start counting. Example:

SELECT ROW_NUMBER() OVER(ORDER BY SalesYTD DESC) AS Row, 
FROM Sales.vSalesPerson
 

Enumerate rows ... 1.2.3....

 
ROW_NUMBER() over ( ORDER BY [Job Stage]) as [pyramidPosition]
 

Reset the enumeration  ..... 1.2.3....1.2.3

 

ROW_NUMBER() over (partition BY idProject ORDER BY [Job Stage]) as [pyramidPosition]
 
http://sqlfiddle.com/#!6/501c0/2/0
 
 Update Table from Select
 

Update projects

set projects.tg4Real = [TG4 Date Real DD/MM/YYYY] ,
 projects.tg5Real = [TG5 Date Real DD/MM/YYYY] 
from
 projects p
inner join
 gtt...[Upload$] u
on p.projectName = [Project Name]
 
 

Multi user

ALTER DATABASE DATA_BASE SET MULTI_USER; 
 

Add user to a DB

Can you check it by Going To Security --> Login-->Right and Click Property and then goto user mapping tab. Then select the database
 
 

Convert String Dates to Date/Datetime 

From '12/10/25' to date 
CONVERT(DATE,CAST ( RTRIM( LTRIM([CREATION DATE])) as nvarchar), 103) 

From '16/01/2007 3:03:35:270AM' to datetime
From '23/06/2014 09:07:17 a. m.'  to datetime
CONVERT(datetime, ( RIGHT(LEFT([START TIME],5),2) + '/'+LEFT([START TIME],2)+'/'+ RIGHT(LEFT([START TIME],10),4)+  SUBSTRING([START TIME],11, 9 ) + REPLACE( SUBSTRING([START TIME],21, 4 ), '. ', '' ) ) , 120 ) as ODBC_datetime


 

 

 

 

 

 

 

 


Android - First Steps VI


Arrays

In your project in the following path: res -> layout folder, create an Android XML file. 
Select from the wizard in Resource Type : Values and named the Xml file as "javafacts.xml".


The XML file must have the following structure:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="messages">
        <item>
First element</item>
        <item>Second element</item>
    </string-array>
</resources>


Get Array in code

In this case R.array.messages is by the name in defined in the XML file.
Resources resources = this.getResources();
        String[] javafacts =  resources.getStringArray(R.array.messages);