Subversion Repository Public Repository

17001_SKYPRO

This repository has no backups
This repository's network speed is throttled to 100KB/sec

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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sky.BLL;
using Sky.Core;
using Sky.Core.Forms;
using Sky.Core.Utilities;
using Sky.DAL;
using Sky.Reports.Commons;
using Sky.Core.Controls;
using Sky.UI.Forms.HT_ViewReport;

namespace Sky.Reports.Forms.Sales
{
    public partial class BaoCaoCongNoTheoHoaDonBan : SkyForm
    {
        private SQLDbConnection cnnData;
        private string[] db = null;
        private string strSQL1;
        private string strSQL2;
        private string strCond1;
        private string strCond2;
        private long intStt;
        private int intStt1;
        private DataSet rst;
        private string valueClicked;
        public BaoCaoCongNoTheoHoaDonBan()
        {
            InitializeComponent();
            cnnData = new SQLDbConnection(Config.ConnectionString);
            db = SkyConvert.GetDatabaseInfo(Config.ConnectionString);
            dEDenNgay.Properties.Mask.Culture = new System.Globalization.CultureInfo("en-US");
            dEDenNgay.Properties.Mask.EditMask = "dd/MM/yyyy";
            dEDenNgay.Properties.Mask.UseMaskAsDisplayFormat = true;
            dEDenNgay.Properties.CharacterCasing = CharacterCasing.Upper;
            dETuNgay.Properties.Mask.Culture = new System.Globalization.CultureInfo("en-US");
            dETuNgay.Properties.Mask.EditMask = "dd/MM/yyyy";
            dETuNgay.Properties.Mask.UseMaskAsDisplayFormat = true;
            dETuNgay.Properties.CharacterCasing = CharacterCasing.Upper;
            CommonFunction.LoadLocation(txtDiaDiem);
            dEDenNgay.DateTime = DateTime.Now;
            dETuNgay.DateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            lblUser.Text = User.CurrentUser.Ten;
        }

        private void skyCommand1_btnCMDClick(object sender, Core.Controls.SkyCommand.BtnCMDClickEventArgs e)
        {
            switch (e.ButtonClicked)
            {
                case SkyCommand.ButtonIndex.Quit:
                    this.Close();
                    break;
                case SkyCommand.ButtonIndex.Loc:
                    Filter();
                    break;
                case SkyCommand.ButtonIndex.Excel:
                    CommonFunction.ExportExcel(gridControl1);
                    break;
                case SkyCommand.ButtonIndex.In:
                    //Print();
                    ContextMenuStrip printMenu = new ContextMenuStrip();
                    //menuExcel.BackgroundImage = Properties.Resources.BANERNANGCHUAN;
                    printMenu.Items.Add("Xem in tổng hợp").Tag = "TH";
                    printMenu.Items.Add("Xem in chi tiết").Tag = "CT";
                    PopupMenu(printMenu, new Point(Cursor.Position.X, Cursor.Position.Y));
                    printMenu.ItemClicked += new ToolStripItemClickedEventHandler(Excel_ItemClicked);
                    break;
            }
        }

        private void Excel_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            ToolStripItem item = e.ClickedItem;
            if (item.Tag.Equals("TH"))
                Print();
            else
                PrintDetails();
        }

