Search This Blog

Friday, December 31, 2010

2011 Predictions

Here are the list of what lies ahead aka predictions for 2011 Technology and fearless forecast. 
  • The world will be getting smaller each day because of the technology and the increasing wisdom.
  • Microsoft will continue to lord it over with the desktop OS while getting its ground on the server side.
  • Linux will continue to be the main actor in the server side however.
  • Unbuntu canonical will to lead the Linux desktop experience and GNOME will still be the default.
  • Android will be the OS of the mass for 2011, but Iphone will still be the number one at the end of the year.
  • There will be new hybrid computer virus same to that of stuxnet.
  • Chrome OS and its browser will gain grounds in the market.
  • Google will still be the number one search engine for this year.
  • Worlds economy will recover and thus the IT business will boom.

Create A Custom 13 Period Calendar

Few years back I have to convert a FoxPro script that generate a custom yearly calendar to asp.net using c#. In a year it consists of 13 Periods, 4 weeks per period and 7 days a week. The concept behind is that the days per period is evenly divided into 28 days. The Logic is very simple yet it is worth taking a look. For documentation I just post here the code that generates the calendar.Below is the code. Happy coding every one.

protected void GenerateCalendar()
    {
        DateTime dtdateStart = DateTime.Now ;
        if (textboxtransdate.Text != "")
        {
            dtdateStart = Convert.ToDateTime(this.textboxtransdate.Text);
        }

int _intend = System.Data.Linq.SqlClient.SqlMethods.DateDiffDay(dtdateStart, Convert.ToDateTime(textboxDateEnd.Text));
       
            int _pdcldr = 1;
            int _wkcldr = 1;
            int _dayCal = 1;
            int _wkcounter = 0; //week counter
            int _periodcount = 0; // period counter
            int _yrcldr = Convert.ToInt32(this.txtYear.Text);
   
            // loop thru until we reached the number of days specified

            for (int i = 0; i <= _intend; i++)
            {
             
                if (i > 0)
                {
                    dtdateStart = dtdateStart.AddDays(1);
                }

                switch (Convert.ToString(dtdateStart.DayOfWeek).ToLower())
                {
                    case "sunday":
                        _dayCal = 1;
                        break;
                    case "monday":
                        _dayCal = 2;
                        break;
                    case "tuesday":
                        _dayCal = 3;
                        break;
                    case "wednesday":
                        _dayCal = 4;
                        break;
                    case "thursday":
                        _dayCal = 5;
                        break;
                    case "friday":
                        _dayCal = 6;
                        break;
                    case "saturday":
                        _dayCal = 7;
                        break;
                }


                _wkcounter = ++_wkcounter;

                //counter for the days
                _periodcount = ++_periodcount;

                //increase _wkcldr by 1
                if (_wkcounter == 8)
                {
                    _wkcldr = ++_wkcldr;
                    _wkcounter = 1;
                }

                //1 period = 28 days if _periodcount ==28 increase the _pdcldr by 1 and reset the _periodcount
                if (_periodcount == 29)
                {
                    //reset the _wkcldr and increase _pdcldr
                    _wkcldr = 1;
                    _pdcldr = ++_pdcldr;

                    if (_pdcldr >= 14)
                    {
                        _wkcldr = 5;
                        _pdcldr = 13;
                    }
                    //reset the _periodcount which serves as the counter for the period
                    _periodcount = 1;
                }
                //prepare to append the data to the database
                using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString3))
                {
                    SqlCommand myCommand = new SqlCommand("Downtime_sp_CreateUpDateDoleCalendar", myConnection);
                    myCommand.CommandType = CommandType.StoredProcedure;
                    myCommand.Parameters.AddWithValue("@transdate",dtdateStart);
                    myCommand.Parameters.AddWithValue("@yrcldr", _yrcldr);
                    myCommand.Parameters.AddWithValue("@pdcldr", _pdcldr);
                    myCommand.Parameters.AddWithValue("@wkcldr", _wkcldr);
                    myCommand.Parameters.AddWithValue("@daycal", _dayCal);

                    DbParameter returnValue;
                    returnValue = myCommand.CreateParameter();
                    returnValue.Direction = ParameterDirection.ReturnValue;
                    myCommand.Parameters.Add(returnValue);

                    myConnection.Open();
                    myCommand.ExecuteNonQuery();
                    myConnection.Close();
                }
            }
    }

