当前位置:  编程技术>.net/c#/asp.net
本页文章导读:
    ▪委托编号大排行(自动生成)       委托编号大排行(自动生成):效果:描述:在本表中自动生成编号,自动生成的编号为所有表中的排序。例如:在添加页面中生成的委托编号未00048,那么在别的表中生成的编号为00049。.........
    ▪用户自己排序记录       某一些情况,我们开发时,不能以添加先后进行排序,也不能以某一字段进行升序或降序排序。只好让用户自己排序。此篇就是以此要求,进行演示的。数据表中,应有此排序的字段,可.........
    ▪【转载】C# LINQ to SQL      1、Concat(连接不同的集合不会自动过滤相同项。会延迟计算) var q = (from c in db.Customers select c.Phone ).Concat( from e in db.Employees select e.HomePhone); var q = (from c in db.Cust.........

[1]委托编号大排行(自动生成)
    来源:    发布时间: 2013-10-28

 

委托编号大排行(自动生成):

效果:

描述:在本表中自动生成编号,自动生成的编号为所有表中的排序。例如:在添加页面中生成的委托编号未00048,那么在别的表中生成的编号为00049。

调用:

1 protected void Page_Load(object sender, EventArgs e)
2 {
3 Response.Expires = -1;
4 if (!IsPostBack)
5 {
6
7 if (ActionType == CommonEnum.ActionLevel.Write)
8 {
9
10 tbwtbh.Text = Getwtbh();
11
12 }
13 }
14 }
15
16 protected string Getwtbh()
17 {
18 string Getwtbh = CommonFunction.GetByMenuCode(ThisPositionID, ApplicationInfo.SerialNumWt, "qjlzhuan_lydj", "wtbh");
19 return Getwtbh;
20 }

函数:

1 #region 委托编号大排行
2
3 public static string GetByMenuCode(string ThisPositionID, int Digit, string TableName, string RowName)
4 {
5 string GetCode = string.Empty;
6 string Title = string.Empty;
7 string sql = string.Format(@"SELECT Max(RIGHT({0}," + Digit + ")) as RowName FROM {1}; " +
8 "SELECT LEFT(Max({2}),LEN(Max({2}))-" + Digit + ") as RowTitle FROM {3}", "wtbhCode", "wtbh", RowName, TableName);
9 DbCommand sqlCommand = ERPDataBase.ERPDB.GetSqlStringCommand(sql);
10 DataSet dsData = new DataSet();
11 ERPDataBase.ERPDB.LoadDataSet(sqlCommand, dsData, new string[] { "data", "Title" });
12 if (dsData.Tables["data"].Rows.Count > 0)
13 {
14 DataRow row = dsData.Tables["data"].Rows[0];
15 if (row["RowName"] == DBNull.Value)
16 {
17 GetCode = "1";
18 GetCode = GetCode.PadLeft(Digit, '0');
19 }
20 else
21 {
22 string second = row["RowName"].ToString();
23 GetCode = second.PadLeft(Digit, '0');
24 }
25 }
26 if (dsData.Tables["Title"].Rows.Count > 0)
27 {
28 DataRow row = dsData.Tables["Title"].Rows[0];
29 if (row["RowTitle"] != DBNull.Value)
30 {
31 Title = row["
    
[2]用户自己排序记录
    来源:    发布时间: 2013-10-28

 某一些情况,我们开发时,不能以添加先后进行排序,也不能以某一字段进行升序或降序排序。只好让用户自己排序。此篇就是以此要求,进行演示的。

数据表中,应有此排序的字段,可以根据记录的多少来定义它的数据类型,如INT等。数据的存储过程,应该应用到事务。以怕异常出现,而出现断序现象。

在添加时,应该找到存在记录中,最大的序号,如第一次添加,即是说最大记录为空,那它的的值为1。

在更新时,需要处理用户输入小于或等于 0值,它真正的值是1;而输入大于 最大排序号时,它应该于最大值。

 在删除时,应该是比被删除记录的排序号大的,都应该减1。

Insus.NET实现的效果如下:

 创建数据表

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Insus.NET
-- Create date: 2013-01-10
-- Description: 创建目录表
-- ============================================
CREATE TABLE [dbo].[Catalog](
[Catalog_nbr] [smallint] IDENTITY(1,1) NOT NULL,
[CatalogName] [nvarchar](100) NOT NULL,
[IsActive] [bit] NOT NULL,
[Sort] [int] NOT NULL,
[CreateBy] [nvarchar](30) NOT NULL,
[CreateDate] [datetime] NOT NULL,
[UpdateBy] [nvarchar](30) NOT NULL,
[UpdateDate] [datetime] NOT NULL,
PRIMARY KEY CLUSTERED
(
[Catalog_nbr] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
UNIQUE NONCLUSTERED
(
[CatalogName] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[Catalog] ADD DEFAULT ((1)) FOR [IsActive]
GO

ALTER TABLE [dbo].[Catalog] ADD DEFAULT (getdate()) FOR [CreateDate]
GO

ALTER TABLE [dbo].[Catalog
    
[3]【转载】C# LINQ to SQL
    来源:    发布时间: 2013-10-28

1、Concat(连接不同的集合不会自动过滤相同项。会延迟计算)

var q = (from c in db.Customers
select c.Phone
).Concat(
from e in db.Employees
select e.HomePhone);
var q = (from c in db.Customers
select new
{
Name = c.CustomerName,
Phone = c.Phone
}).Concat(
from e in db.Employees
select new
{
Name = e.EmployeeName,
Phone = e.HomePhone
});

 

2、Union(合并,自动过滤相同的项。会延迟计算)

var q = (from c in db.Customers
select c.Country).Union(
from e in db.Employees
select e.Country);

 

3、Intersect(交。会延迟计算)

var q = (from c in db.Customers
select c.Country).Intersect(
from e in db.Employees
select e.Country);
 

4、Except(差,A-B。从A集合排除A交B。会延迟计算)

var q = (from c in db.Customers
select c.Country).Except(
from e in db.Employees
select e.Country);

 

5、Top、Bottom(取出指定数量的数据。会延迟计算)

 

6、Take(获取集合的前n个数据。会延迟计算)

var q = (from e in db.Employees
orderby e.HireDate
selct e).Take(5);

 

7、Skip(跳过集合的前n个数据。会延迟计算)

var q = (from p in db.Products
orderby p.UnitPrice descending
select p).Skip(10);

      选择10种最贵的产品之外的所有产品

 

8、TakeWhile(直到某一条件不成立才停止获取。会延迟计算)
   即用其条件去依次判断源序列中的元素,返回符合判断条件的元素,该判断操作将在返回false或源序列的末尾结束

 

9、SkipWhile(顾名思义,同上)

 

10、Paging(分页操作)

var q = (from c in db.Customers
orderby c.CustomerName
select c).Skip(50).Take(10);

 

11、Like

var q = from c in db.Customers
     where SqlMethods.Like(c.CustomerID, "C%")
     select c;

    查询消费者ID没有“AXOXT”形式的消费者:

var q = from c in db.Customers
     where !SqlMethods.Like(c.CustomerID, "A_O_T")
     select c;DateDiffDay

    在两个时间变量之间比较。分别有:DateDiffDay、DateDiffHour、DateDiffMillisecond、DateDiffMinute、DateDiffMonth、DateDiffSecond、DateDiffYear:

    
最新技术文章:
 




特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3