        private void PrintDetails()
        {
            string strSQL3;
            string strFormula;
            string strValue;
            string strTable;
            string str1="";
            try
            {
                if (rst.Tables[0].Rows.Count < 1)
                {
                    SkyConvert.Msg("Không có dữ liệu in.", (int)EventValue.WARNING);
                    return;
                }
                strSQL3 =
                    "SELECT TOP 100 PERCENT SoCai.Ngay,SoCai.ChungTu,DM_KhachHang.Ma AS MaKhach,DM_KhachHang.Ten AS TenKhach,SoCai.PsNo, " +
                    " ISNULL(SoTT.PsCo,0)+ISNULL(SoCai.PsCo,0) AS PsCo,ISNULL(SoCai.PsNo,0)-ISNULL(SoTT.PsCo,0)-ISNULL(SoCai.PsCo,0) AS ConLai,SoThanhToan.Ngay AS NgayTT, " +
                    " SoThanhToan.ChungTu AS Chung_TuTT,SoThanhToan.GhiChu AS GhiChuTT,SoThanhToan.PsCo AS PsCoTT " +
                    " From SoCai INNER JOIN DM_KhachHang ON SoCai.KhachHangCode=DM_KhachHang.Code " +
                    " LEFT Join " +
                    " (SELECT TOP 100 PERCENT SoCai.SoHoaDon,SUM(SoCai.PsCo) As PsCo " +
                    " From SoCai " +
                    " WHERE SoCai.SoHoaDon<>'' AND SoCai.LoaiCT='PCNCC' " +
                    " GROUP BY SoCai.SoHoaDon) AS SoTT ON SoCai.ChungTu=SoTT.SoHoaDon " +
                    " LEFT OUTER JOIN " +
                    " (SELECT TOP 100 PERCENT SoCai.Ngay,SoCai.ChungTu,SoCai.GhiChu,SoCai.PsCo, " +
                    " (Case When ISNULL(SoCai.SoHoaDon,'')<>'' Then SoCai.SoHoaDon ELSE SoCai.ChungTu END) AS SoHoaDon " +
                    " From SoCai " +
                    " WHERE SoCai.ChungTu<>'' AND ISNULL(SoCai.PsCo,0)<>0 AND SoCai.LoaiCT in('PCNCC','HDMH')) AS SoThanhToan ON SoThanhToan.SoHoaDon=SoCai.ChungTu " +
                    " WHERE SoCai.ChungTu<>'' AND SoCai.LoaiCT='HDMH' " + strCond2;
                strFormula = "TuNgay#DenNgay#KhachHang";
                
                if (!SkyConvert.RongTht(txtKhachHang.EditValue))
                {
                    string CodeKH = (txtKhachHang.EditValue != null) ? txtKhachHang.EditValue.ToString() : "";
                    string TenKH = (txtKhachHang.EditValue != null) ? txtKhachHang.EditValue.ToString() : "";
                    strValue = dETuNgay.DateTime.ToString("dd/MM/yyyy") + "#" +
                               dEDenNgay.DateTime.ToString("dd/MM/yyyy") + "#" +
                               CodeKH + " - " + CommonFunction
                                   .GetNameOfObject("DM_KhachHang", TenKH, cnnData);
                }
                else
                {
                    strValue = dETuNgay.DateTime.ToString("dd/MM/yyyy") + "#" +
                               dEDenNgay.DateTime.ToString("dd/MM/yyyy");
                }
                if (!SkyConvert.RongTht(txtKhoHang.EditValue))
                {
                    str1 = str1 + "Kho hàng: " + CommonFunction
                               .GetNameOfObject("DM_Kho", txtKhoHang.EditValue.ToString(), cnnData) + new string(' ', 10);

                }
                if (!SkyConvert.RongTht(txtNhomKH.EditValue))
                {
                    str1 = str1 + "Nhóm khách hàng: " + CommonFunction
                               .GetNameOfObject("DM_NhomKH", txtNhomKH.EditValue.ToString(), cnnData) + new string(' ', 10);
                }
                if (!SkyConvert.RongTht(txtKhachHang.EditValue))
                {
                    str1 = str1 + "Khách hàng: " + CommonFunction
                               .GetNameOfObject("DM_KhachHang", txtKhachHang.EditValue.ToString(), cnnData) + new string(' ', 10);
                }
                if (!SkyConvert.RongTht(txtTuSoHD.Text))
                {
                    str1 = str1 + "Chứng từ từ số: " + txtTuSoHD.Text + new string(' ', 10);
                }
                if (!SkyConvert.RongTht(txtDenSoHD.Text))
                {
                    str1 = str1 + "Chứng từ đến số: " + txtDenSoHD.Text + new string(' ', 10);
                }
                Openreport.ViewReportTht(cnnData, strSQL3, "BC_CongNoTheoHoaDonMua_ChiTiet", strFormula, strValue,
                    db[0], db[1], db[2], db[3]);
            }
            catch (Exception e)
            {
                SkyConvert.ThongBaoLoiTht(e.HResult, e.Message);
            }
        }

