วันศุกร์ที่ 28 มิถุนายน พ.ศ. 2556

Crysal Report การติดตั้ง(Deploy) บน Server

ต้องการติดตั้งตัว Report ซึ่งพัฒนาจาก Visual Studio 2010 ในเครื่องเราลงใน Server

เตรียมการดังนี้


1. หาตัว Crystal Report RunTime ที่มี Version ตรงกับที่อยู่ใน VS2010 ในเครื่องที่พัฒนาของเรา ติดตั้งให้ Server หาได้จากที่นี่ Crystal Reports, developer version for Microsoft Visual Studio Updates & Runtime
2. ตรวจสอบ ส่วนประกอบ assemblies ของ Crystal Report ใน web.config ในเครื่องเราให้ตรงกันกับเครื่อง Server
3. ให้เช็ท application pool ใน IIS Manager ของ web เราใน server ให้ทำงานแบบ LOCAL SERVICE
4. เซ็ท .NET Trust Level  ของโฟลเดอร์ web ของเราใน IIS Manager ให้เป็น FULL(internal)
5. ต้องมีโฟลเดอร์ aspnet_client ในโฟลเดอร์ web ของเราถ้าไม่มีหาจาก c:\inetpub\wwwroot ใน Server
6. ถ้าใช้ Sql Server  ต้องมี Service ชื่อ Sql Server Integration Service  ติดตั้งอยู่ด้วยไม่งั้นจะพบ error code 17 : SQL Server Does not Exist or Access Denied

วันจันทร์ที่ 24 มิถุนายน พ.ศ. 2556

Visual Studio - แก้ Error Create Control ขณะกำลังออกแบบ

 เกิด Error Create Control ขึ้นใน Visual Studio 2010 ขณะกำลังออกแบบ หรือ Design time ไม่แสดง Control  แต่สามารถรันได้ตามปรกติ



สาเหตุ คือเราไปเขียน Code ส่วน event  Page_Init

วิธีแก้ VB
 เพิ่ม   If Context IsNot Nothing AndAlso Context.Session IsNot Nothing Then
              ....any code
        end if
คร่อม code ใน Page_Init

 จาก link นี้

Controls State: "Error Creating Control" in the Design View in Visual Studio 2010

วันเสาร์ที่ 22 มิถุนายน พ.ศ. 2556

Crytal Report ตัว Report บัง Datepicker หรือเมนู

มีปัญหา ตัว Datepicker แสดงผลอยู่หลัง Report


แก้โดยใช้ z-index
โดยการใส่ style="position:relative; z-index:-1"  ให้กับ tag div ที่มีตัว Report อยู่ดังนี้

   <div style="position:relative; z-index:-1">   
        <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
            AutoDataBind="true" EnableParameterPrompt="False"
            ReportSourceID="CrystalReportSource1" ToolPanelView="None"
            EnableDatabaseLogonPrompt="False" />   
    </div>
 
ผลลัพท์


น่าจะใช้กับ Control อื่นได้เช่น Panel, Menu

Crystal Report - เบื้องต้น

Crystal report ไม่รวมใน Visual Studio 2010 ต้องติดตั้งเองเพิ่ม

มีปัญหากับ IE10 ไม่ Render ต้องเติม Code ในส่วน Header ของหน้าที่มี  CrystalReportViewer

           <meta http-equiv="X-UA-Compatible" content="IE=9,chrome=1" />

บังคับให้ IE10 ใช้ Compatible mode 


มีบทความเยอะที่เขียนไว้เช่น
 
http://www.thaicreate.com การติดตั้ง Crystal Report

 http://www.thaicreate.com

http://www.codeproject.com

Displaying-Exporting-and-Printing-Crystal-Reports

วันพุธที่ 19 มิถุนายน พ.ศ. 2556

jQuery Datepicker แบบไทย

ต้องการ textbox ที่รับข้อความแบบวันที่ไทยแบบนี้
   

ไฟล์  http://goo.gl/IrwUKB

วิธีทำ

