/// <summary>
/// 创建订单编号
/// </summary>
/// <param name="no">上一个订单编号</param>
/// <returns></returns>
public static string CreaterOrderNo(string no)
{
DateTime now = DateTime.Now
string orderNostring = now.Year.ToString() + now.Month.ToString().PadLeft(2,'0') + now.Day.ToString().PadLeft(2,'0') + no.PadLeft(4, '0')
return (orderNostring)
}
/// <summary>
/// 获取当天的最后一个订单编号
/// </summary>
/// <returns></returns>
public string GetOrderLastOrderNo()
{
string cmdText = "select top 1 bianhao from dd where DATEDIFF(year,fabu,getdate())=0 and DATEDIFF(month,fabu,getdate())=0 and DATEDIFF(day,fabu,getdate())=0 order by fabu desc "
object orderNo
SqlCommand cmd = new SqlCommand(cmdText, conn)
try
{
///打开连接
conn.Open()
///读取数据
orderNo = cmd.ExecuteScalar()
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex)///抛出异常
}
finally { conn.Close()}///关闭连接
return orderNo == null ? string.Empty : orderNo.ToString()
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
///获取当天最近的订单编号
string orderNo = GetOrderLastOrderNo()
///创建下一个订单编号的基数
if (string.IsNullOrEmpty(orderNo) == true)
{
///下一个订单号的基数为1
orderNo = "0001"
}
else
{
///创建下一个订单号的基数
orderNo = (Int32.Parse(orderNo.Substring(8)) + 1).ToString()
}
///创建下一个订单编号
orderNo = CreaterOrderNo(orderNo)
if (DateTime.Compare(Convert.ToDateTime(textbox1.Text), DateTime.Now) <=0 &&DateTime.Compare(Convert.ToDateTime(textbox2.Text), DateTime.Now) <=0)
{
RegisterStartupScript(null, "<script>alert('日期已过!')</script>")
}
else
{
if (DateTime.Compare(Convert.ToDateTime(textbox2.Text), Convert.ToDateTime(textbox1.Text)) >0)
{
string insertquery = string.Format("insert into dd (name,sex,age,shenfen,zhengjian,guoji,danwei,dtime,ltime,num,email,tel,beizhu,room,fabu,bianhao) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}')", tbxName.Text, ddlsex.SelectedItem.Value, tbxAge.Text, ddlshenfen.SelectedItem.Value, tbxZhengjian.Text, tbxGuoji.Text, tbxDanwei.Text, textbox1.Text, textbox2.Text, tbxNum.Text, tbxEmail.Text, tbxTel.Text, tbxBeizhu.Text, tbxRoom.Text, DateTime.Now.ToString(), orderNo)
myset.insertdata(insertquery)
Response.Write("<script>alert('提交成功!')location.href='dingfang3.aspx'</script>")
}
else
{
RegisterStartupScript(null, "<script>alert('入住日期和离店日期填写有误!')</script>")
}
}
}
方法1:修改表定义,加入年份方法2:写存储过程
create proc addcolumn
@tablename varchar(30), --表名
@colname varchar(30), --要加的列名
@coltype varchar(100), --要加的列类型
@colid int --加到第几列
as
declare @colid_max int
declare @sql varchar(1000) --动态sql语句
--------------------------------------------------
if not exists(select 1 from sysobjects
where name = @tablename and xtype = 'u ')
begin
raiserror 20001 '没有这个表 '
return -1
end
--------------------------------------------------
if exists(select 1 from syscolumns
where id = object_id(@tablename) and name = @colname)
begin
raiserror 20002 '这个表已经有这个列了! '
return -1
end
--------------------------------------------------
--保证该表的colid是连续的
select @colid_max = max(colid) from syscolumns where id=object_id(@tablename)
if @colid > @colid_max or @colid < 1
set @colid = @colid + 1
--------------------------------------------------
set @sql = 'alter table '+@tablename+ ' add '+@colname+ ' '+@coltype
exec(@sql)
select @colid_max = colid
from syscolumns where id = object_id(@tablename) and name = @colname
if @@rowcount <> 1
begin
raiserror 20003 '加一个新列不成功,请检查你的列类型是否正确 '
return -1
end
--------------------------------------------------
--打开修改系统表的开关
EXEC sp_configure 'allow updates ',1 RECONFIGURE WITH OVERRIDE
--将新列列号暂置为-1
set @sql = 'update syscolumns
set colid = -1
where id = object_id( ' ' '+@tablename+ ' ' ')
and colid = '+cast(@colid_max as varchar(10))
exec(@sql)
--将其他列的列号加1
set @sql = 'update syscolumns
set colid = colid + 1
where id = object_id( ' ' '+@tablename+ ' ' ')
and colid >= '+cast(@colid as varchar(10))
exec(@sql)
--将新列列号复位
set @sql = 'update syscolumns
set colid = '+cast(@colid as varchar(10))+ '
where id = object_id( ' ' '+@tablename+ ' ' ')
and name = ' ' '+@colname + ' ' ' '
exec(@sql)
--------------------------------------------------
--关闭修改系统表的开关
EXEC sp_configure 'allow updates ',0 RECONFIGURE WITH OVERRIDE
go
1、首先创建一个名为tComposer的新表,将作曲家字段设置为主键,显示标题设置为作曲家编号。2、其次将作曲家名称字段设置为必填字段,将年字段的格式属性设置为长日期。
3、然后将年代字段的有效性规则设置为输人的日期必须满足在1980年以后(含1980年)的作曲家,并设置有效性文本为年代日期必须为1980年以后的作曲家。
4、最后打开tCollect表,冻结CDID字段,隐藏价格字段,并保存显示布局。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)