        private void Print()
        {
            string strPara = "BC_CongNoTheoHoaDonBan";
            string strpara1 = "TuNgay#DenNgay";
            string strValue = dETuNgay.DateTime.ToString("dd/MM/yyyy") + "#" +
                              dEDenNgay.DateTime.ToString("dd/MM/yyyy");
            string str1 = "";
            try
            {
                if (rst.Tables[0].Rows.Count < 1)
                {
                    SkyConvert.Msg("Không có dữ liệu in.", (int)EventValue.WARNING);
                    return;
                }
                if (!SkyConvert.RongTht(txtKhoHang.EditValue))
                {
                    str1 = str1 + "Kho hàng: " + CommonFunction
                               .GetNameOfObject("DM_Kho", txtKhoHang.EditValue.ToString(), cnnData) + new string(' ', 10);

                }
                if (!SkyConvert.RongTht(txtNhomKH.EditValue))
                {
                    str1 = str1 + "Nhóm khách hàng: " + CommonFunction
                               .GetNameOfObject("DM_NhomKH", txtNhomKH.EditValue.ToString(), cnnData) + new string(' ', 10);
                }
                if (!SkyConvert.RongTht(txtKhachHang.EditValue))
                {
                    str1 = str1 + "Khách hàng: " + CommonFunction
                               .GetNameOfObject("DM_KhachHang", txtKhachHang.EditValue.ToString(), cnnData) + new string(' ', 10);
                }
                if (!SkyConvert.RongTht(txtTuSoHD.Text))
                {
                    str1 = str1 + "Chứng từ từ số: " + txtTuSoHD.Text + new string(' ', 10);
                }
                if (!SkyConvert.RongTht(txtDenSoHD.Text))
                {
                    str1 = str1 + "Chứng từ đến số: " + txtDenSoHD.Text + new string(' ', 10);
                }
                Openreport.ViewReportTht(cnnData, strSQL1, strPara, strpara1 + "#DieuKien", strValue + "#" + str1, db[0], db[1], db[2], db[3]);
            }
            catch (Exception e)
            {
                SkyConvert.ThongBaoLoiTht(e.HResult, e.Message);
            }
        }