ใช้ 2 file จาก link ข้างบนคือ  ui.datepicker.js, ui.datepicker-th.js ใสในโฟล์เดอร์ Scripts
และ file อืน ๆ จาก jQuery-ui-1.7.2.zip  แตกไฟล์แล้วหาไฟล์ในโฟล์เดอร์ \jquery-ui-1.7.2\themes\base มาเพิ่มในโฟเดอร์ Styles ดังรูป



ใน Source


<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <link href="Styles/ui.all.css" rel="stylesheet" type="text/css" />
    <link href="Styles/ui.datepicker.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="Scripts/jquery-1.3.2.js"></script>
    <script type="text/javascript" src="Scripts/ui.datepicker.js"></script>
    <script type="text/javascript" src="Scripts/ui.datepicker-th.js"></script>
  
 <script type="text/javascript">
     $(function () {
         $("#<%= txtFrom.ClientID %>").datepicker({
             showmonth: true,
             autoSize: true,
             showAnim: 'slideDown',
             duration: 'fast',
             changeMonth: true,
             changeYear: true
         });

     });

    </script>
</asp:Content>

วิธีเรียกใช้

<asp:TextBox ID="TxtFrom" runat="server"></asp:TextBox>

ข้อระวัง

jQuery UI 1.7.2 is only supported with jQuery 1.3.2

jQuery UI 1.8 RC 2+ is supported with jQuery 1.3.2 and jQuery 1.4.2


วันจันทร์ที่ 17 มิถุนายน พ.ศ. 2556

SQL Server ลบแถวถ้ามีในตารางอื่น

 SQL Server ลบแถวถ้ามีในตารางอื่น
 
DELETE  x
FROM  vipstudent x
WHERE
   EXISTS
    (
    SELECT 1
    FROM test1 y
    WHERE
      x.std_code = y.std_code
    )

วันศุกร์ที่ 14 มิถุนายน พ.ศ. 2556

ASP.NET ลำดับที่ใน gridview

ลำดับที่ 1,2,3 ในคอลัมน์แรกของ Gridview เพิ่ม code

<asp:TemplateField HeaderText="ที่">
                    <ItemTemplate>
                        <%# Container.DataItemIndex + 1 %>
                    </ItemTemplate>


วันอังคารที่ 11 มิถุนายน พ.ศ. 2556

javascript แสดงหน้าต่าง confirm ที่มีเงื่อนไขแบบลูกทุ่ง

  • มี 3 CheckBox
  • 1 Button 
  • 1 Html Input Text (เอาไว้เก็บค่า)
ต้องการ
   1. ถ้าไม่คลิกเลยเวลากดป่ม Button ให้แสดง alert('คุณยังไม่ได้เลือก') ข้อความพร้อมปุ่ม OK อันเดียว

   2. ถ้าคลิ๊กเลือก x อันให้เมื่อกดปุ่ม Button ให้แสดง confirm('คุณต้องการเลือก X อันใช่ใหม ?') ข้อความพร้อมปุ่ม OK และ Cancel

Code html
   <p>      
   <asp:CheckBox ID="CheckBox1" onclick ="checkboxAction();" runat="server" />
    &nbsp;
    <input id="Text1" type="text" /></p>
    <p>
        <asp:CheckBox ID="CheckBox2" onclick ="checkboxAction();" runat="server" />
    &nbsp;&nbsp;
        </p>
    <p>
        <asp:CheckBox ID="CheckBox3" onclick ="checkboxAction();" runat="server" />
&nbsp;</p>
    <p>
        &nbsp;
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </p>


javascript 2 function
<script language="javascript" type="text/javascript">
      function checkboxAction() {
        var chk1 = document.getElementById('<%=CheckBox1.ClientID%>');
        var chk2 = document.getElementById('<%=CheckBox2.ClientID%>');
        var chk3 = document.getElementById('<%=CheckBox3.ClientID%>');
        var txt = document.getElementById('Text1');

        if (chk1.checked)
            a1 = 1;
        else
           a1 = 0;      /// lab1.innerHTML = parseInt(lab1.innerHTML) + 1

        if (chk2.checked)
            a2 = 1;
        else
            a2 = 0;

        if (chk3.checked)
            a3 = 1;
        else
            a3 = 0;
        txt.value = a1 + a2 + a3; //// lab1.innerHTML = a1 + a2 + a3;
    }

    function confirmalert(){
        if (document.getElementById('Text1').value == 0) {
            alert('คุณยังไม่ได้เลือก');
            return false;
        }
        else {
            return confirm('คุณต้องการเลือก ' + document.getElementById('Text1').value + ' อันใช้ใหม ?');
        }
    }
 </script>

