Monday, September 26, 2016

select record in variable SQL

DECLARE @var1 varchar(30)  
SELECT @var1 = 'Generic Name'  
SELECT @var1 = ((SELECT top 10 Client_account_number FROM #TempTable1))  
SELECT @var1 AS 'account_number' ;

Generic script for selecting columns from result of stored proc

CREATE PROCEDURE SampleSP
AS
SELECT 1 AS Col1, 2 AS Col2
UNION
SELECT 11, 22
GO


CREATE TABLE #TempTable (Col1 INT, Col2 INT)
GO
INSERT INTO #TempTable
EXEC SampleSP
GO

SELECT *
FROM #TempTable
GO

DROP TABLE #TempTable
DROP PROCEDURE SampleSP
GO

Friday, September 16, 2016

TFS Locking issue


Files with .dll extension as well as other extensions like .exe, .doc, .docx, etc. are automatically locked because (as mentioned) here they cannot be merged.
If you want to disable the automatic lock and allow these files to go through gated check-in, follow the steps below:
  1. Log in to your build server.
  2. Open visual studio.
  3. In team explorer, log into your team project.
  4. Go to "Settings".
  5. Under "Team Project Collection", select "Source Control".
  6. Set "File Merging" property to "Disabled" for any file extension you don't want to be automatically locked.

Friday, September 9, 2016

SQL bulk insert sample

USE TestData
GO
CREATE TABLE CSVTest
(ID INT,
FirstName VARCHAR(40),
LastName VARCHAR(40),
BirthDate SMALLDATETIME)
GO

BULK
INSERT CSVTest
FROM 'F:\naiki_DB\mike\cvtest.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
--Check the content of the table.
SELECT *
FROM CSVTest
GO
--Drop the table to clean up database.
DROP TABLE CSVTest
GO

Monday, September 5, 2016

javascript sample from aspx.cs page


Printing from aspx.cs page

imgBtnPrint.Attributes.Add("onclick", "window.print();");

alert box from aspx.cs page

Response.Write("<script>alert('Hello');</script>");
button that directly prints a document via website:

<input type="button" value="Print" onclick="window.print();" />

or

<asp:button id="button1" runat="server" onclientclick="window.print(); return false;" text=Print" />

Another sample
  string popupScript = "<script language='javascript'>" + "window.open('frmLogin.aspx" + "', 'PasswwordExpiryWarning', " + "'width=430, height=318, menubar=no, resizable=no')" + "</script>";
 ClientScript.RegisterStartupScript(popupScript.GetType(), "Warning", popupScript);



btn cancle (on popup window):
btnCancel.Attributes.Add("onClick", "javascript:window.close();");














Friday, September 2, 2016

dynamically creating html table and binding to table in aspx page

aspx page code


 <table id="tblCTC_Data" runat="server">
                            <tr id="tdrCTCData_Header">
                                <td runat="server">Description fo Class Shares
                                </td>
                                <td runat="server">(a) Immediately before 1 January 2011
                                </td>
                                <td runat="server">(b) Where the company became a resident since 1 January 2011
                                </td>
                                <td runat="server">Add Considiration received or accrued for the issue of shares by the company
                                </td>
                                <td runat="server">Deduct amount transferred to holders of shares
                                </td>
                                <td runat="server">Deduct reduction as a result of the application of s42
                                </td>
                                <td runat="server">Deduct reduction as a result of the application of s44
                                </td>
                                <td runat="server">Deduct reduction as a result of the application of s46
                                </td>
                                <td runat="server">Balance of contributed tax capital at the end of the assesment
                                </td>
                            </tr>
                        </table>



aspx.cs page code


            tblCTC_Data.Rows.Clear();
            HtmlTableRow headerRow = new HtmlTableRow();
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "Description fo Class Shares" });
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "(a) Immediately before 1 January 2011" });
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "(b) Where the company became a resident since 1 January 2011" });
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "Add Considiration received or accrued for the issue of shares by the company" });
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "Deduct amount transferred to holders of shares" });
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "Deduct reduction as a result of the application of s42" });
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "Deduct reduction as a result of the application of s44" });
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "Deduct reduction as a result of the application of s46" });
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "Balance of contributed tax capital at the end of the assesment" });

            foreach (HtmlTableCell c in headerRow.Cells)
            {
                c.Style.Add("font-weight", "bold");
            }

            tblCTC_Data.Rows.Add(headerRow);

            if (_rootCustomer.ReturnDetail.CorporateIncomeTaxReturn.CompanyDetails.ContributedTaxCapitalDetails.Count > 0)
            {
                foreach (CorporateIncomeTaxReturnStructureCompanyDetailsContributedTaxCapitalDetail xDataTable in
                _rootCustomer.ReturnDetail.CorporateIncomeTaxReturn.CompanyDetails.ContributedTaxCapitalDetails)
                {
                    HtmlTableRow newRow = new HtmlTableRow();
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.ShareClassDescription.ToString() });
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.Before1January2011Amt.ToString() });
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.After1January2011Amt.ToString() });
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.ConsiderationReceivedForShareIssueAmt.ToString() });
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.TransferredToHoldersAmt.ToString() });
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.ReductionApplicationS42Amt.ToString() });
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.ReductionApplicationS44Amt.ToString() });
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.ReductionApplicationS46Amt.ToString() });
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.BalanceEndOfYearAmt.ToString() });
                    tblCTC_Data.Rows.Add(newRow);
                }

            }