        private void Filter()
        {
            strCond1 = "";
            double dblTongCong;
            string strSQL3;
            gridControl1.DataSource = null;
            gridControl1.RefreshDataSource();
            gridControl2.DataSource = null;
            gridControl2.RefreshDataSource();
            try
            {
                if (Modul_HeThong.KiemTraQuyenDiaDiem((txtDiaDiem.CheckedComboBoxEditControl.EditValue != null) ? txtDiaDiem.CheckedComboBoxEditControl.EditValue.ToString() : "") == false)
                {
                    SkyConvert.Msg("Xin vui lòng chọn địa điểm", (int)EventValue.WARNING);
                    txtDiaDiem.Focus();
                    return;
                }
                if (SkyConvert.IsDate(dETuNgay.EditValue))
                {
                    if (!SkyConvert.RongTht(strCond1))
                    {
                        strCond1 = strCond1 + " AND ";
                    }
                    strCond1 = strCond1 + "SoCai.Ngay>=" + SkyConvert.InsSQLTht(SkyConvert.SQLDateTHT(dETuNgay.EditValue.ToString()).ToString());
                }
                if (SkyConvert.IsDate(dEDenNgay.EditValue))
                {
                    if (!SkyConvert.RongTht(strCond1))
                    {
                        strCond1 = strCond1 + " AND ";
                    }
                    strCond1 = strCond1 + "SoCai.Ngay<=" + SkyConvert.InsSQLTht(SkyConvert.SQLDateTHT(dEDenNgay.EditValue.ToString()).ToString());
                }
                //Loc theo dia diem
                if (!SkyConvert.RongTht(txtDiaDiem.CheckedComboBoxEditControl.EditValue))
                {
                    if (!SkyConvert.RongTht(strCond1))
                    {
                        strCond1 = strCond1 + " AND ";
                    }
                    string diadiem = txtDiaDiem.CheckedComboBoxEditControl.EditValue.ToString();
                    diadiem = diadiem.Replace(",", "','");
                    strCond1 = strCond1 + " SoCai.DiaDiem in ('" + diadiem + "')";
                }
                //So sanh tu so hoa don den so hoa don
                if (!SkyConvert.RongTht(txtTuSoHD.Text))
                {
                    if (!SkyConvert.RongTht(strCond1))
                    {
                        strCond1 = strCond1 + " AND ";
                    }
                    strCond1 = strCond1 + "SoCai.Chungtu>=" + SkyConvert.InsSQLTht(txtTuSoHD.Text);
                }
                if (!SkyConvert.RongTht(txtDenSoHD.Text))
                {
                    if (!SkyConvert.RongTht(strCond1))
                    {
                        strCond1 = strCond1 + " AND ";
                    }
                    strCond1 = strCond1 + "SoCai.Chungtu<=" + SkyConvert.InsSQLTht(txtDenSoHD.Text);
                }
                if (!SkyConvert.RongTht(txtKhoHang.EditValue))
                {
                    if (!SkyConvert.RongTht(strCond1))
                    {
                        strCond1 = strCond1 + " AND ";
                    }
                    strCond1 = strCond1 + "SoCai.KhoCode=" + SkyConvert.InsSQLTht(txtKhoHang.EditValue.ToString());
                }
                //Loc theo Khach hang
                if (!SkyConvert.RongTht(txtKhachHang.EditValue))
                {
                    if (!SkyConvert.RongTht(strCond1))
                    {
                        strCond1 = strCond1 + " AND ";
                    }
                    strCond1 = strCond1 + "DM_Khachhang.Code=" + SkyConvert.InsSQLTht(txtKhachHang.EditValue.ToString());
                }
                //Loc Nhom Khach Hang
                if (!SkyConvert.RongTht(txtNhomKH.EditValue))
                {
                    if (!SkyConvert.RongTht(strCond1))
                    {
                        strCond1 = strCond1 + " AND ";
                    }
                    strCond1 = strCond1 + "DM_Khachhang.NhomKH=" + SkyConvert.InsSQLTht(txtNhomKH.EditValue.ToString());
                }
                strSQL1 = SkyConvert.ReadSQL("BC_CongNoTheoHoaDonBan", cnnData);
                if (SkyConvert.RongTht(strSQL1))
                {
                    return;
                }
                if (!SkyConvert.RongTht(strCond1))
                {
                    strCond1 = " AND " + strCond1;
                }
                strSQL1 = strSQL1.Replace("{strCondition1}", strCond1);
                rst = SkyConvert.GetFieldsFromSQLTht(cnnData, strSQL1);

                if (rst.Tables[0].Rows.Count < 1)
                {
                    SkyConvert.Msg("Không tìm thấy dữ liệu thỏa mãn điều kiện!", (int)EventValue.WARNING);
                    return;
                }
                DataTable dt = new DataTable();
                dt = rst.Tables[0];
                int stt = 0;
                List<BaoCaoCongNoTheoHDBan> lstResult = new List<BaoCaoCongNoTheoHDBan>();
                foreach (DataRow row in dt.Rows)
                {
                    stt += 1;
                    BaoCaoCongNoTheoHDBan obj = new BaoCaoCongNoTheoHDBan();
                    obj.STT = stt;
                    obj.Ngay = SkyConvert.FormatDateTht(row["Ngay"]);
                    obj.ChungTu = row["ChungTu"].ToString();
                    obj.MaKhach = row["MaKhach"].ToString();
                    obj.TenKhach = row["TenKhach"].ToString();
                    obj.PsCo = SkyConvert.FormatNumber1Tht(row["PsCo"], ClSysTHT.bThapPhan);
                    obj.PsNo = SkyConvert.FormatNumber1Tht(row["PsNo"], ClSysTHT.bThapPhan);
                    obj.ConLai = SkyConvert.FormatNumber1Tht(row["ConLai"], ClSysTHT.bThapPhan);
                    lstResult.Add(obj);
                }
                gridControl1.DataSource = lstResult; gridControl1.RefreshDataSource();

                strSQL3 = "SELECT SUM(PsCo) AS PsCo,SUM(PsNo) PsNo,SUM(ConLai) ConLai from ( " + strSQL1 +
                          ") AS TongTien";
                lblTongCong.Text = "Tổng cộng: " + SkyConvert.FormatNumber1Tht(rst.Tables[0].Rows.Count, 0);
                txtPsCo.Text = SkyConvert.FormatNumber1Tht(SkyConvert.GetValueFromSQLTHT(strSQL3, "PsCo", cnnData),
                    ClSysTHT.bThapPhan);
                txtPsNo.Text = SkyConvert.FormatNumber1Tht(SkyConvert.GetValueFromSQLTHT(strSQL3, "PsNo", cnnData),
                    ClSysTHT.bThapPhan);
                txtConlai.Text = SkyConvert.FormatNumber1Tht(SkyConvert.GetValueFromSQLTHT(strSQL3, "ConLai", cnnData),
                    ClSysTHT.bThapPhan);
            }
            catch (Exception e)
            {
                SkyConvert.ThongBaoLoiTht(e.HResult, e.Message);
            }
        }

