标签:datatable bre null room 之间 ike source spm 外键
1 2018.9.26 2 --往GridControl中添加绑定数据 3 // 房间费用 4 DataTable dtRoomInfo = new DataTable(); 5 dtRoomInfo.Columns.Add("v_name", Type.GetType("System.String")); 6 dtRoomInfo.Columns.Add("t_kt_time", Type.GetType("System.String")); 7 dtRoomInfo.Columns.Add("v_ktsc", Type.GetType("System.String")); 8 dtRoomInfo.Columns.Add("v_jfgz_name", Type.GetType("System.String")); 9 dtRoomInfo.Columns.Add("f_room_money", Type.GetType("System.String")); 10 11 DataRow rowRoomInfo = dtRoomInfo.NewRow(); 12 rowRoomInfo["v_name"] = ddModel.v_czzl_name; 13 rowRoomInfo["t_kt_time"] = ddModel.t_kaitai_time.ToString("yyyy-MM-dd HH:mm"); 14 decimal hour = decimal.Parse((ddModel.i_jfsc * 1.0 / (60 * 60)).ToString()); 15 rowRoomInfo["v_ktsc"] = ((int)hour).ToString() + "小时" + ((hour - (int)hour) * 60).ToString("0") + "分钟"; 16 rowRoomInfo["v_jfgz_name"] = ddModel.v_jfgz_name; 17 rowRoomInfo["f_room_money"] = ddModel.f_room_money.ToString(); 18 dtRoomInfo.Rows.Add(rowRoomInfo); 19 this.gridControlRoomInfo.DataSource = dtRoomInfo; 20 21 //预付款 22 DataTable dtYFMoney = new DataTable(); 23 dtYFMoney.Columns.Add("v_fkfs", Type.GetType("System.String")); 24 dtYFMoney.Columns.Add("t_time", Type.GetType("System.String")); 25 dtYFMoney.Columns.Add("f_yf_money", Type.GetType("System.String")); 26 dtYFMoney.Columns.Add("v_operation_name", Type.GetType("System.String")); 27 dtYFMoney.Columns.Add("v_mark", Type.GetType("System.String")); 28 DataRow rowYFMoney = dtYFMoney.NewRow(); 29 //支付类型 30 switch (ddModel.i_yj_payment_type) 31 { 32 case 0: 33 rowYFMoney["v_fkfs"] = "现金"; 34 break; 35 case 1: 36 rowYFMoney["v_fkfs"] = "银行卡"; 37 break; 38 case 2: 39 rowYFMoney["v_fkfs"] = "微信"; 40 break; 41 case 3: 42 rowYFMoney["v_fkfs"] = "支付宝"; 43 break; 44 default: 45 break; 46 } 47 rowYFMoney["t_time"] = ddModel.t_kaitai_time.ToString("yyyy-MM-dd HH:mm"); 48 rowYFMoney["f_yf_money"] = ddModel.f_yajin_money.ToString(); 49 rowYFMoney["v_operation_name"] =ddModel.v_operator_name; 50 rowYFMoney["v_mark"] =ddModel.v_mark; 51 dtYFMoney.Rows.Add(rowYFMoney); 52 this.gridControlYFMoney.DataSource = dtYFMoney; 53 ------------------------------------------------------------------------------------------------------------ 54 2018.10.15:周一 55 56 -- 返回前5个数据 57 SELECT TOP 5 * 58 FROM Student; 59 60 -- 返回前50%的数据 61 SELECT TOP 50 PERCENT * 62 FROM Student; 63 64 -- 以"C"或"P"开头 65 SELECT * 66 FROM Student 67 WHERE Subject LIKE ‘[CP]%‘; 68 69 -- 不以"C"或"P"开头 70 SELECT * 71 FROM Student 72 -- WHERE Subject LIKE ‘[^CP]%‘; 73 -- WHERE Subject LIKE ‘[!CP]%‘; //不行 74 WHERE Subject NOT LIKE ‘[CP]%‘; 75 76 -- 以"A-D"开头 77 SELECT * 78 FROM Student 79 WHERE Subject LIKE ‘[A-D]%‘; 80 81 --选择科目是java和c#的所有人 82 SELECT * 83 FROM Student 84 WHERE Subject IN (‘Java‘,‘C#‘); 85 -- WHERE Subject NOT IN (‘Java‘,‘C#‘); 86 87 --选择范围之间 88 SELECT * 89 FROM Student 90 WHERE StuAge BETWEEN 22 AND 24; 91 -- WHERE StuAge NOT BETWEEN 22 AND 24; 92 93 SELECT * 94 FROM Student 95 WHERE (StuAge BETWEEN 22 AND 24) AND Subject NOT IN(‘Java‘); 96 97 SELECT * 98 FROM Student 99 WHERE StuName BETWEEN ‘曹操‘ AND ‘关羽‘ 100 ORDER BY StuName; 101 102 --若有日期的话 103 --SELECT * FROM Student WHERE Date BETWEEN #07/04/1996# AND #07/09/1996#; 104 105 -- 连接 106 -- 内 107 SELECT * 108 FROM Student INNER JOIN UserLogin 109 ON Student.StuName=UserLogin.UserName; 110 -- 左外 111 SELECT * 112 FROM Student LEFT JOIN UserLogin 113 ON Student.StuName=UserLogin.UserName; 114 -- 右外 115 SELECT * 116 FROM Student RIGHT JOIN UserLogin 117 ON Student.StuName=UserLogin.UserName; 118 -- 自然 119 SELECT * 120 FROM Student FULL JOIN UserLogin 121 ON Student.StuName=UserLogin.UserName; 122 123 -- 自连接 124 SELECT S.StuName AS NAME1,U.UserName AS NAME2 125 FROM Student S,UserLogin U 126 WHERE S.ID =U.ID; 127 128 --组合并去重复 129 SELECT StuName AS NAME 130 FROM Student 131 UNION 132 SELECT UserName 133 FROM UserLogin 134 ORDER BY StuName; 135 136 --组合但未去重复 137 SELECT StuName AS NAME 138 FROM Student 139 UNION ALL 140 SELECT UserName 141 FROM UserLogin 142 ORDER BY StuName; 143 144 --复制表中的数据到另一个新建表 145 SELECT * 146 INTO Student1015 147 FROM Student; 148 149 -- 复制到另一个数据库//貌似不可行 150 SELECT * 151 INTO Student181015 IN ‘Nwind.mdb‘ 152 FROM Student; 153 154 --只复制一些列到新表 155 SELECT StuName,StuAge 156 INTO Student1015_1 157 FROM Student; 158 159 --复制多个表中信息插入新表 160 SELECT UserLogin.ID,Student.StuName,Student.StuAge 161 INTO Student1015_2 162 FROM Student INNER JOIN UserLogin 163 ON Student.StuName=UserLogin.UserName 164 ORDER BY UserLogin.ID; 165 166 --建一个空表,查询返回时无返回值 167 SELECT * 168 INTO newtable 169 FROM Student 170 WHERE 1=0; 171 172 --把指定列插入另一个表的指定列 173 INSERT INTO Student1015_2(ID,StuName,StuAge) 174 SELECT TOP 3 Student.ID,Student.Subject,Student.StuAge 175 FROM Student 176 WHERE Student.Subject=‘c#‘; 177 178 --删除表 179 DROP TABLE Student1015_2; 180 --只删除表中数据 181 TRUNCATE TABLE Student1015_2; 182 183 --添加列 184 ALTER TABLE Student1015_1 185 ADD STU15 DATE; 186 --删除列 187 ALTER TABLE Student1015_1 188 DROP COLUMN STU15; 189 --更改列 190 ALTER TABLE Student1015_1 191 ALTER COLUMN STU15 DATETIME; 192 193 --创建视图 194 GO 195 CREATE VIEW [MYSTUDENT] AS 196 SELECT ID,StuName 197 FROM Student1015 198 WHERE StuAge=24; 199 GO 200 201 GO 202 CREATE VIEW [DYMYSTUDENT] AS 203 SELECT ID,StuName 204 FROM Student1015 205 WHERE StuAge>(SELECT AVG(StuAge) FROM Student1015); 206 GO 207 --查询视图 208 GO 209 SELECT * 210 FROM [MYSTUDENT] 211 GO 212 --更新视图//貌似不行 213 GO 214 CREATE OR REPLACE VIEW [MYSTUDENT] AS 215 SELECT ID,StuName 216 FROM Student1015 217 WHERE StuAge=23; 218 GO 219 --删除视图 220 DROP VIEW [MYSTUDENT]; 221 222 --查询时间 223 SELECT * 224 FROM Student1015_1 225 WHERE STU15=‘2018-10-15‘; 226 ---------------------------------------------------------------------------------------------------------------- 227 2018.10.16:周二 228 --进阶 229 230 --别名 231 SELECT StuName,StuNum+‘,‘+StuClass+‘,‘+StuGender+‘,‘+StuPhone AS 信息 232 FROM Student; 233 234 --删除主键约束 235 ALTER TABLE Student DROP CONSTRAINT PK_Student; 236 237 --创建表并添加唯一性约束 238 CREATE TABLE Persons( 239 P_Id int NOT NULL, 240 LastName varchar(255) NOT NULL, 241 FirstName varchar(255), 242 Address varchar(255), 243 City varchar(255), 244 CONSTRAINT uc_PersonID UNIQUE (P_Id,LastName) 245 ); 246 --如果表已被创建添加唯一性约束 247 ALTER TABLE Student 248 ADD UNIQUE (ID); 249 --如果需要命名约束 250 ALTER TABLE Student 251 ADD CONSTRAINT uc_Student UNIQUE (ID,StuName) 252 --删除这个约束 253 ALTER TABLE Student 254 DROP CONSTRAINT uc_Student; 255 256 --主键约束 257 CREATE TABLE Person( 258 P_Id int NOT NULL, 259 LastName varchar(255) NOT NULL, 260 FirstName varchar(255), 261 Address varchar(255), 262 City varchar(255), 263 CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName) 264 ); 265 --在上面的实例中,只有一个主键 PRIMARY KEY(pk_PersonID)。 266 --然而,pk_PersonID 的值是由两个列(P_Id 和 LastName)组成的。 267 --如果表已创建 268 ALTER TABLE Person 269 ADD CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName); 270 --删除约束 271 ALTER TABLE Person 272 DROP CONSTRAINT pk_PersonID; 273 274 --外键约束 275 CREATE TABLE Orders( 276 O_Id int NOT NULL PRIMARY KEY, 277 OrderNo int NOT NULL, 278 P_Id int FOREIGN KEY REFERENCES Person(P_Id) 279 ); 280 281 --如需命名 FOREIGN KEY 约束,并定义多个列的 FOREIGN KEY 约束 282 CREATE TABLE Orders1( 283 O_Id int NOT NULL, 284 OrderNo int NOT NULL, 285 P_Id int, 286 PRIMARY KEY (O_Id), 287 CONSTRAINT fk_PerOrders FOREIGN KEY (P_Id) 288 REFERENCES Person(P_Id) 289 ); 290 291 -- 当表已被创建时 292 ALTER TABLE Orders 293 ADD FOREIGN KEY (P_Id) 294 REFERENCES Persons(P_Id) 295 -- 如需命名 FOREIGN KEY 约束,并定义多个列的 FOREIGN KEY 约束 296 ALTER TABLE Orders 297 ADD CONSTRAINT fk_PerOrders 298 FOREIGN KEY (P_Id) 299 REFERENCES Persons(P_Id) 300 301 -- 删除约束 302 ALTER TABLE Orders 303 DROP CONSTRAINT fk_PerOrders 304 305 -- 默认约束 306 307 -- 下面的 SQL 在表创建时在 "City" 列上创建 DEFAULT 约束: 308 CREATE TABLE Persons1016_1( 309 P_Id int NOT NULL, 310 LastName varchar(255) NOT NULL, 311 FirstName varchar(255), 312 Address varchar(255), 313 City varchar(255) DEFAULT ‘Sandnes‘ 314 ) 315 -- 通过使用类似 GETDATE() 这样的函数,DEFAULT 约束也可以用于插入系统值: 316 CREATE TABLE Orders1016_2( 317 O_Id int NOT NULL, 318 OrderNo int NOT NULL, 319 P_Id int, 320 OrderDate date DEFAULT GETDATE() 321 ) 322 323 --当表已被创建时,如需在 "City" 列创建 DEFAULT 约束 324 ALTER TABLE Persons 325 ADD CONSTRAINT DF_Persons_City DEFAULT(‘SANDNES‘) FOR City 326 --Persons 为表名 327 --City 为列名 328 --DF_Persons_City 为我们创建的默认约束的名称 约束名称一般为:约束类型简称_表名_列名 329 330 --删除 331 ALTER TABLE Persons1016_1 332 ALTER COLUMN City DROP DEFAULT; 333 334 --having 335 SELECT ID,StuName,StuClass,StuPhone,StuAge,SUM(ID+StuAge) AS HE 336 FROM Student 337 GROUP BY ID ,StuName,StuClass,StuPhone,StuAge 338 HAVING StuAge>22; 339 ?
2018.10.23-24:周二 周三 // 复制设置 private void tzxButtonExCopy_Click(object sender, EventArgs e) { if (this.currentSelectedCzzlModel==null) { MessageBoxFunction.showInfoMessageBox("请选择正确的餐桌进行复制!"); return; } // 弹出选择桌台页面 SelectTableListForm formSelectTableList = new SelectTableListForm(); formSelectTableList.ShowDialog(); //获取到所选择的桌子 selectCzzlList=formSelectTableList.SelectedTableInfoList; //MessageBox.Show(selectCzzlList.Count.ToString()); if (formSelectTableList.DialogResult != DialogResult.OK) { return; } if (selectCzzlList == null || selectCzzlList.Count == 0) { return; } //把设置复制到所选择的餐桌 foreach (cy_jczl_czzl_lb item in selectCzzlList) { if (this.currentSelectedCzzlModel.pk == item.pk) { continue; } //对某些餐桌上已有设置的菜品进行清空 List<cy_jczl_czzl_ktsp> deleteKtspList=TableProfileManager.Instance.getKtspList(item.v_no); foreach (cy_jczl_czzl_ktsp deleteKtspModel in deleteKtspList) { TableProfileManager.Instance.ktspDelete(deleteKtspModel.pk); } //餐桌资料的一些设置进行复制 item.i_cwf_type= this.currentSelectedCzzlModel.i_cwf_type; if (item.i_cwf_type == 0) { item.f_cwf_cz_money = this.currentSelectedCzzlModel.f_cwf_cz_money; } else if (item.i_cwf_type == 1) { item.f_cwf_cz_money = this.currentSelectedCzzlModel.f_cwf_cz_money; item.f_cwf_people_money = 0; } else if (item.i_cwf_type == 2) { item.f_cwf_people_money = this.currentSelectedCzzlModel.f_cwf_people_money; item.f_cwf_cz_money = 0; } else { return; } item.i_ktcd = this.currentSelectedCzzlModel.i_ktcd; item.i_ktsp = this.currentSelectedCzzlModel.i_ktsp; TableProfileManager.Instance.CzzlUpdate(item); //餐桌所选的开台菜品进行复制 List<cy_jczl_czzl_ktsp> currentKtspList = TableProfileManager.Instance.getKtspList(this.currentSelectedCzzlModel.v_no); if (currentKtspList == null || currentKtspList.Count == 0) { return; } foreach (cy_jczl_czzl_ktsp currentKtspModel in currentKtspList) { cy_jczl_czzl_ktsp copyKtspModel = new cy_jczl_czzl_ktsp(); copyKtspModel.f_amount = currentKtspModel.f_amount; copyKtspModel.f_price = currentKtspModel.f_price; copyKtspModel.f_total_money = currentKtspModel.f_total_money; copyKtspModel.i_dalei_pk = currentKtspModel.i_dalei_pk; copyKtspModel.i_czzl_pk = item.pk; copyKtspModel.i_delete = currentKtspModel.i_delete; copyKtspModel.i_goods_pk = currentKtspModel.i_goods_pk; copyKtspModel.i_status = currentKtspModel.i_status; copyKtspModel.i_operator_pk = item.i_operator_pk; copyKtspModel.i_xiaolei_pk = currentKtspModel.i_xiaolei_pk; copyKtspModel.t_create_time = item.t_create_time; copyKtspModel.v_czzl_no = item.v_no; copyKtspModel.v_dalei_name = currentKtspModel.v_dalei_name; copyKtspModel.v_danwei_name = currentKtspModel.v_danwei_name; copyKtspModel.v_goods_name = currentKtspModel.v_goods_name; copyKtspModel.v_goods_no = currentKtspModel.v_goods_no; copyKtspModel.v_mark = currentKtspModel.v_mark; copyKtspModel.v_specs = currentKtspModel.v_specs; copyKtspModel.v_xiaolei_name = currentKtspModel.v_xiaolei_name; TableProfileManager.Instance.ktspAdd(copyKtspModel); } } MessageBoxFunction.showInfoMessageBox("批量添加成功!"); base.Close(); return; }
标签:datatable bre null room 之间 ike source spm 外键
原文地址:https://www.cnblogs.com/nullcodeworld/p/9849066.html