-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmAddDonHang.cs
681 lines (606 loc) · 29.5 KB
/
frmAddDonHang.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
using System;
using System.Transactions;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Windows.Forms;
using qlShop.models;
using qlShop.reports;
using qlShop.qlshop_model;
namespace qlShop
{
public partial class frmAddDonHang : Form
{
//CurrencyManager cm = BindingContext[gridControl1.DataSource,gridControl1.DataMember] as CurrencyManager;
public DonHang ViewItem { get; set; }
public string forMode { set; get; }
public DataTable tblDonHangChiTiet = null;
public frmAddDonHang()
{
InitializeComponent();
forMode = "NEW";
//ViewItem = new DonHang();
KhoiTaoTableDonHangChiTiet();
}
private void frmAddDonHang_Load(object sender, EventArgs e)
{
//KhoiTaoDuLieuSearch();
//txtSearch.Properties.DataSource = SanPhamController.GetActiveList();
//txtSearch.Properties.DisplayMember = "SanPhamID";
//txtSearch.Properties.ValueMember = "SanPhamID";
txtSanPham.Properties.NullValuePrompt = "Scan mã sản phẩm vào đây";
KhoiTaoLuoi();
KhoiTaoDSKhachHang();
//------------------------------------------
dateEditNgayBan.DateTime = DateTime.Now;
txtNhanVien.Text = Utility.NguoiSuDung.NguoiDungID;
txtNhanVien.Properties.ReadOnly = true;
txtMaPhieu.Properties.ReadOnly = true;
txtTienHang.Properties.ReadOnly = true;
txtTienHang.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
txtTienHang.Properties.DisplayFormat.FormatString = "### ### ##0";
txtTienHang.Properties.Mask.UseMaskAsDisplayFormat = true;
txtTong.Properties.ReadOnly = true;
txtTong.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
txtTong.Properties.DisplayFormat.FormatString = "### ### ##0";
txtTong.Properties.Mask.UseMaskAsDisplayFormat = true;
txtConNo.Properties.ReadOnly = true;
txtConNo.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
txtConNo.Properties.DisplayFormat.FormatString = "### ### ##0";
txtConNo.Properties.Mask.UseMaskAsDisplayFormat = true;
txtGiamGia.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
txtGiamGia.Properties.DisplayFormat.FormatString = "### ### ##0";
txtGiamGia.Properties.Mask.UseMaskAsDisplayFormat = true;
txtThanhToan.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
txtThanhToan.Properties.DisplayFormat.FormatString = "### ### ##0";
txtThanhToan.Properties.Mask.UseMaskAsDisplayFormat = true;
txtKhachDua.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
txtKhachDua.Properties.DisplayFormat.FormatString = "### ### ##0";
txtKhachDua.Properties.Mask.UseMaskAsDisplayFormat = true;
txtTienThua.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
txtTienThua.Properties.DisplayFormat.FormatString = "### ### ##0";
txtTienThua.Properties.Mask.UseMaskAsDisplayFormat = true;
txtTienThua.Properties.ReadOnly = true;
//Chế độ view đơn hang
if ((forMode.ToUpper().Equals("VIEW"))&& (ViewItem!=null))
{
txtMaPhieu.Text = ViewItem.DonHangID;
dateEditNgayBan.DateTime = ViewItem.NgayBan;
if (ViewItem.KhachHangID!=null)
{
lookUpEditKhachHang.EditValue = ViewItem.KhachHangID;
}
txtNhanVien.Text = ViewItem.NhanVienID;
txtGhiChu.Text = ViewItem.GhiChu;
txtTienHang.Value = ViewItem.TienHang;
txtGiamGia.Value = ViewItem.GiamGia;
txtTong.Value = ViewItem.TongCong;
txtThanhToan.Value = ViewItem.ThanhToan;
txtConNo.Value = ViewItem.ConNo;
txtKhachDua.Value = ViewItem.KhachDua == null ? 0 :(decimal) ViewItem.KhachDua;
txtTienThua.Value = ViewItem.TienThua == null ? 0 : (decimal)ViewItem.TienThua;
//lay danh sach san pham
DataTable tblTemp = DonHangController.GetSanPham(ViewItem.DonHangID);
//KhoiTaoTableDonHangChiTiet();
foreach (DataRow item in tblTemp.Rows)
{
tblDonHangChiTiet.Rows.Add(item["SanPhamID"].ToString(),
item["TenSanPham"].ToString(),Convert.ToInt32(item["SoLuong"].ToString()),
Convert.ToInt32(item["DonGia"].ToString()));
}
gridControl1.DataSource = tblDonHangChiTiet;// DonHangController.GetSanPham(ViewItem.DonHangID);
btnSave.Enabled = false;
}
CapNhatTrangThai();
btnEdit.Enabled = false; //18/12/2015 ; khóa lại ko cho sauwr sau khi đã lưu đơn hàng.
}
private void KhoiTaoTableDonHangChiTiet()
{
if (tblDonHangChiTiet==null)
{
tblDonHangChiTiet = new DataTable();
}
tblDonHangChiTiet.Columns.Add(new DataColumn("SanPhamID", typeof(string)));
tblDonHangChiTiet.Columns.Add(new DataColumn("TenSanPham", typeof(string)));
tblDonHangChiTiet.Columns.Add(new DataColumn("Size", typeof(string)));
tblDonHangChiTiet.Columns.Add(new DataColumn("SoLuong", typeof(int)));
tblDonHangChiTiet.Columns.Add(new DataColumn("DonGia", typeof(int)));
tblDonHangChiTiet.Columns.Add(new DataColumn("ThanhTien",typeof(decimal),"[SoLuong]*[DonGia]"));
tblDonHangChiTiet.Columns.Add(new DataColumn("TonKho", typeof(int)));
gridControl1.DataSource = tblDonHangChiTiet;
CurrencyManager cm = BindingContext[gridControl1.DataSource, gridControl1.DataMember] as CurrencyManager;
cm.ListChanged += new ListChangedEventHandler(cm_ListChanged);
}
/*
private void KhoiTaoDuLieuSearch()
{
int i = 0;
txtSearch.Properties.Columns[i].Caption = "Mã sản phẩm";
txtSearch.Properties.Columns[i].FieldName = "SanPhamID";
i++;
txtSearch.Properties.Columns[i].Caption = "Tên sản phẩm";
txtSearch.Properties.Columns[i].FieldName = "TenSanPham";
i++;
txtSearch.Properties.Columns[i].Caption = "Giá bán";
txtSearch.Properties.Columns[i].FieldName = "GiaBan";
txtSearch.Properties.Columns[i].FormatType = DevExpress.Utils.FormatType.Numeric;
txtSearch.Properties.Columns[i].FormatString = "# ##0";
i++;
txtSearch.Properties.Columns[i].Caption = "Tồn kho";
txtSearch.Properties.Columns[i].FieldName = "SLTonKho";
//txtSearch.Properties.
txtSearch.Properties.AutoSearchColumnIndex = 1;
txtSearch.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;
txtSearch.Properties.SearchMode = DevExpress.XtraEditors.Controls.SearchMode.AutoComplete;
txtSearch.Properties.NullValuePrompt = "Nhập mã sản phẩm hoặc tên";
}
*/
private void KhoiTaoLuoi()
{
int i = 0;
gridView1.Columns[i].Caption = "Mã sản phẩm";
gridView1.Columns[i].FieldName = "SanPhamID";
gridView1.Columns[i].OptionsColumn.AllowEdit = false;
i++;
gridView1.Columns[i].Caption = "Tên sản phẩm";
gridView1.Columns[i].FieldName = "TenSanPham";
gridView1.Columns[i].OptionsColumn.AllowEdit = false;
i++;
gridView1.Columns[i].Caption = "Size";
gridView1.Columns[i].FieldName = "Size";
//gridView1.Columns[i].OptionsEditForm.
gridView1.Columns[i].OptionsColumn.AllowEdit = true;
i++;
gridView1.Columns[i].Caption = "Số lượng";
gridView1.Columns[i].FieldName = "SoLuong";
gridView1.Columns[i].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
gridView1.Columns[i].DisplayFormat.FormatString = "### ### ##0";
i++;
gridView1.Columns[i].Caption = "Đơn giá";
gridView1.Columns[i].FieldName = "DonGia";
gridView1.Columns[i].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
gridView1.Columns[i].DisplayFormat.FormatString = "### ### ##0";
i++;
gridView1.Columns[i].Caption = "Thành Tiền";
gridView1.Columns[i].FieldName = "ThanhTien";
gridView1.Columns[i].OptionsColumn.AllowEdit = false;
//gridView1.Columns[i].UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
//gridView1.Columns[i].UnboundExpression = "[SoLuong]*[DonGia]";
gridView1.Columns[i].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
gridView1.Columns[i].DisplayFormat.FormatString = "### ### ##0";
gridView1.Columns[i].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
i++;
gridView1.Columns[i].Caption = "#";
gridView1.Columns[i].OptionsColumn.FixedWidth = true;
gridView1.Columns[i].Width = 50;
gridView1.OptionsView.ColumnAutoWidth = false;
gridView1.OptionsView.ShowFooter = true;
gridView1.OptionsView.ColumnAutoWidth = false;
}
private void KhoiTaoDSKhachHang()
{
lookUpEditKhachHang.Properties.DataSource = KhachHangController.GetList();
lookUpEditKhachHang.Properties.DisplayMember="TenKhachHang";
lookUpEditKhachHang.Properties.ValueMember="KhachHangID";
lookUpEditKhachHang.Properties.NullText="Chưa chọn khách hàng";
lookUpEditKhachHang.Text = string.Empty;
lookUpEditKhachHang.Properties.Columns[0].Caption = "Mã khách hàng";
lookUpEditKhachHang.Properties.Columns[0].FieldName = "KhachHangID";
lookUpEditKhachHang.Properties.Columns[1].Caption = "Tên Khách Hàng";
lookUpEditKhachHang.Properties.Columns[1].FieldName = "TenKhachHang";
lookUpEditKhachHang.Properties.SearchMode = DevExpress.XtraEditors.Controls.SearchMode.AutoComplete;
lookUpEditKhachHang.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;
}
private void gr_btn_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
if (e.Button.Caption.ToUpper().Equals("DEL"))
{
int intRow = gridView1.FocusedRowHandle;
if (intRow>=0)
{
tblDonHangChiTiet.Rows.RemoveAt(intRow);
gridView1.RefreshData();
gridView1.BestFitColumns();
}
}
}
private void lookUpEdit1_Properties_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
if (e.Button.Caption.ToUpper().Equals("ADD"))
{
frmAddKhachHang f = new frmAddKhachHang();
f.ShowDialog(this);
lookUpEditKhachHang.Properties.DataSource = KhachHangController.GetList();
if (f.strNewKhachHangID != string.Empty)
{
lookUpEditKhachHang.EditValue = f.strNewKhachHangID;
}
f.Dispose();
}
}
//static CurrencyManager cm = BindingContext[gridControl1.DataSource,gridControl1.DataMember] as CurrencyManager;
//CurrencyManager cm = BindingContext[gridControl1.DataSource, gridControl1.DataMember] as CurrencyManager;
//cm.ListChanged += new ListChangedEventHandler(cm_ListChanged);
void cm_ListChanged(object sender, ListChangedEventArgs e)
{
//gridView1.PostEditor();
//txtTienHang.Text = gridView1.Columns[4].SummaryItem.SummaryValue.ToString();
//MessageBox.Show("Test");
//foreach (var item in tblDonHangChiTiet.Rows)
//{
//}
if (!forMode.ToUpper().Equals("VIEW"))
{
txtTienHang.Text = tblDonHangChiTiet.Compute("sum(ThanhTien)", null).ToString();
txtTong.Value = txtTienHang.Value - txtGiamGia.Value;
txtThanhToan.Value = txtTong.Value;
txtConNo.Value = txtTong.Value - txtThanhToan.Value;
}
}
private void txtGiamGia_EditValueChanged(object sender, EventArgs e)
{
txtTong.Value = txtTienHang.Value - txtGiamGia.Value;
txtThanhToan.Value = txtTong.Value;
txtConNo.Value = txtTong.Value - txtThanhToan.Value;
//calcEditPhanTram.Value = (txtGiamGia.Value / txtTienHang.Value) * 100;
}
private void txtThanhToan_EditValueChanged(object sender, EventArgs e)
{
txtConNo.Value = txtTong.Value - txtThanhToan.Value;
if (txtKhachDua.Value >0)
{
txtTienThua.Value = txtKhachDua.Value - txtThanhToan.Value;
}
}
private void Save()
{
string strMaDonHang = string.Empty;
using (TransactionScope scope = new TransactionScope())
{
DonHang itemSave = new DonHang();
//kiem tra xem co phai nguoi dung dang sua don hang hay khong
if (forMode.ToUpper().Equals("EDIT"))//dang sua don hang, phai xu ly xoa don hang cu
{
string strDonHangID = txtMaPhieu.Text;
DonHangController.Del(strDonHangID);
itemSave.DonHangID = strDonHangID;
itemSave.NgayBan = dateEditNgayBan.DateTime;
itemSave.LastUpdate = DateTime.Now;//ngay sua don hang
}
else
{
itemSave.DonHangID = DonHangController.TaoMaDonHang("EX", 10);
itemSave.NgayBan = dateEditNgayBan.DateTime;
}
strMaDonHang = itemSave.DonHangID;
//thong tin ban hang
if (lookUpEditKhachHang.EditValue != null)
{
itemSave.KhachHangID = lookUpEditKhachHang.EditValue.ToString();
itemSave.TenKhachHang = lookUpEditKhachHang.Text;
}
itemSave.GhiChu = txtGhiChu.Text;
itemSave.NhanVienID = txtNhanVien.Text;
itemSave.TenNhanVien = Utility.NguoiSuDung.TenNguoiDung;
itemSave.LastUpdate = DateTime.Now;
//thong tin thanh toan
itemSave.TienHang = txtTienHang.Value;
itemSave.GiamGia = txtGiamGia.Value;
itemSave.TongCong = txtTong.Value;
itemSave.ThanhToan = txtThanhToan.Value;
itemSave.ConNo = txtConNo.Value;
itemSave.KhachDua = txtKhachDua.Value;
itemSave.TienThua = txtTienThua.Value;
//lay thong tin chi tiet don hang
List<DonHangChiTiet> DonHangItems = new List<DonHangChiTiet>();
if (tblDonHangChiTiet != null)
{
foreach (DataRow item in tblDonHangChiTiet.Rows)
{
DonHangChiTiet newitem = new DonHangChiTiet();
newitem.DonHangID = itemSave.DonHangID;
newitem.SanPhamID = item["SanPhamID"].ToString();
newitem.TenSanPham = item["TenSanPham"].ToString();
newitem.Size = item["Size"].ToString().ToUpper();
newitem.SoLuong = Convert.ToInt32(item["SoLuong"].ToString());
newitem.DonGia = Convert.ToDecimal(item["DonGia"].ToString());
//newitem.TonKho = SanPhamController.GetTonKho(newitem.SanPhamID);
DonHangItems.Add(newitem);
}
}
DonHangController.Add(itemSave, DonHangItems);
scope.Complete();
}
if (MessageBox.Show("Bạn có muốn in Bill luôn không", "Xác Nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
Print_Bill(strMaDonHang);
}
}
private void Print_Bill(string strDonHangID)
{
PhieuBanHang_58 rp = new PhieuBanHang_58(); // new PhieuBanHang();
rp.SetDataSource(reportsController.prtDonHang(strDonHangID));
rp.Refresh();
ThongTinShop shop = ThongTinShopController.GetItem();
rp.SetParameterValue("TenShop", shop.TenShop);
rp.SetParameterValue("DiaChi", shop.DiaChi);
rp.SetParameterValue("SoDienThoai", shop.SoDienThoai);
rp.SetParameterValue("WebSite", shop.website);
frmViewReports fReport = null;
foreach (Form item in MdiChildren)
{
if (item.GetType() == typeof(frmViewReports))
{
fReport = (item as frmViewReports);
fReport.crystalReportViewer1.ReportSource = rp;
fReport.Activate();
return;
}
}
fReport = new frmViewReports();
fReport.crystalReportViewer1.ReportSource = rp;
//fReport.MdiParent = this.MdiParent;
fReport.ShowDialog(this);
}
/// <summary>
/// Hàm kiểm tra hợp lệ trước khi save
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private bool isValidateForm(out string strMsg)
{
string strErr = string.Empty;
if (tblDonHangChiTiet.Select("[Size] is null").Count() > 0) strErr += "Chưa nhập size cho sản phẩm. Kiểm tra lại\n\n";
if (tblDonHangChiTiet.Rows.Count < 1) strErr += "Chưa có sản phẩm nào trong đơn hàng.\n\n";
if (tblDonHangChiTiet.Select("[SoLuong] <=0").Count() > 0) strErr += "Có sản phẩm số lượng không hợp lệ (<=0). Kiểm tra lại.\n\n";
strMsg = strErr;
if (strErr.Equals(string.Empty))
{
return true;
}
else
{
return false;
}
}
private void btnSave_Click(object sender, EventArgs e)
{
//kiểm tra demo phần mềm-------------------------//
//DateTime Ngayhethan = new DateTime(2015, 8 ,15);
//if (DateTime.Now >Ngayhethan)
//{
// MessageBox.Show("Phần mềm đã hết hạn sử dụng, vui lòng liên hệ tác giả.","Cảnh báo",MessageBoxButtons.OK);
// return;
//}
//kiểm tra nếu có sản phẩm nào chưa có size thì không cho lưu.
string strError = string.Empty;
if (!isValidateForm(out strError))
{
MessageBox.Show(strError, "Cảnh báo", MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
Save();
frmDonHang f = new frmDonHang();
f.MdiParent = this.MdiParent;
f.Show();
this.Dispose();
}
private void btnExport_Click(object sender, EventArgs e)
{
frmDonHang f = new frmDonHang();
f.MdiParent = this.MdiParent;
f.Show();
this.Dispose();
}
private void SellNewITem(string strSanPhamID,string strSize = null)
{
if (!SanPhamController.IsExitsItem(strSanPhamID)) //nêu mã sản phẩm ko có, thử tìm mã mở rộng
{
strSanPhamID = SanPhamController.GetIDFromExtID(strSanPhamID);
}
if (SanPhamController.IsExitsItem(strSanPhamID))
{
SanPham itemSP = SanPhamController.GetItem(strSanPhamID);
DataRow[] findRow = null;
if (strSize ==null)
{
findRow = tblDonHangChiTiet.Select(string.Format("[SanPhamID]='{0}' and [Size] is null", strSanPhamID));
}
else
{
findRow = tblDonHangChiTiet.Select(string.Format("[SanPhamID]='{0}' and [Size] = '{1}'", strSanPhamID,strSize));
}
if (findRow.Count()<1)//chưa có
{
tblDonHangChiTiet.Rows.Add(itemSP.SanPhamID, itemSP.TenSanPham, strSize, 1, itemSP.GiaBan);
}
else
{
findRow[0]["SoLuong"] = Convert.ToInt32(findRow[0]["SoLuong"]) + 1;
}
gridView1.RefreshData();
gridView1.BestFitColumns();
}
else
{
MessageBox.Show("Sản phầm này chưa có trong danh mục,\n\n Vui lòng kiểm tra lại hoặc nhập vào danh mục sản phẩm","Cảnh Báo",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
}
private void CapNhatTrangThai()
{
switch (forMode.ToUpper())
{
case "VIEW":
btnCancel.Enabled = false;
btnSave.Enabled = false;
btnEdit.Enabled = true;
//
txtSanPham.Enabled = false;
gridView1.Columns["SoLuong"].OptionsColumn.AllowEdit = false;
gridView1.Columns["DonGia"].OptionsColumn.AllowEdit = false;
gridColumn6.OptionsColumn.AllowEdit = false;
lookUpEditKhachHang.Enabled = false;
dateEditNgayBan.Enabled = false;
txtGhiChu.Enabled = false;
txtGiamGia.Enabled = false;
txtThanhToan.Enabled = false;
break;
case "EDIT": //dang edit du lieu
btnCancel.Enabled = true;
btnSave.Enabled = true;
btnEdit.Enabled = false;
//
txtSanPham.Enabled = true;
gridView1.Columns["SoLuong"].OptionsColumn.AllowEdit = true;
gridView1.Columns["DonGia"].OptionsColumn.AllowEdit = true;
gridColumn6.OptionsColumn.AllowEdit = true;
lookUpEditKhachHang.Enabled = true;
dateEditNgayBan.Enabled = true;
txtGhiChu.Enabled = true;
txtGiamGia.Enabled = true;
txtThanhToan.Enabled = true;
break;
case "NEW": //Them don hang moi
btnCancel.Enabled = false;
btnSave.Enabled = true;
btnEdit.Enabled = false;
//
txtSanPham.Enabled = true;
gridView1.Columns["SoLuong"].OptionsColumn.AllowEdit = true;
gridView1.Columns["DonGia"].OptionsColumn.AllowEdit = true;
gridColumn6.OptionsColumn.AllowEdit = true;
lookUpEditKhachHang.Enabled = true;
dateEditNgayBan.Enabled = true;
txtGhiChu.Enabled = true;
txtGiamGia.Enabled = true;
txtThanhToan.Enabled = true;
break;
default:
break;
}
}
private void btnEdit_Click(object sender, EventArgs e)
{
forMode = "EDIT";
CapNhatTrangThai();
}
private void txtKhachDua_EditValueChanged(object sender, EventArgs e)
{
txtTienThua.Value = txtKhachDua.Value - txtThanhToan.Value;
if (txtTienThua.Value<0)
{
txtTienThua.Value = 0;
}
}
private void txtKhachDua_DoubleClick(object sender, EventArgs e)
{
if (txtKhachDua.Value==0)
{
txtKhachDua.Value = txtThanhToan.Value;
}
}
private void buttonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
if(e.Button.Caption.ToUpper().Equals("FIND"))
{
frmTimSanPham f = new frmTimSanPham();
f.SendSanPhamID = new frmTimSanPham.SendData(SellNewITem);
f.ShowDialog(this);
}
}
private void txtSanPham_KeyDown(object sender, KeyEventArgs e)
{
string strSanPhamID = string.Empty;
if (e.KeyCode == Keys.Enter)
{
if (txtSanPham.EditValue != null)
{
strSanPhamID = txtSanPham.EditValue.ToString();
}
else
{
return;
}
SellNewITem(strSanPhamID);
txtSanPham.Focus();
txtSanPham.SelectAll();
}
}
private void btnPrinterTest_Click(object sender, EventArgs e)
{
//tao source de in thu don hang
DataTable TblPrinter = new DataTable();
TblPrinter.Columns.Add(new DataColumn("DonHangID", typeof(string)));
TblPrinter.Columns.Add(new DataColumn("TenKhachHang", typeof(string)));
TblPrinter.Columns.Add(new DataColumn("NgayBan", typeof(DateTime)));
TblPrinter.Columns.Add(new DataColumn("NhanVienID", typeof(string)));
TblPrinter.Columns.Add(new DataColumn("GhiChu", typeof(string)));
TblPrinter.Columns.Add(new DataColumn("TienHang", typeof(decimal)));
TblPrinter.Columns.Add(new DataColumn("GiamGia", typeof(decimal)));
TblPrinter.Columns.Add(new DataColumn("TongCong", typeof(decimal)));
TblPrinter.Columns.Add(new DataColumn("ThanhToan", typeof(decimal)));
TblPrinter.Columns.Add(new DataColumn("ConNo", typeof(decimal)));
TblPrinter.Columns.Add(new DataColumn("KhachDua", typeof(decimal)));
TblPrinter.Columns.Add(new DataColumn("TienThua", typeof(decimal)));
TblPrinter.Columns.Add(new DataColumn("TenSanPham", typeof(string)));
TblPrinter.Columns.Add(new DataColumn("Size", typeof(string)));
TblPrinter.Columns.Add(new DataColumn("SoLuong", typeof(int)));
TblPrinter.Columns.Add(new DataColumn("DonGia", typeof(decimal)));
foreach (DataRow item in tblDonHangChiTiet.Rows)
{
TblPrinter.Rows.Add(
"000",
lookUpEditKhachHang.Text,
dateEditNgayBan.DateTime,
txtNhanVien.EditValue,
txtGhiChu.Text,
txtTienHang.EditValue == null ? 0 : txtTienHang.EditValue,
txtGiamGia.EditValue == null ? 0 : txtGiamGia.EditValue,
txtTong.EditValue == null ? 0 : txtTong.EditValue,
txtThanhToan.EditValue == null ? 0 : txtThanhToan.EditValue,
txtConNo.EditValue == null ? 0 : txtConNo.EditValue,
txtKhachDua.EditValue == null ? 0 : txtKhachDua.EditValue,
txtTienThua.EditValue == null ? 0 : txtTienThua.EditValue,
item["TenSanPham"].ToString(),
item["Size"] is null?"": item["Size"].ToString(),
Convert.ToDecimal( item["SoLuong"].ToString()),
Convert.ToDecimal( item["DonGia"].ToString())
);
}
////-------------------------------------------------------
//PhieuTam rp = new PhieuTam();
PhieuBanHang_58 rp = new PhieuBanHang_58();
rp.SetDataSource(TblPrinter);
rp.Refresh();
ThongTinShop shop = ThongTinShopController.GetItem();
rp.SetParameterValue("TenShop", shop.TenShop);
rp.SetParameterValue("DiaChi", shop.DiaChi);
rp.SetParameterValue("SoDienThoai", shop.SoDienThoai);
rp.SetParameterValue("WebSite", shop.website);
frmViewReports fReport = null;
foreach (Form item in MdiChildren)
{
if (item.GetType() == typeof(frmViewReports))
{
fReport = (item as frmViewReports);
fReport.crystalReportViewer1.ReportSource = rp;
fReport.Activate();
return;
}
}
fReport = new frmViewReports();
fReport.crystalReportViewer1.ReportSource = rp;
fReport.MdiParent = this.MdiParent;
fReport.Show();
}
private void calcEditPhanTram_EditValueChanged(object sender, EventArgs e)
{
txtGiamGia.Value = txtTong.Value * (calcEditPhanTram.Value / 100);
txtTong.Value = txtTienHang.Value - txtGiamGia.Value;
txtThanhToan.Value = txtTong.Value;
txtConNo.Value = txtTong.Value - txtThanhToan.Value;
}
}
}