Stored Procedure That Will Create and Update Table

Below is a stored procedure code that will create or update the data. Its a prototype stored procedure for updating and inserting record to a certain database.

Stored Procedure that will Update or Create Data


Create Proc [dbo].[FrtCnt_sp_CreateUpdateFactor]

@pk INT, -- primary key
@fkpackstyle INT, -- foriegn key for packstyle
@descpn CHAR(25), -- description
@coef float   -- coeffient

AS

      DECLARE @ReturnValue int
      DECLARE @ErrorCode int
      DECLARE @nCnt int
      SET @nCnt = 0

/*Determine if the current pk being passed to @pk currently exist in the recordset*/

SELECT a.pkfactor FROM frtcnt_tbl_ref_factor a WHERE a.pkfactor = @pk
IF @@rowcount >0

      SET @nCnt =1 –set

BEGIN TRANSACTION

            -- Insert New Record to the database

            IF(@nCnt =0)
                  BEGIN
                        INSERT INTO  frtcnt_tbl_ref_factor
                        (
                                    pkfactor,
                                    fkpackstyle,
                                    descpn,
                                    Coef
                        )
                        VALUES
                        (
                              @pk,
                              @fkpackstyle,
                              @descpn,
                              @Coef
                        )

                        SET @ErrorCode = @@ERROR
                        IF (@ErrorCode <> 0) GOTO DetailError
                        SELECT @ReturnValue = SCOPE_IDENTITY()                     

                  END
            ELSE
                  BEGIN
                        -- Update The Existing Record in the Database

                        UPDATE  frtcnt_tbl_ref_factor SET
                                    pkfactor = @pk,
                                    fkpackstyle = @fkpackstyle,
                                    descpn = @descpn,
                                    Coef = @coef,
                                    datemodified = getdate(),
                                    modifiedby =  suser_sname()
                 
                        WHERE pkfactor = @pk

                        SET @ErrorCode = @@ERROR
                        IF (@ErrorCode <> 0) GOTO DetailError                      

                  END

COMMIT TRANSACTION
      RETURN (0)

      DetailError:
      ROLLBACK TRANSACTION
      RETURN(@ErrorCode)

Change Local Administrator Password at Startup

1. Open notepad and type the following code

Set WshNetwork = WScript.CreateObject("WScript.Network")
strComputer = "."
Set objUser = GetObject("WinNT://" & strComputer & "/Administrator,user")
objUser.SetPassword "Password"
objUser.SetInfo

2. Save it in c:\startup\change.vbs

3. Open Registry Editor (regedit).

4. Navigate to the following node MyComputer\HKey_Local_Machine\SOFTWARE\Policies
\Microsoft\Windows\System\Scripts\Startup

5. Create a string under start up node with the following name FileSysPath.

6. In the FileSysPath Modify the value to c:\startup\change.vbs

7. This will change the administrator password to "Password" during start up.
 

Thursday, December 30, 2010

Shutdown Using Scheduled Task in Windows 7

This tutorial will show you how to create a scheduled task in windows 7.

1. Click start, All Programs, Accessories, System Tools, Task Scheduler.


2.  In the action pane click create task.


 3. In General Tab We need to name the task we want to perform. In our case I named it shutdown @ 1300H

4. In Trigger Tab click New. For this demo we choose One time. You may select daily or weekly from the selection.

5. In the Action Tab click New a pop up window will appear. In the Program/Script type the following %systemroot%\system32\shutdown.exe. In the argument type the following -t 01 -f -s.

6. Afterward click OK button.

Wednesday, December 29, 2010

Schedule your pc to shutdown automatically using scheduled task

Did you know that there is a built in functionality that you can call that would shutdown a pc using windows at any given time. This is very helpful functionality as one can schedule the pc to automatically shutdown the pc on any given time. Follow the steps below.

1. Click start, All Programs, Accessories, System Tools, Scheduled Task.
2. Click Add Scheduled Task and click next afterwards.
3. Click Browse
4. In the file name type the following %systemroot%\system32\shutdown.exe and click Open and click next

5. Click Daily to perform the task on a daily basis.


6. Click Ok