Thứ Năm, 24 tháng 10, 2013

Dev: gridView1.SelectedRowsCount

tìm các row chọn selected

List<int> selected = new List<int>();
        private void chkSelect_CheckedChanged(object sender, EventArgs e)
        {
            CheckEdit chk = sender as CheckEdit;
            insupd(chk.Checked, Convert.ToInt32(gvNhanVien.GetRowCellValue(gvNhanVien.FocusedRowHandle, "Hrm_EmployeeID") + ""));
        }

        private void insupd(bool _flag, int _code)
        {
            if (_flag)
            {
                if (!selected.Contains(_code))
                    selected.Add(_code);
            }
            else
            {
                if (selected.Contains(_code))
                    selected.Remove(_code);
            }
        }


-------------------------------------- --------------------------------------
--------------------------------------  --------------------------------------
The following sample code can be used to get the value of the ID column within the third data row (this row's handle is equal to 2).
C#

VB

string cellValue;
cellValue = gridView1.GetRowCellValue(2, "ID").ToString();
 
 
// Create an empty list.
ArrayList rows = new ArrayList();
// Add the selected rows to the list.
for (int i = 0; i < gridView1.SelectedRowsCount; i++) {
   if (gridView1.GetSelectedRows()[i] >= 0)
      rows.Add(gridView1.GetDataRow(gridView1.GetSelectedRows()[i]));
}
try {
   gridView1.BeginUpdate();
   for (int i = 0; i < rows.Count; i++) {
      DataRow row = rows[i] as DataRow;
      // Change the field value.
      row["Discontinued"] = true;                             
   }
}
finally {
   gridView1.EndUpdate();
}    

 

How to get the GridView selected objects


0
To get all selected objects in the GridView, you should iterate via all selected rows, get row handles, and then by using the GetSelectedRows method get the selected row object itself.
See Also:
Selections Overview
Open in popup window
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1 {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
            list = new BindingList<MyObject>();

            for(int i = 0; i < 10; i++) {
                list.Add(new MyObject(i.ToString(),(i+10).ToString()));
            }
            bs = new BindingSource();
            bs.DataSource = list;

            gridControl1.DataSource = bs;

        }


        BindingSource bs;
        BindingList<MyObject> list;

        private void simpleButton1_Click(object sender, EventArgs e) {
            listBoxControl1.Items.Clear();
            for(int i = 0; i < gridView1.SelectedRowsCount; i++) {
                int row = (gridView1.GetSelectedRows()[i]);
                MyObject obj = gridView1.GetRow(row) as MyObject;
                if(obj == null) return;
                listBoxControl1.Items.Add(obj.Field2.ToString());
            }
        }

    }
    public class MyObject: INotifyPropertyChanged {
        public MyObject(string str1,string str2) {
            field1 = str1;
            field2 = str2;
        }
        private string field1;
        public string Field1 {
            get { return field1; }
            set {
                field1 = value;
                NotifyPropertyChanged("Field1");
            }
        }

        private string field2;
        public string Field2 {
            get { return field2; }
            set {
                field2 = value;
                NotifyPropertyChanged("Field2");
            }
        }


        #region INotifyPropertyChanged Members

        private void NotifyPropertyChanged(String info) {
            if (PropertyChanged != null) {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}

Thứ Ba, 15 tháng 10, 2013

GeoLite Free Downloadable Databases

Announcement

Free access to the latest in IP geolocation databases is now available in our GeoLite2 Databases.

Databases

IP Geolocation

The GeoLite databases are our free IP geolocation databases. They are updated on the first Tuesday of each month. These databases are offered in the same binary and csv formats as our subscription databases. Any code which can read the subscription databases can also read the GeoLite databases.
We publish accuracy statistics for GeoLite City.

Autonomous System Numbers

We offer free databases that map IPv4 and IPv6 addresses to Autonomous System Numbers (ASN), including the names of each Autonomous System. The databases are updated every month.

Support

MaxMind does not provide customer support for free GeoLite databases. If you have questions on how to use these databases, we suggest asking on Stack Overflow.

License

The GeoLite databases are distributed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. The attribution requirement may be met by including the following in all advertising and documentation mentioning features of or use of this database:

  This product includes GeoLite data created by MaxMind, available from
  <a href="http://www.maxmind.com">http://www.maxmind.com</a>.

We also offer commercial redistribution licensing.

Downloads


Download links
Database Binary / gzip Binary / xz CSV / gzip CSV / zip CSV / xz
GeoLite Country Download Gzip only Zip only Download Zip only
GeoLite Country IPv6 Download Gzip only Download Gzip only Gzip only
GeoLite City Download Download Zip and xz only Download Download
GeoLite City IPv6 (Beta) Download Gzip only Download Gzip only Gzip only
GeoLite ASN Download Gzip only Zip only Download Zip only
GeoLite ASN IPv6 Download Gzip only Zip only Download Zip only

Link website

Look Up a ZIP Code

 https://tools.usps.com/go/ZipLookupAction!input.action

http://dev.maxmind.com/geoip/legacy/geolite/

SQL CHUYỂN ĐỔI MÔ HÌNH E­R SANG MÔ HÌNH QUAN HỆ

http://tailieu.vn/doc/chuyen-doi-mo-hinh-e-r-sang-mo-hinh-quan-he.1299741.html
Chia sẻ: cuongbkav | Ngày: 02-12-2012
Các bước chuyển đổi mô hình ER sang mô hình quan hệ B1: Chuyển đổi các tập hợp thể thành các lược đồ quan hệ B2: Chuyển đổi mối quan hệ Is-a B3: Chuyển đối mối quan hệ nhị nguyên 1-1. B4: Chuyển đối mối quan hệ nhị nguyên 1-n. B5: Chuyển đối mối quan hệ nhị nguyên n-. B6: Chuyển đổi các mối quan hệ phản xạ. B7: Chuyển đổi mối quan hệ đa nguyên.

SQL linh tinh

16.
/****** Object:  UserDefinedFunction [dbo].[ConvertNumberToText]    Script Date: 30/12/2014 09:34:25 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*
 Tanldt
 Ngày: 05/07/2006
 Trả về số kiểu chữ:
 select dbo.ConvertNumberToText('10736918')
*/
ALTER    FUNCTION [dbo].[ConvertNumberToText](
 @Number VARCHAR(32)
)
RETURNS NVARCHAR(500)
AS
BEGIN
DECLARE @Text NVARCHAR(500)
DECLARE @Len INT
DECLARE @i INT
DECLARE @j INT
DECLARE @Flag VARCHAR(10)

SELECT @Len = LEN(LTRIM(RTRIM(@Number)))
SELECT @i = 1
SELECT @Text = ''

IF @Len > 32
BEGIN
 SELECT @Text = N'Số quá lớn. Không thể convert được!'
 RETURN @Text
END

WHILE @i <= @Len
BEGIN
 IF ((@Len - @i + 1)%3 = 0
  AND SUBSTRING(@Number, @i, 1) = '0'
  AND (SUBSTRING(@Number, @i + 1, 1) <> '0' OR SUBSTRING(@Number, @i + 2, 1) <> '0'))
  SELECT @Text = @Text + N' không'

 IF SUBSTRING(@Number, @i, 1) = '2'
  IF @i = 1
   SELECT @Text = @Text + N' Hai'
  else
   SELECT @Text = @Text + N' hai'
 IF SUBSTRING(@Number, @i, 1) = '3'
  IF @i = 1
   SELECT @Text = @Text + N' Ba'
  ELSE
   SELECT @Text = @Text + N' ba'
 IF SUBSTRING(@Number, @i, 1) = '4'
  IF @i = 1
   SELECT @Text = @Text + N' Bốn'
  ELSE
   SELECT @Text = @Text + N' bốn'
 IF SUBSTRING(@Number, @i, 1) = '6'
  IF @i = 1
   SELECT @Text = @Text + N' Sáu'
  ELSE
   SELECT @Text = @Text + N' sáu'
 IF SUBSTRING(@Number, @i, 1) = '7'
  IF @i = 1
   SELECT @Text = @Text + N' Bảy'
  ELSE
   SELECT @Text = @Text + N' bảy'
 
 IF SUBSTRING(@Number, @i, 1) = '8'
  IF @i = 1
   SELECT @Text = @Text + N' Tám'
  ELSE
   SELECT @Text = @Text + N' tám'
 
 IF SUBSTRING(@Number, @i, 1) = '9'
  IF @i = 1
   SELECT @Text = @Text + N' Chín'
  ELSE
   SELECT @Text = @Text + N' chín'

 IF SUBSTRING(@Number, @i, 1) = '5'
  IF @i = 1
   SELECT @Text = @Text + N' Năm'
  ELSE
  
   BEGIN
 
    IF (@i > 0 AND (@Len - @i + 1)%3 = 1 AND SUBSTRING(@Number, @i - 1, 1) <> '0')
     SELECT @Text = @Text + N' lăm'
    ELSE SELECT @Text = @Text + N' năm'  
   END

 IF (@i > 1 AND SUBSTRING(@Number, @i, 1) = '1' AND (@Len - @i + 1)%3 = 1 AND SUBSTRING(@Number, @i - 1, 1) > '1')
  SELECT @Text = @Text + N' mốt'
 ELSE
   IF ((@Len - @i + 1)%3 <> 2 AND SUBSTRING(@Number, @i, 1) = '1')
   SELECT @Text = @Text + N' Một'

 IF ((@Len - @i + 1)%3 = 2 AND SUBSTRING(@Number, @i, 1) <> '0' AND SUBSTRING(@Number, @i, 1) <> '1')
  SELECT @Text = @Text + N' mươi'
 ELSE
  IF ((@Len - @i + 1)%3 = 2 AND SUBSTRING(@Number, @i, 1) <> '0')
  SELECT @Text = @Text + N' Mười'

 IF ((@Len - @i + 1)%3 = 2 AND SUBSTRING(@Number, @i, 1) = '0' AND SUBSTRING(@Number, @i + 1, 1) <> '0') SELECT @Text = @Text + N' lẻ'

 IF ((@Len - @i + 1)%3 = 0 AND (SUBSTRING(@Number, @i + 1, 1) <> '0' OR SUBSTRING(@Number, @i + 2, 1) <> '0'))
  SELECT @Text = @Text + N' trăm'
 ELSE IF ((@Len - @i + 1)%3 = 0 AND SUBSTRING(@Number, @i, 1) <> '0')
  SELECT @Text = @Text + N' trăm'

 IF ((@Len - @i + 1) = 4)
  SELECT @Text = @Text + N' nghìn'
 IF ((@Len - @i + 1) = 7)
  SELECT @Text = @Text + N' triệu'
 IF ((@Len - @i + 1) = 10)
  SELECT @Text = @Text + N' tỷ'
 IF ((@Len - @i + 1) = 13)
  SELECT @Text = @Text + N' nghìn tỷ'
 IF ((@Len - @i + 1) = 16)
  SELECT @Text = @Text + N' triệu tỷ'
 IF ((@Len - @i + 1) = 19)
  SELECT @Text = @Text + N' tỷ tỷ'
 IF ((@Len - @i + 1) = 22)
  SELECT @Text = @Text + N' triệu tỷ tỷ'
 IF ((@Len - @i + 1) = 25)
  SELECT @Text = @Text + N' tỷ tỷ tỷ'
 IF ((@Len - @i + 1) = 28)
  SELECT @Text = @Text + N' triệu tỷ tỷ tỷ'

 IF ((@Len - @i + 1)%3 = 0 AND SUBSTRING(@Number, @i, 1) = '0' AND SUBSTRING(@Number, @i + 1, 1) = '0' AND SUBSTRING(@Number, @i + 2, 1) = '0')
  SELECT @i = @i + 2

 IF (@Len - @i + 1)%3 = 1
 BEGIN
  SELECT @Flag = 'True'

  SELECT @j = @i

  WHILE @j <= @Len
  BEGIN
   IF SUBSTRING(@Number, @j, 1) <> '0'
    SELECT @Flag = 'False'
   SELECT @j = @j + 1
  END
 END

 IF @Flag = 'True'
  BREAK

 SELECT @i = @i + 1
END

 --QuangPNV
 if(LEN(@Text) > 0)
 begin
  set @Text = LOWER(@Text)
  set @Text = UPPER(LEFT(RTRIM(LTRIM(@Text)),1)) + RIGHT(RTRIM(LTRIM(@Text)),LEN(LTRIM(RTRIM(@Text))) - 1)
 end
RETURN @Text
END

15 tuyệt chiêu khó nhất của SQL transaction phiên
BEGIN TRANSACTION Tran_Test;
 UPDATE _Test SET [content] = 'bang téttt'

 IF @@ERROR != 0  -- neu co loi xay ra, rollback
 BEGIN
      PRINT 'rollback ne';
      ROLLBACK TRAN Tran_Test;
 END

 -----------------

BEGIN TRANSACTION Tran_Test2;
 UPDATE _ABC SET noidung = 'noidung'
 IF @@ERROR != 0  -- neu co loi xay ra, rollback
 BEGIN
      PRINT 'rollback ne';
      ROLLBACK TRAN Tran_Test2;
 END


 ROLLBACK TRAN Tran_Test;


--
declare @Tran_Test as varchar(20)
set @Tran_Test='Tran_Test'

declare @Tran_Test2 as varchar(20)
set @Tran_Test2='Tran_Test2'


Commit TRANSACTION @Tran_Test

Commit TRANSACTION @Tran_Test2



14.
UPDATE
    Table
SET
    Table.col1 = other_table.col1,
    Table.col2 = other_table.col2
FROM
    Table
INNER JOIN
    other_table
ON
    Table.id = other_table.id

13.
ALTER PROCEDURE [dbo].[発番_チェック] --Numbering_Check
@kid char(2),
@dno varchar(9) OUTPUT
AS
       INSERT INTO 発番管理(kanriID,odrDay,intSeq) VALUES(@kid,@oday,1) --Qun lý đánh STT đơn hàng
       SET @seq = 1
SET  @dno =RIGHT(@oday+RIGHT(1000 + @seq,3),9)

12. Delete same xóa trùng http://www.codeproject.com/Articles/157977/Remove-Duplicate-Rows-from-a-Table-in-SQL-Server

Remove Duplicate Rows from a Table in SQL Server


, 16 Feb 2011 CPOL
Easiest way to delete more than one duplicate row from a table in SQL Server

Introduction

Most of the times, we use primary key or unique key for preventing insertion of duplicate rows in SQL Server. But if we don't use these keys, then it's obvious that duplicate rows could be entered by the user. After inserting duplicate rows into table, it becomes a major issue to delete those duplicate rows. In that time, we need to delete those duplicate rows to resolve the issue. So this topic will help us to delete those duplicate rows from the specific table.

Background

I used some basic T-SQL code to accomplish the target. So you don't need to worry to understand this code.

Problem

Firstly, we will create a table, where we will insert some duplicate rows to understand the topic properly. Create a table called ATTENDANCE by using the following code:
CREATE TABLE [dbo].[ATTENDANCE](
 [EMPLOYEE_ID] [varchar](50) NOT NULL,
 [ATTENDANCE_DATE] [date] NOT NULL
) ON [PRIMARY]   
Now insert some data into this table.
INSERT INTO dbo.ATTENDANCE (EMPLOYEE_ID,ATTENDANCE_DATE)VALUES
   ('A001',CONVERT(DATETIME,'01-01-11',5)) 
INSERT INTO dbo.ATTENDANCE (EMPLOYEE_ID,ATTENDANCE_DATE)VALUES
   ('A001',CONVERT(DATETIME,'01-01-11',5)) 
INSERT INTO dbo.ATTENDANCE (EMPLOYEE_ID,ATTENDANCE_DATE)VALUES
   ('A002',CONVERT(DATETIME,'01-01-11',5)) 
INSERT INTO dbo.ATTENDANCE (EMPLOYEE_ID,ATTENDANCE_DATE)VALUES
   ('A002',CONVERT(DATETIME,'01-01-11',5)) 
INSERT INTO dbo.ATTENDANCE (EMPLOYEE_ID,ATTENDANCE_DATE)VALUES
   ('A002',CONVERT(DATETIME,'01-01-11',5)) 
INSERT INTO dbo.ATTENDANCE (EMPLOYEE_ID,ATTENDANCE_DATE)VALUES
   ('A003',CONVERT(DATETIME,'01-01-11',5)) 
After inserting the data, check the data of the below table. If we grouped the employee_id and attendance_date, then A001 and A002 become duplicates.
EMPLOYEE_ID ATTENDANCE_DATE
A001 2011-01-01
A001 2011-01-01
A002 2011-01-01
A002 2011-01-01
A002 2011-01-01
A003 2011-01-01
So how can we delete those duplicate data?

Solution

First, insert an identity column in that table by using the following code:
ALTER TABLE dbo.ATTENDANCE ADD AUTOID INT IDENTITY(1,1)  
Now the table data will be like the following table:
EMPLOYEE_ID ATTENDANCE_DATE AUTOID
A001 2011-01-01 1
A001 2011-01-01 2
A002 2011-01-01 3
A002 2011-01-01 4
A002 2011-01-01 5
A003 2011-01-01 6
Check the AUTOID column. Now we will start playing the game with this column.
Now use the following code to find out the duplicate rows that exist in the table.
SELECT * FROM dbo.ATTENDANCE WHERE AUTOID NOT IN (SELECT MIN(AUTOID) _
 FROM dbo.ATTENDANCE GROUP BY EMPLOYEE_ID,ATTENDANCE_DATE)  
The above code will give us the following result:
EMPLOYEE_ID ATTENDANCE_DATE AUTOID
A001 2011-01-01 2
A002 2011-01-01 4
A002 2011-01-01 5
Ultimately, these are the duplicate rows which we want to delete to resolve the issue. Use the following code to resolve it.
DELETE FROM dbo.ATTENDANCE WHERE AUTOID NOT IN (SELECT MIN(AUTOID) _
 FROM dbo.ATTENDANCE GROUP BY EMPLOYEE_ID,ATTENDANCE_DATE) 
Now check the data. No duplicate rows exist in the table.
Is it too complicated?

11. A chương chuong SQL

DECLARE @barchID AS  INT
SET @barchID =78

  SELECT  dp.[Order], dp.DegreeName, SL =  COUNT(he.DegreeCode) 
  FROM Hrm_Employee he 
  LEFT JOIN Dic_Degree  dp ON he.DegreeCode = dp.Dic_DegreeID 
   WHERE he.Active = 1 
  AND (ISNULL(@barchID,0)  =  ''  OR  (ISNULL(@barchID,0)  <>  0  AND  he.Hrm_BranchID =   RTRIM(@barchID)))
  AND he.Hrm_BranchID=@barchID
  
  GROUP BY dp.[Order],  dp.DegreeName 
  HAVING COUNT(he.DegreeCode) > 0
  ORDER BY dp.[Order]

  SELECT  *  FROM  Hrm_TimeKeeper_TableList htktl

SELECT  *  FROM  Hrm_TimeKeeper_Shift htks WHERE  htks.Hrm_TimeKeeperTableListID=63

DELETE  FROM  Hrm_TimeKeeper_Shift WHERE  Hrm_TimeKeeperTableListID =  63


     select Hrm_EmployeeID, EmployeeCode, LastName +' '+FirstName, LaborFrom from Hrm_Employee
    
    select * from Hrm_Employee  where LastName like N'%Lê Thị Kim%'             -- and Hrm_BranchID=78
  
    update Hrm_Employee set Dic_Work_StatusID=7  where LastName +' '+FirstName like N'%Đặng xuân trường%' and Hrm_BranchID=78
    update Hrm_Employee set Dic_Work_StatusID=6  where Hrm_EmployeeID in(2861) and Hrm_BranchID=78
  
     select * from Hrm_Employee where  Hrm_BranchID=78
     where EmployeeCode like '%03304000%'
     LastName like N'%Lê minh%' and
    
   delete  Hrm_Employee      where LastName like N'%Giáng sinh%' and Hrm_BranchID=78

10. If you want to disable all constraints in the database just run this code:
-- disable all constraints
EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"
To switch them back on, run: (the print is optional of course and it is just listing the tables)
-- enable all constraints
exec sp_msforeachtable @command1="print '?'", @command2="ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"


9. ALTER TABLE SchoolFee DISABLE TRIGGER trigger_Update_SchoolFee
ALTER TABLE SchoolFee ENABLE TRIGGER trigger_Update_SchoolFee
8.
CREATE TRIGGER trigger_name ON tablename
FOR UPDATE
AS
SET NOCOUNT ON
IF ( UPDATE(Column1) OR UPDATE(Column2))
BEGIN
  your sql here
END
 

Số thứ tự so thu tu    STT
    SELECT * FROM (
      SELECT
        ROW_NUMBER() OVER (ORDER BY DateCode ASC) AS rownumber,
        DateCode, ClassID
      FROM Schedule
    ) AS foo
    WHERE rownumber <= 3

7.
DECLARE @IntVariable int;
DECLARE @SQLString nvarchar(500);
DECLARE @ParmDefinition nvarchar(500);

/* Build the SQL string one time.*/
SET @SQLString =
     N'SELECT BusinessEntityID, NationalIDNumber, JobTitle, LoginID
       FROM AdventureWorks2012.HumanResources.Employee 
       WHERE BusinessEntityID = @BusinessEntityID';
SET @ParmDefinition = N'@BusinessEntityID tinyint';
/* Execute the string with the first parameter value. */
SET @IntVariable = 197;
EXECUTE sp_executesql @SQLString, @ParmDefinition,
                      @BusinessEntityID = @IntVariable;
/* Execute the same string with the second parameter value. */
SET @IntVariable = 109;
EXECUTE sp_executesql @SQLString, @ParmDefinition,
                      @BusinessEntityID = @IntVariable;
Output parameters can also be used with sp_executesql. The following example retrieves a job title from the AdventureWorks2012.HumanResources.Employee table and returns it in the output parameter @max_title.
DECLARE @IntVariable int;
DECLARE @SQLString nvarchar(500);
DECLARE @ParmDefinition nvarchar(500);
DECLARE @max_title varchar(30);

SET @IntVariable = 197;
SET @SQLString = N'SELECT @max_titleOUT = max(JobTitle) 
   FROM AdventureWorks2012.HumanResources.Employee
   WHERE BusinessEntityID = @level';
SET @ParmDefinition = N'@level tinyint, @max_titleOUT varchar(30) OUTPUT';

EXECUTE sp_executesql @SQLString, @ParmDefinition, @level = @IntVariable, @max_titleOUT=@max_title OUTPUT;
SELECT @max_title;

6.                       CASE
                      WHEN dbo.SchoolFee.MonthSchoolFee IS NOT NULL THEN
                           SUBSTRING(CAST(dbo.SchoolFee.MonthSchoolFee AS CHAR(6)),5, 2) + '/' + SUBSTRING(CAST(dbo.SchoolFee.MonthSchoolFee AS CHAR(6)), 1, 4)
                           END AS 'MonthSchoolFee',


                      CASE dbo.SchoolFee.MonthSchoolFee
                      WHEN NULL THEN ''
                      ELSE
                           SUBSTRING(CAST(dbo.SchoolFee.MonthSchoolFee AS CHAR(6)),5, 2) + '/' + SUBSTRING(CAST(dbo.SchoolFee.MonthSchoolFee AS CHAR(6)), 1, 4)
                           END AS 'MonthSchoolFee',
5.
    Declare Tb_Cur Cursor
    For    Select Hrm_EmployeeID From [#tem_TKNS]
    Open Tb_Cur
    Fetch Next From Tb_Cur Into @Hrm_EmployeeID
    While @@FETCH_STATUS = 0
        Begin
             SELECT TOP (1) @ResolutionCoefficient=ResolutionCoefficient, @TitleCoefficient=TitleCoefficient
             FROM Hrm_Contract WHERE EmployeeID=@Hrm_EmployeeID AND IsCurrent=1
             --
             --select @ResolutionCoefficient AS 'here'
             UPDATE [#tem_TKNS] SET ResolutionCoefficient=@ResolutionCoefficient, TitleCoefficient=@TitleCoefficient
             WHERE     Hrm_EmployeeID=@Hrm_EmployeeID  
            Fetch Next From Tb_Cur Into @Hrm_EmployeeID
        End  
    Close Tb_Cur;
    Deallocate Tb_Cur;
4.
Date Format Standard SQL Statement Sample Output
Mon DD YYYY 1
HH:MIAM (or PM)
Default SELECT CONVERT(VARCHAR(20), GETDATE(), 100) Jan 1 2005 1:29PM 1
MM/DD/YY USA SELECT CONVERT(VARCHAR(8), GETDATE(), 1) AS [MM/DD/YY] 11/23/98
MM/DD/YYYY USA SELECT CONVERT(VARCHAR(10), GETDATE(), 101) AS [MM/DD/YYYY] 11/23/1998
YY.MM.DD ANSI SELECT CONVERT(VARCHAR(8), GETDATE(), 2) AS [YY.MM.DD] 72.01.01
YYYY.MM.DD ANSI SELECT CONVERT(VARCHAR(10), GETDATE(), 102) AS [YYYY.MM.DD] 1972.01.01
DD/MM/YY British/French SELECT CONVERT(VARCHAR(8), GETDATE(), 3) AS [DD/MM/YY] 19/02/72
DD/MM/YYYY British/French SELECT CONVERT(VARCHAR(10), GETDATE(), 103) AS [DD/MM/YYYY] 19/02/1972
DD.MM.YY German SELECT CONVERT(VARCHAR(8), GETDATE(), 4) AS [DD.MM.YY] 25.12.05
DD.MM.YYYY German SELECT CONVERT(VARCHAR(10), GETDATE(), 104) AS [DD.MM.YYYY] 25.12.2005
DD-MM-YY Italian SELECT CONVERT(VARCHAR(8), GETDATE(), 5) AS [DD-MM-YY] 24-01-98
DD-MM-YYYY Italian SELECT CONVERT(VARCHAR(10), GETDATE(), 105) AS [DD-MM-YYYY] 24-01-1998
DD Mon YY 1 - SELECT CONVERT(VARCHAR(9), GETDATE(), 6) AS [DD MON YY] 04 Jul 06 1
DD Mon YYYY 1 - SELECT CONVERT(VARCHAR(11), GETDATE(), 106) AS [DD MON YYYY] 04 Jul 2006 1
Mon DD, YY 1 - SELECT CONVERT(VARCHAR(10), GETDATE(), 7) AS [Mon DD, YY] Jan 24, 98 1
Mon DD, YYYY 1 - SELECT CONVERT(VARCHAR(12), GETDATE(), 107) AS [Mon DD, YYYY] Jan 24, 1998 1
HH:MM:SS - SELECT CONVERT(VARCHAR(8), GETDATE(), 108) 03:24:53
Mon DD YYYY HH:MI:SS:MMMAM (or PM) 1 Default +
milliseconds
SELECT CONVERT(VARCHAR(26), GETDATE(), 109) Apr 28 2006 12:32:29:253PM 1
MM-DD-YY USA SELECT CONVERT(VARCHAR(8), GETDATE(), 10) AS [MM-DD-YY] 01-01-06
MM-DD-YYYY USA SELECT CONVERT(VARCHAR(10), GETDATE(), 110) AS [MM-DD-YYYY] 01-01-2006
YY/MM/DD - SELECT CONVERT(VARCHAR(8), GETDATE(), 11) AS [YY/MM/DD] 98/11/23
YYYY/MM/DD - SELECT CONVERT(VARCHAR(10), GETDATE(), 111) AS [YYYY/MM/DD] 1998/11/23
YYMMDD ISO SELECT CONVERT(VARCHAR(6), GETDATE(), 12) AS [YYMMDD] 980124
YYYYMMDD ISO SELECT CONVERT(VARCHAR(8), GETDATE(), 112) AS [YYYYMMDD] 19980124
DD Mon YYYY HH:MM:SS:MMM(24h) 1 Europe default + milliseconds SELECT CONVERT(VARCHAR(24), GETDATE(), 113) 28 Apr 2006 00:34:55:190 1
HH:MI:SS:MMM(24H) - SELECT CONVERT(VARCHAR(12), GETDATE(), 114) AS [HH:MI:SS:MMM(24H)] 11:34:23:013
YYYY-MM-DD HH:MI:SS(24h) ODBC Canonical SELECT CONVERT(VARCHAR(19), GETDATE(), 120) 1972-01-01 13:42:24
YYYY-MM-DD HH:MI:SS.MMM(24h) ODBC Canonical
(with milliseconds)
SELECT CONVERT(VARCHAR(23), GETDATE(), 121) 1972-02-19 06:35:24.489
YYYY-MM-DDTHH:MM:SS:MMM ISO8601 SELECT CONVERT(VARCHAR(23), GETDATE(), 126) 1998-11-23T11:25:43:250
DD Mon YYYY HH:MI:SS:MMMAM 1 Kuwaiti SELECT CONVERT(VARCHAR(26), GETDATE(), 130) 28 Apr 2006 12:39:32:429AM 1
DD/MM/YYYY HH:MI:SS:MMMAM Kuwaiti SELECT CONVERT(VARCHAR(25), GETDATE(), 131) 28/04/2006 12:39:32:429AM

3. convert datetime to date chuyển đổi sql server
 SELECT CONVERT(VARCHAR(8), GETDATE(), 3) AS [DD/MM/YY]
 ------------------
2.  SELECT CONVERT(VARCHAR(10), GETDATE(), 103) AS [DD/MM/YYYY]

DECLARE @identity AS INT
SET @identity=0
Set nocount on
Insert into Process_Reward (RecipientID,PersonID,RewardCode,Foundation,Reason,Object,Form,Source,TotalValue,Status,Date,DecideNumber,DecideDate,Active)
values(@RecipientID,@PersonID,@RewardCode,@Foundation,@Reason,@Object,@Form,@Source,@TotalValue,@Status,@Date,@DecideNumber,@DecideDate,@Active)
SET @identity=@@IDENTITY

INSERT INTO Process_Reward_Employee
(
    EmployeeID,
    Process_RewardID, ACTIVE
)
VALUES
(
    @EmployeeID, @identity, 'TRUE'
)
return @@identity
............
Update Process_Reward set RecipientID=@RecipientID,PersonID=@PersonID,RewardCode=@RewardCode,Foundation=@Foundation,Reason=@Reason,Object=@Object,Form=@Form,Source=@Source,TotalValue=@TotalValue,Status=@Status,Date=@Date,DecideNumber=@DecideNumber,DecideDate=@DecideDate,Active=@Active
 where Process_RewardID=@Process_RewardID
exec USP_Process_Reward_Employee_Update  @EmployeeID, @Process_RewardID, 'TRUE'
...........

Thứ Hai, 14 tháng 10, 2013

.NET Using a delegate to pass data between two forms

Truyền dữ liệu giữa 2 form nhập cha con

Introduction

This code demonstrates how you can pass data from one form to another using a delegate. The advantage of using a delegate is that the form from which you want to send the data, doesn't need to know anything about the form that it's sending its data to. This way, you can reuse the same form in other forms or applications.

Details

This is form 1. From this form we display form 2. And from form 2 we send a TextBox back to form 1.

And the code for form 1:
private void btnForm1_Click(object sender, System.EventArgs e)
{
    // Create an instance of form 2
    Form2 form2 = new Form2();
 
    // Create an instance of the delegate
    form2.passControl = new Form2.PassControl(PassData);
 
    // Show form 2
    form2.Show();
}
 
private void PassData(object sender)
{
    // Set de text of the textbox to the value of the textbox of form 2
    txtForm1.Text = ((TextBox)sender).Text;
}

Form 2 sends the TextBox back to form 1:

public class Form2 : System.Windows.Forms.Form
{
    // Define delegate
    public delegate void PassControl(object sender);
 
    // Create instance (null)
    public PassControl passControl;
 
    private void btnForm2_Click(object sender, System.EventArgs e)
    {
        if (passControl != null)
        {
            passControl(txtForm2);
        {
        this.Hide();
    }
}
Of course, using the delegate, you can not only send back the textbox, but other controls, variables or even the form itself, because they are all objects. I hope this is useful.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here

......

format string

1. Hiển thị thông báo messagebox đầy đủ các nút thông báo      
 if (XtraMessageBox.Show(Common.msgDeleteQuestion, "Cảnh báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
        {
            f_MQH_DeleteData();
        }
 2. LookupEdit Lookup Edit hiện thị ngày trước tháng năm Run designer /Columns/displayformat FieldName dd/MM/yyyy datetime

3. Sử dụng button bên combobox

        private void lookUpEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            ButtonEdit edit = (ButtonEdit)sender;
            if (edit.Properties.Buttons.IndexOf(e.Button) == 1)
            {
                MessageBox.Show("Them ngach luong");
            }
        }
4. Gridcontrol auto column hiển thị dữ liệu dài gridview/OptionsView và chọn ColumnAutoWidth sau đó kéo thả hoặc set size
5. Bản 12 có sự kiện  rowclick dùng thay cho 2 sự kiện ở bản 8
6. Hiển thị dữ liệu các cột khác comboxbox lookupedit
        object row = lookUpBacLuong.Properties.GetDataSourceRowByKeyValue(lookUpBacLuong.EditValue);
        if (row != null)
        {
            txtHeSoLuong.Text = ((DataRowView)row)["Coefficient"].ToString();
        }

7. upload file  sử dụng buttonedit properties kind Glyph Image chọn hình biểu tượng icon
8. Tìm kiếm like một từ bất kỳ ký tự cột control grid view Option AutoFilterCondition Chọn Like/Contains

Devexpress

2.checkbox in trong grid gridview









Tìm tổng số dòng trong lookupEdit    
   int idLoc = lookUpDaoTao_TenKhoaHoc.ItemIndex;

        int TotalLoc = ((IListSource)lookUpDaoTao_TenKhoaHoc.Properties.DataSource).GetList().Count;
        if (idLoc < TotalLoc)
            lookUpDaoTao_TenKhoaHoc.ItemIndex = idLoc + 1;
        else
            lookUpDaoTao_TenKhoaHoc.ItemIndex = idLoc - 1;
        Random rnd = new Random();
        txtDaoTao_SoBuoiCoMat.Text = rnd.Next(13, 50).ToString(); // creates a number between 13 and 50
        calcEditDaoTao_SoBuoiNghiHoc.Value = rnd.Next(3, 1




0
    • I found an article in your knowledge base that describes how to get a number of items of lookupEdit but in C#. Althrough i am C# programmer too i couldn't convert this code to VB.NET
      int count = (dxLookUpEdit.Properties.DataSource as IList).Count;
      I came with this at the end but it throws an exception: Unable to cast object of type 'System.Data.DataTable' to type 'System.Collections.IList'.
      Dim count% = (CType(dxLookUpEdit.Properties.DataSource, IList)).Count
      I have also tried by using ConversionHelpers.AsWorkaround method but obviously it wasn't solution as well.
      Thanks in advance for any assistance :)

0
Hello,
In order to avoid duplicate issue i want to answer about an another problem i have with lookUpEdit control. Namely ti works just fine like this (without touching anything in design view):
dt = New DataTable
da = New OleDb.OleDbDataAdapter("SELECT ID, Title FROM tblVideo ORDER BY Title ASC", oledbcon)
cb = New OleDb.OleDbCommandBuilder(da)
da.Fill(dt)
Me.dxLookUpEdit.Properties.DataSource = dt
Me.dxLookUpEdit.Properties.DisplayMember = dt.Columns(1).ToString
Me.dxLookUpEdit.Properties.ValueMember = dt.Columns(0).ToString
but i want to change the column's captions so i've done something like this:
dt = New DataTable
da = New OleDb.OleDbDataAdapter("SELECT ID, Title FROM tblVideo ORDER BY Title ASC", oledbcon)
cb = New OleDb.OleDbCommandBuilder(da)
da.Fill(dt)
Dim myCol1 As New DevExpress.XtraEditors.Controls.LookUpColumnInfo()
myCol1.Caption = "Movie #"
myCol1.FieldName = "Col1"
Dim myCol2 As New DevExpress.XtraEditors.Controls.LookUpColumnInfo()
myCol2.Caption = "Movie Title"
myCol2.FieldName = "Col2"
Me.dxLookUpEdit.Properties.Columns.Add(myCol1)
'Me.dxLookUpEdit.Properties.Columns.Add(myCol2)
Me.dxLookUpEdit.Properties.DataSource = dt
Me.dxLookUpEdit.Properties.DisplayMember = dt.Columns(1).ToString
Me.dxLookUpEdit.Properties.ValueMember = dt.Columns(0).ToString
From the beginning i thought that there is nothing ... no records/items but then i noticed that if i pop up the control althrough i cannot see the text i can select the items. After i select an item it appears just fine in the lookUpEdit control. Why this happens and how to resolve the same?
Thanks :)

0
Hi Neal,
When you use the DataTable as the LookUpEdit datasource, you should explicitly cast it to IListSource since it does not implement it itself.
Dim count% = CType(dxLookUpEdit.Properties.DataSource, IListSource).GetList().Count
As for the second question, you should set LookUpEdit columns' FieldName exactly to the fieldname of a datasource used in it:
Dim myCol1 As New DevExpress.XtraEditors.Controls.LookUpColumnInfo()
myCol1.Caption = "Movie #"
myCol1.FieldName = dt.Columns(0).ColumnName
Me.dxLookUpEdit.Properties.Columns.Add(myCol1)
Please let us know if this helps.
Thanks,
Michael.

0
Perfect !!!
Thanks for the suggestions.
But, honestly this controls differ too much from the standard controls that come with VS.NET.
Sometimes i feel like i am n00b programer who just started to learn a new VS.NET IDE.
However as they looks amazing it is worthy for the effort.
Regards ;)

0
Hi Neal,
I am happy to hear that my assistance was helpful to you.
Thanks,
Michael.
.........