        private void BaoCaoCongNoTheoHoaDonBan_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.T)
            {
                Filter();
            }
            if (e.Control && e.KeyCode == Keys.P)
            {
                Print();
            }
            if (e.Control && e.KeyCode == Keys.Q || e.KeyCode == Keys.Escape)
            {
                this.Close();
            }
            if (e.Control && e.KeyCode == Keys.E)
            {
                CommonFunction.ExportExcel(gridControl1);
            }
        }

        private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            valueClicked = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ChungTu").ToString();
            RowColChange();
        }

        private void RowColChange()
        {
            strSQL2 = "";
            try
            {
                if (rst.Tables[0].Rows.Count < 1)
                {
                    return;
                }
                strSQL2 = SkyConvert.ReadSQL("BC_CongNoTheoHoaDonBan_ChiTiet", cnnData);
                if (SkyConvert.RongTht(strSQL2))
                {
                    return;
                }
                strCond2 = " AND SoCai.ChungTu='" + valueClicked + "' OR SoCai.SoHoaDon='" + valueClicked + "'";
                strCond2 = strCond1 + strCond2;
                strSQL2 = strSQL2.Replace("{strCondition1}", strCond2);
                DataSet rst2 = SkyConvert.GetFieldsFromSQLTht(cnnData, strSQL2);
                if (rst2.Tables[0].Rows.Count < 1)
                {
                    SkyConvert.Msg("Không tìm thấy dữ liệu thỏa mãn điều kiện!", (int)EventValue.WARNING);
                    return;
                }
                DataTable dt = new DataTable();
                dt = rst2.Tables[0];
                int stt = 0;
                List<BaoCaoCongNoTheoHDBan> lstResult = new List<BaoCaoCongNoTheoHDBan>();
                foreach (DataRow row in dt.Rows)
                {
                    stt += 1;
                    BaoCaoCongNoTheoHDBan obj = new BaoCaoCongNoTheoHDBan();
                    obj.STT = stt;
                    obj.Ngay = SkyConvert.FormatDateTht(row["Ngay"]);
                    obj.ChungTu = row["ChungTu"].ToString();
                    obj.GhiChu = row["GhiChu"].ToString();
                    obj.ThanhToan = SkyConvert.FormatNumber1Tht(row["PsNo"], ClSysTHT.bThapPhan);
                    lstResult.Add(obj);
                }
                gridControl2.DataSource = lstResult;
                gridControl2.RefreshDataSource();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
    }
    public class BaoCaoCongNoTheoHDBan
    {
        public int STT { get; set; }
        public string Ngay { get; set; }
        public string ChungTu { get; set; }
        public string MaKhach { get; set; }
        public string TenKhach { get; set; }
        public string PsCo { get; set; }
        public string PsNo { get; set; }
        public string ConLai { get; set; }
        public string GhiChu { get; set; }
        public string ThanhToan { get; set; }
    }
}

Commits for 17001_SKYPRO/trunk/03.Source/SkySolution/Sky.Reports/Forms/Sales/BaoCaoCongNoTheoHoaDonBan.cs

Diff revisions: vs.
Revision Author Commited Message
249 Diff Diff hopnguyenhaui picture hopnguyenhaui Thu 13 Jul, 2017 17:17:08 +0000
243 hopnguyenhaui picture hopnguyenhaui Wed 12 Jul, 2017 13:37:08 +0000