same code for asp.net table

.aspx page

  <asp:Table ID="tblCTC" runat="server" Width="794px" BorderStyle="Solid" BorderWidth="3px">
                <asp:TableRow ID="thrCTC_Description" runat="server" BackColor="Gray" ForeColor="White">
                    <asp:TableCell Font-Size="XX-Small" ID="thcCTC_Description" runat="server" ColumnSpan="2">
                        Contributed Tax Capital
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow ID="tdrCTC_CTCDetails_GrossIncomeAmt" runat="server" Width="794px">
                    <asp:TableCell Font-Size="XX-Small">
                        <asp:Table runat="server" ID="tblCTC_Data">
                            <asp:TableRow ID="tdrCTCData_Header" runat="server">
                                <asp:TableCell>Description fo Class Shares</asp:TableCell>
                                <asp:TableCell>(a) Immediately before 1 January 2011</asp:TableCell>
                                <asp:TableCell>(b) Where the company became a resident since 1 January 2011</asp:TableCell>
                                <asp:TableCell>Add Considiration received or accrued for the issue of shares by the company</asp:TableCell>
                                <asp:TableCell>Deduct amount transferred to holders of shares</asp:TableCell>
                                <asp:TableCell>Deduct reduction as a result of the application of s42</asp:TableCell>
                                <asp:TableCell>Deduct reduction as a result of the application of s44</asp:TableCell>
                                <asp:TableCell>Deduct reduction as a result of the application of s46</asp:TableCell>
                                <asp:TableCell>Balance of contributed tax capital at the end of the assesment</asp:TableCell>
                            </asp:TableRow>
                        </asp:Table>
                    </asp:TableCell>
                </asp:TableRow>
            </asp:Table>




aspx.cs page code:

    tblCTC_Data.Rows.Clear();
            //HtmlTableRow headerRow = new HtmlTableRow();
            System.Web.UI.WebControls.TableRow headerRow = new System.Web.UI.WebControls.TableRow();
            headerRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = "Description fo Class Shares" });
            headerRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = "Description fo Class Shares" });


            //headerRow.Cells.Add(new HtmlTableCell() { InnerText = "Description fo Class Shares" });
            headerRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = "(a) Immediately before 1 January 2011" });
            headerRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = "(b) Where the company became a resident since 1 January 2011" });
            headerRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = "Add Considiration received or accrued for the issue of shares by the company" });
            headerRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = "Deduct amount transferred to holders of shares" });
            headerRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = "Deduct reduction as a result of the application of s42" });
            headerRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = "Deduct reduction as a result of the application of s44" });
            headerRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = "Deduct reduction as a result of the application of s46" });
            headerRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = "Balance of contributed tax capital at the end of the assesment" });

            foreach (HtmlTableCell c in headerRow.Cells)
            {
                c.Style.Add("font-weight", "bold");
            }
            //tblCTC_Data.Rows.Add()
            tblCTC_Data.Rows.Add(headerRow);

            if (_rootCustomer.ReturnDetail.CorporateIncomeTaxReturn.CompanyDetails.ContributedTaxCapitalDetails.Count > 0)
            {
                foreach (CorporateIncomeTaxReturnStructureCompanyDetailsContributedTaxCapitalDetail xDataTable in
                _rootCustomer.ReturnDetail.CorporateIncomeTaxReturn.CompanyDetails.ContributedTaxCapitalDetails)
                {

                    System.Web.UI.WebControls.TableRow newRow = new System.Web.UI.WebControls.TableRow();
                    newRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = xDataTable.ShareClassDescription.ToString() });
                    newRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = xDataTable.Before1January2011Amt.ToString() });
                    newRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = xDataTable.After1January2011Amt.ToString() });
                    newRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = xDataTable.ConsiderationReceivedForShareIssueAmt.ToString() });
                    newRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = xDataTable.TransferredToHoldersAmt.ToString() });
                    newRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = xDataTable.ReductionApplicationS42Amt.ToString() });
                    newRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = xDataTable.ReductionApplicationS44Amt.ToString() });
                    newRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = xDataTable.ReductionApplicationS46Amt.ToString() });
                    newRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = xDataTable.BalanceEndOfYearAmt.ToString() });
                    tblCTC_Data.Rows.Add(newRow);
                }

            }