ใน Form_Load
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim sConfirm As String = "return confirmalert();"
            Button1.Attributes.Add("OnClick", sConfirm)
        End If

    End Sub

วันจันทร์ที่ 10 มิถุนายน พ.ศ. 2556

Javascript - นับจำนวน Checkbox ที่ถูก Check

Javascript - นับจำนวน Checkbox ที่ถูก Check

    function checkboxAction() {
        var chk1 = document.getElementById('<%=CheckBox1.ClientID%>');
        var chk2 = document.getElementById('<%=CheckBox2.ClientID%>');
        var chk3 = document.getElementById('<%=CheckBox3.ClientID%>');
        var lab1 = document.getElementById('<%=Label1.ClientID%>');

        if (chk1.checked)
            a1 = 1;
        else
           a1 = 0;      /// lab1.innerHTML = parseInt(lab1.innerHTML) + 1

        if (chk2.checked)
            a2 = 1;
        else
            a2 = 0;

        if (chk3.checked)
            a3 = 1;
        else
            a3 = 0;
        lab1.innerHTML = a1 + a2 + a3;

    }

วันพฤหัสบดีที่ 6 มิถุนายน พ.ศ. 2556

ASP.net - เปลี่ยนวันที่ปัจจุบัน เป็นรูปแบบ US yyyy/MM/dd

เปลี่ยนวันที่ปัจจุบัน เป็นรูปแบบ US yyyy/MM/dd  เช่นใช้กับ SQL-server

d4 = Date.Parse(DateTime.Now, New Globalization.CultureInfo("th-TH"))
 Dim s4 As String = d4.ToString("yyyy/MM/dd", New Globalization.CultureInfo("en-US"))

asp.net - เปิด page ใหม่ใช้ ClientScrtpt

asp.net - เปิด page ใหม่ใช้ ClientScrtpt

 ClientScript.RegisterStartupScript(Me.Page.GetType(), "", "window.open('rptInvoice.aspx','Graph','height=900,width=720,left=0,top=0,menubar=0,status=1,scrollbars=1,resizable=1');", True)

ASP.net - ล้างค่าใน Label ทุกอันที่อยู่ใน form ASP.net

 สามารถดัดแปลงไปใช้กับ Textbox ได้เช่นกัน

Protected Sub ClearLabel(ByVal p1 As Control)
        For Each ctrl As Control In p1.Controls
            If TypeOf ctrl Is Label Then
                Dim t As Label = TryCast(ctrl, Label)

                If t IsNot Nothing Then
                    t.Text = [String].Empty
                End If
            Else
                If ctrl.Controls.Count > 0 Then
                    ClearLabel(ctrl)
                End If
            End If
        Next
    End Sub

วันเสาร์ที่ 1 มิถุนายน พ.ศ. 2556

java script ทำงานจากค่าของ checkbox

 java script ที่ทำงานจากค่าของ checkbox ในตัวอย่าง  checkbox1 ถูกคลิ๊ก   checkbox2 ก็ถูกติ๊กไปด้วย textbox1 ก็จะแสดงค่าไปด้วยกัน ที่สำคัญคือ ('<%=CheckBox1.ClientID%>')


   function checkboxAction() {
        var chk = document.getElementById('<%=CheckBox1.ClientID%>');
        var chk2 = document.getElementById('<%=CheckBox2.ClientID%>');
        var txt = document.getElementById('<%=TextBox1.ClientID%>');

        if (chk == null || txt == null)
            alert('Checkbox and/or textbox could not be found!');
        else {
            if (chk.checked) {
                txt.value = 'blah';
                chk2.checked = true
            }
            else {
                txt.value = 'hello';
                chk2.checked = false;
            }
        }
    }