Hiển thị các bài đăng có nhãn Linq. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Linq. Hiển thị tất cả bài đăng

Thứ Năm, 13 tháng 2, 2020

Khi đa luồng kết hợp bất đồng bộ.


#region Khai báo list
        Library.Utilities.ThreadCls threads;

        System.Collections.Generic.List<KhachHang> objKH = new System.Collections.Generic.List<KhachHang>();
        System.Collections.Generic.List<TienCongNo> dauKy = new System.Collections.Generic.List<TienCongNo>();
        System.Collections.Generic.List<NoHoaDonDauKy> noDauKyHd1 = new System.Collections.Generic.List<NoHoaDonDauKy>();
        System.Collections.Generic.List<TienCongNo> objHD_NDK = new System.Collections.Generic.List<TienCongNo>();
        System.Collections.Generic.List<TienSoQuy> noDauKySq1 = new System.Collections.Generic.List<TienSoQuy>();
        System.Collections.Generic.List<TienCongNo> objSQ_NDK = new System.Collections.Generic.List<TienCongNo>();
        System.Collections.Generic.List<TienCongNo> objPhatSinh = new System.Collections.Generic.List<TienCongNo>();
        System.Collections.Generic.List<TienCongNo> objDaThu = new System.Collections.Generic.List<TienCongNo>();
        System.Collections.Generic.List<TienCongNo> objKhauTru = new System.Collections.Generic.List<TienCongNo>();
        System.Collections.Generic.List<TienCongNo> objThuTruoc = new System.Collections.Generic.List<TienCongNo>();
        System.Collections.Generic.List<TienCongNo> objThuTruocTrongKy = new System.Collections.Generic.List<TienCongNo>();
        System.Collections.Generic.List<DataCongNo> objList = new System.Collections.Generic.List<DataCongNo>();

Import tự động


var excel = new LinqToExcel.ExcelQueryFactory(Tag.ToString());
                    System.Collections.Generic.List<CongNoDauKy> list = Library.Import.ExcelAuto.ConvertDataTable<CongNoDauKy>(Library.Import.ExcelAuto.GetDataExcel(excel, gv, itemSheet));

                    gc.DataSource = list;

#region Excel tự động
using System.Linq;

namespace Library.Import
{
    public static class ExcelAuto
    {
        public class GridviewInfo
        {
            public string FieldName { get; set; }
            public string Caption { get; set; }
        }

Get item trong GridLookUpEdit


private void GlkCustomer_EditValueChanged(object sender, EventArgs e)
        {
            try
            {
                var item = sender as DevExpress.XtraEditors.GridLookUpEdit;
                if (item.EditValue == null) return;

                txtCustomer.Text = item.Properties.View.GetFocusedRowCellValue("Name").ToString();
            }
            catch { }
        }

Đa luồng công nợ


private object objLock = new object();
        private bool isStop = false;
        private int _taskIndex;

        private List<BackgroundWorker> Threads = new List<BackgroundWorker>();

        private List<CongNoItem>
            _noDauKy,
            _phatSinh,
            _daThu,
            _khauTru,
            _thuTruocA,
            _thuTruocB,
            _conNo;

Join nhiều điều kiện


var list = (from p in db.xkXuatKhos
                                join ct in db.xkTaiSans on p.MaXK equals ct.MaXK
                                join bh in db.xkBanHangs on p.MaBanHang equals bh.MaBH
                                join bhvt in db.xkBanHang_VatTus on  ( bh.MaBH+"&"+ ct.MaLTS ) equals (  bhvt.MaBH+"&"+  bhvt.MaLTS )
                                join ts in db.tsLoaiTaiSans on ct.MaLTS equals ts.MaLTS
                                join dvt in db.tsLoaiTaiSan_DVTs on ts.MaDVT equals dvt.MaDVT
                                where p.MaXK == maXK
                                select new
                                {
                                    ts.TenLTS,
                                    ts.KyHieu,
                                    dvt.TenDVT,
                                    SoLuongYeuCau=bhvt.SoLuongQuyDoi-bhvt.SoLuongDaXuatKho+ct.SoLuong,
                                    SoLuongThucXuat=ct.SoLuong,
                                    DonGia=ct.DonGia,
                                    ThanhTien=ct.SoLuong*ct.DonGia
                                }).AsEnumerable().Select((p, Index) => new
                                {
                                    STT = Index + 1,
                                    p.TenLTS,
                                    p.KyHieu,
                                    p.TenDVT,
                                    p.SoLuongYeuCau,
                                    p.SoLuongThucXuat,
                                    p.DonGia,
                                    p.ThanhTien
                                }).ToList();

AddRange


foreach (var item in List_tn)
            {
                var List_mb = (from tn in db.tnToaNhas
                               join mb in db.mbMatBangs on tn.MaTN equals mb.MaTN

                               join lmb in db.mbLoaiMatBangs on mb.MaLMB equals lmb.MaLMB

                               join tt in db.mbTrangThais on mb.MaTT equals tt.MaTT
                               where tn.MaTN == item.MaTN
                               select new LtData
                               {
                                   TenTN = tn.TenTN,

                                   TongDienTich = db.mbMatBangs.Where(o => o.MaTN == item.MaTN).Sum(o => o.DienTich),

                                   //Đang sử dụng
                                   CanHoThue = tt.ChoThue == false & lmb.MaNMB == 1 ? mb.DienTich : 0,
                                   VanPhongThue = tt.ChoThue == false & lmb.MaNMB == 2 ? mb.DienTich : 0,
                                   KhacThue = tt.ChoThue == false & lmb.MaNMB == 3 ? mb.DienTich : 0,
                                   TongDienTichThue = tt.ChoThue == false ? mb.DienTich : 0,

                                   //Chưa sử dụng
                                   CanHoTrong = tt.ChoThue == true & lmb.MaNMB == 1 ? mb.DienTich : 0,
                                   VanPhongTrong = tt.ChoThue == true & lmb.MaNMB == 2 ? mb.DienTich : 0,
                                   KhacTrong = tt.ChoThue == true & lmb.MaNMB == 3 ? mb.DienTich : 0,
                                   TongDienTichTrong = tt.ChoThue == true ? mb.DienTich : 0,

                               }).ToList();
                ltData.AddRange(List_mb);
               
            }

.Skip(1).Take(30)


var objYeuCau = _db.tnycYeuCaus.Where(_ => _.IsCoLichSu == false).ToList(); //.Skip(1).Take(30)
Skip: bắt đầu từ
Take: lấy bao nhiêu