예제 #1
0
 public int Them(BOXuLyKho item, List <BOXuLyKhoChiTiet> lsArray, Transit mTransit)
 {
     ThemMoi(item, lsArray, mTransit);
     frmXuLyKho.AddObject(item.XuLyKho);
     frmXuLyKho.Commit();
     return(item.XuLyKho.ChinhKhoID);
 }
예제 #2
0
 public int Them(BOXuLyKho item, List<BOXuLyKhoChiTiet> lsArray, Transit mTransit)
 {
     ThemMoi(item, lsArray, mTransit);
     frmXuLyKho.AddObject(item.XuLyKho);
     frmXuLyKho.Commit();
     return item.XuLyKho.ChinhKhoID;
 }
예제 #3
0
 private int Xoa(BOXuLyKho item, Transit mTransit)
 {
     item.XuLyKho.Deleted = true;
     frmXuLyKho.Update(item.XuLyKho);
     return(item.XuLyKho.ChinhKhoID);
 }
예제 #4
0
 private int Them(BOXuLyKho item, Transit mTransit)
 {
     frmXuLyKho.AddObject(item.XuLyKho);
     return(item.XuLyKho.ChinhKhoID);
 }
예제 #5
0
 private int Sua(BOXuLyKho item, Transit mTransit)
 {
     item.XuLyKho.Edit = false;
     frmXuLyKho.Update(item.XuLyKho);
     return(item.XuLyKho.ChinhKhoID);
 }
예제 #6
0
        private int ThemMoi(BOXuLyKho item, List <BOXuLyKhoChiTiet> lsArray, Transit mTransit)
        {
            if (lsArray != null)
            {
                List <Data.TONKHOTONG> lsTonKhoTong = new List <TONKHOTONG>();
                List <Data.TONKHO>     lsTonKho     = new List <TONKHO>();
                foreach (BOXuLyKhoChiTiet line in lsArray)
                {
                    IQueryable <Data.TONKHO> lsArrayLine = null;
                    switch (item.XuLyKho.LoaiID)
                    {
                    case 1:
                        lsArrayLine = frmTonKho.Query().Where(s => s.DonViID == line.TonKho.DonViID && s.MonID == line.TonKho.MonID && s.KhoID == item.XuLyKho.KhoID && s.SoLuongTon > 0).OrderBy(s => s.NgayHetHan).ThenBy(s => s.TonKhoID);
                        if (lsArrayLine.Count() > 0 && line.TonKho.SoLuongNhap < lsArrayLine.Sum(s => s.SoLuongTon) && line.TonKho.SoLuongNhap > 0)
                        {
                            foreach (var l in lsArrayLine)
                            {
                                if (line.TonKho.SoLuongNhap > 0)
                                {
                                    Data.TONKHOTONG tonkhotong = null;
                                    if (lsTonKhoTong.Exists(s => s.KhoID == item.XuLyKho.KhoID && s.MonID == line.TonKho.MonID && s.DonViID == line.TonKho.DonViID))
                                    {
                                        tonkhotong = lsTonKhoTong.Find(s => s.KhoID == item.XuLyKho.KhoID && s.MonID == line.TonKho.MonID && s.DonViID == line.TonKho.DonViID);
                                    }
                                    else
                                    {
                                        tonkhotong = KiemTraTonKhoTong(frmTonKhoTong, (int)item.XuLyKho.KhoID, (int)line.TonKho.MonID, (int)line.TonKho.DonViID);
                                        lsTonKhoTong.Add(tonkhotong);
                                    }
                                    tonkhotong.SoLuongTon       += line.TonKho.SoLuongNhap;
                                    tonkhotong.SoLuongDieuChinh += line.TonKho.SoLuongNhap;
                                    Data.TONKHO tonkho = null;
                                    if (lsTonKho.Exists(s => s.TonKhoID == l.TonKhoID))
                                    {
                                        tonkho = lsTonKho.Find(s => s.TonKhoID == l.TonKhoID);
                                    }
                                    else
                                    {
                                        tonkho = l;
                                        lsTonKho.Add(tonkho);
                                    }
                                    line.XuLyKhoChiTiet.TONKHO = new TONKHO();
                                    line.XuLyKhoChiTiet.TONKHO.PhatSinhTuTonKhoID = tonkho.TonKhoID;
                                    line.XuLyKhoChiTiet.TONKHO.LoaiPhatSinhID     = (int)item.XuLyKho.LoaiID;
                                    CopyTonKho(line.XuLyKhoChiTiet.TONKHO, tonkho);

                                    if (tonkho.SoLuongTon > line.TonKho.SoLuongNhap)
                                    {
                                        line.XuLyKhoChiTiet.TONKHO.SoLuongPhatSinh = tonkho.SoLuongTon - line.TonKho.SoLuongNhap;
                                        tonkho.SoLuongTon      += line.TonKho.SoLuongNhap;
                                        line.TonKho.SoLuongNhap = 0;
                                    }
                                    else
                                    {
                                        line.XuLyKhoChiTiet.TONKHO.SoLuongPhatSinh = line.TonKho.SoLuongNhap - tonkho.SoLuongTon;
                                        line.TonKho.SoLuongNhap += tonkho.SoLuongTon;
                                        tonkho.SoLuongTon        = 0;
                                    }
                                }
                            }
                        }
                        break;

                    case 2:
                    case 3:
                        lsArrayLine = frmTonKho.Query().Where(s => s.DonViID == line.TonKho.DonViID && s.MonID == line.TonKho.MonID && s.KhoID == item.XuLyKho.KhoID && s.SoLuongTon > 0).OrderBy(s => s.NgayHetHan).ThenBy(s => s.TonKhoID);
                        if (lsArrayLine.Count() > 0 && line.TonKho.SoLuongNhap < lsArrayLine.Sum(s => s.SoLuongTon) && line.TonKho.SoLuongNhap > 0)
                        {
                            foreach (var l in lsArrayLine)
                            {
                                if (line.TonKho.SoLuongNhap > 0)
                                {
                                    Data.TONKHOTONG tonkhotong = null;
                                    if (lsTonKhoTong.Exists(s => s.KhoID == item.XuLyKho.KhoID && s.MonID == line.TonKho.MonID && s.DonViID == line.TonKho.DonViID))
                                    {
                                        tonkhotong = lsTonKhoTong.Find(s => s.KhoID == item.XuLyKho.KhoID && s.MonID == line.TonKho.MonID && s.DonViID == line.TonKho.DonViID);
                                    }
                                    else
                                    {
                                        tonkhotong = KiemTraTonKhoTong(frmTonKhoTong, (int)item.XuLyKho.KhoID, (int)line.TonKho.MonID, (int)line.TonKho.DonViID);
                                        lsTonKhoTong.Add(tonkhotong);
                                    }
                                    tonkhotong.SoLuongTon -= line.TonKho.SoLuongNhap;
                                    if (item.XuLyKho.LoaiID == 2)
                                    {
                                        tonkhotong.SoLuongMat += line.TonKho.SoLuongNhap;
                                    }
                                    if (item.XuLyKho.LoaiID == 3)
                                    {
                                        tonkhotong.SoLuongHu += line.TonKho.SoLuongNhap;
                                    }

                                    Data.TONKHO tonkho = null;
                                    if (lsTonKho.Exists(s => s.TonKhoID == l.TonKhoID))
                                    {
                                        tonkho = lsTonKho.Find(s => s.TonKhoID == l.TonKhoID);
                                    }
                                    else
                                    {
                                        tonkho = l;
                                        lsTonKho.Add(tonkho);
                                    }
                                    line.XuLyKhoChiTiet.TONKHO = new TONKHO();
                                    line.XuLyKhoChiTiet.TONKHO.PhatSinhTuTonKhoID = tonkho.TonKhoID;
                                    line.XuLyKhoChiTiet.TONKHO.LoaiPhatSinhID     = (int)item.XuLyKho.LoaiID;
                                    CopyTonKho(line.XuLyKhoChiTiet.TONKHO, tonkho);

                                    if (tonkho.SoLuongTon > line.TonKho.SoLuongNhap)
                                    {
                                        line.XuLyKhoChiTiet.TONKHO.SoLuongPhatSinh = tonkho.SoLuongTon - line.TonKho.SoLuongNhap;
                                        tonkho.SoLuongTon      -= line.TonKho.SoLuongNhap;
                                        line.TonKho.SoLuongNhap = 0;
                                    }
                                    else
                                    {
                                        line.XuLyKhoChiTiet.TONKHO.SoLuongPhatSinh = line.TonKho.SoLuongNhap - tonkho.SoLuongTon;
                                        line.TonKho.SoLuongNhap -= tonkho.SoLuongTon;
                                        tonkho.SoLuongTon        = 0;
                                    }
                                }
                            }
                        }
                        break;

                    default:
                        break;
                    }

                    line.XuLyKho       = new XULYKHO();
                    line.XuLyKho.KhoID = item.XuLyKho.KhoID;
                    item.XuLyKho.XULYKHOCHITIETs.Add(line.XuLyKhoChiTiet);
                }
                item.XuLyKho.TongTien = lsArray.Sum(s => s.TonKho.SoLuongNhap * s.TonKho.GiaBan);
                foreach (TONKHO i in lsTonKho)
                {
                    frmTonKho.Update(i);
                }
                foreach (TONKHOTONG i in lsTonKhoTong)
                {
                    frmTonKhoTong.Update(i);
                }
                frmTonKho.Commit();
                frmTonKhoTong.Commit();
            }
            return(item.XuLyKho.ChinhKhoID);
        }
예제 #7
0
        private int ThemMoi(BOXuLyKho item, List<BOXuLyKhoChiTiet> lsArray, Transit mTransit)
        {
            if (lsArray != null)
            {
                List<Data.TONKHOTONG> lsTonKhoTong = new List<TONKHOTONG>();
                List<Data.TONKHO> lsTonKho = new List<TONKHO>();
                foreach (BOXuLyKhoChiTiet line in lsArray)
                {
                    IQueryable<Data.TONKHO> lsArrayLine = null;
                    switch (item.XuLyKho.LoaiID)
                    {
                        case 1:
                            lsArrayLine = frmTonKho.Query().Where(s => s.DonViID == line.TonKho.DonViID && s.MonID == line.TonKho.MonID && s.KhoID == item.XuLyKho.KhoID && s.SoLuongTon > 0).OrderBy(s => s.NgayHetHan).ThenBy(s => s.TonKhoID);
                            if (lsArrayLine.Count() > 0 && line.TonKho.SoLuongNhap < lsArrayLine.Sum(s => s.SoLuongTon) && line.TonKho.SoLuongNhap > 0)
                            {
                                foreach (var l in lsArrayLine)
                                {
                                    if (line.TonKho.SoLuongNhap > 0)
                                    {
                                        Data.TONKHOTONG tonkhotong = null;
                                        if (lsTonKhoTong.Exists(s => s.KhoID == item.XuLyKho.KhoID && s.MonID == line.TonKho.MonID && s.DonViID == line.TonKho.DonViID))
                                        {
                                            tonkhotong = lsTonKhoTong.Find(s => s.KhoID == item.XuLyKho.KhoID && s.MonID == line.TonKho.MonID && s.DonViID == line.TonKho.DonViID);
                                        }
                                        else
                                        {
                                            tonkhotong = KiemTraTonKhoTong(frmTonKhoTong, (int)item.XuLyKho.KhoID, (int)line.TonKho.MonID, (int)line.TonKho.DonViID);
                                            lsTonKhoTong.Add(tonkhotong);
                                        }
                                        tonkhotong.SoLuongTon += line.TonKho.SoLuongNhap;
                                        tonkhotong.SoLuongDieuChinh += line.TonKho.SoLuongNhap;
                                        Data.TONKHO tonkho = null;
                                        if (lsTonKho.Exists(s => s.TonKhoID == l.TonKhoID))
                                        {
                                            tonkho = lsTonKho.Find(s => s.TonKhoID == l.TonKhoID);
                                        }
                                        else
                                        {
                                            tonkho = l;
                                            lsTonKho.Add(tonkho);
                                        }
                                        line.XuLyKhoChiTiet.TONKHO = new TONKHO();
                                        line.XuLyKhoChiTiet.TONKHO.PhatSinhTuTonKhoID = tonkho.TonKhoID;
                                        line.XuLyKhoChiTiet.TONKHO.LoaiPhatSinhID = (int)item.XuLyKho.LoaiID;
                                        CopyTonKho(line.XuLyKhoChiTiet.TONKHO, tonkho);

                                        if (tonkho.SoLuongTon > line.TonKho.SoLuongNhap)
                                        {
                                            line.XuLyKhoChiTiet.TONKHO.SoLuongPhatSinh = tonkho.SoLuongTon - line.TonKho.SoLuongNhap;
                                            tonkho.SoLuongTon += line.TonKho.SoLuongNhap;
                                            line.TonKho.SoLuongNhap = 0;
                                        }
                                        else
                                        {
                                            line.XuLyKhoChiTiet.TONKHO.SoLuongPhatSinh = line.TonKho.SoLuongNhap - tonkho.SoLuongTon;
                                            line.TonKho.SoLuongNhap += tonkho.SoLuongTon;
                                            tonkho.SoLuongTon = 0;
                                        }
                                    }
                                }
                            }
                            break;
                        case 2:
                        case 3:
                            lsArrayLine = frmTonKho.Query().Where(s => s.DonViID == line.TonKho.DonViID && s.MonID == line.TonKho.MonID && s.KhoID == item.XuLyKho.KhoID && s.SoLuongTon > 0).OrderBy(s => s.NgayHetHan).ThenBy(s => s.TonKhoID);
                            if (lsArrayLine.Count() > 0 && line.TonKho.SoLuongNhap < lsArrayLine.Sum(s => s.SoLuongTon) && line.TonKho.SoLuongNhap > 0)
                            {
                                foreach (var l in lsArrayLine)
                                {
                                    if (line.TonKho.SoLuongNhap > 0)
                                    {
                                        Data.TONKHOTONG tonkhotong = null;
                                        if (lsTonKhoTong.Exists(s => s.KhoID == item.XuLyKho.KhoID && s.MonID == line.TonKho.MonID && s.DonViID == line.TonKho.DonViID))
                                        {
                                            tonkhotong = lsTonKhoTong.Find(s => s.KhoID == item.XuLyKho.KhoID && s.MonID == line.TonKho.MonID && s.DonViID == line.TonKho.DonViID);
                                        }
                                        else
                                        {
                                            tonkhotong = KiemTraTonKhoTong(frmTonKhoTong, (int)item.XuLyKho.KhoID, (int)line.TonKho.MonID, (int)line.TonKho.DonViID);
                                            lsTonKhoTong.Add(tonkhotong);
                                        }
                                        tonkhotong.SoLuongTon -= line.TonKho.SoLuongNhap;
                                        if (item.XuLyKho.LoaiID == 2)
                                        {
                                            tonkhotong.SoLuongMat += line.TonKho.SoLuongNhap;
                                        }
                                        if (item.XuLyKho.LoaiID == 3)
                                        {
                                            tonkhotong.SoLuongHu += line.TonKho.SoLuongNhap;
                                        }

                                        Data.TONKHO tonkho = null;
                                        if (lsTonKho.Exists(s => s.TonKhoID == l.TonKhoID))
                                        {
                                            tonkho = lsTonKho.Find(s => s.TonKhoID == l.TonKhoID);
                                        }
                                        else
                                        {
                                            tonkho = l;
                                            lsTonKho.Add(tonkho);
                                        }
                                        line.XuLyKhoChiTiet.TONKHO = new TONKHO();
                                        line.XuLyKhoChiTiet.TONKHO.PhatSinhTuTonKhoID = tonkho.TonKhoID;
                                        line.XuLyKhoChiTiet.TONKHO.LoaiPhatSinhID = (int)item.XuLyKho.LoaiID;
                                        CopyTonKho(line.XuLyKhoChiTiet.TONKHO, tonkho);

                                        if (tonkho.SoLuongTon > line.TonKho.SoLuongNhap)
                                        {
                                            line.XuLyKhoChiTiet.TONKHO.SoLuongPhatSinh = tonkho.SoLuongTon - line.TonKho.SoLuongNhap;
                                            tonkho.SoLuongTon -= line.TonKho.SoLuongNhap;
                                            line.TonKho.SoLuongNhap = 0;
                                        }
                                        else
                                        {
                                            line.XuLyKhoChiTiet.TONKHO.SoLuongPhatSinh = line.TonKho.SoLuongNhap - tonkho.SoLuongTon;
                                            line.TonKho.SoLuongNhap -= tonkho.SoLuongTon;
                                            tonkho.SoLuongTon = 0;
                                        }
                                    }
                                }
                            }
                            break;
                        default:
                            break;
                    }

                    line.XuLyKho = new XULYKHO();
                    line.XuLyKho.KhoID = item.XuLyKho.KhoID;
                    item.XuLyKho.XULYKHOCHITIETs.Add(line.XuLyKhoChiTiet);
                }
                item.XuLyKho.TongTien = lsArray.Sum(s => s.TonKho.SoLuongNhap * s.TonKho.GiaBan);
                foreach (TONKHO i in lsTonKho)
                {
                    frmTonKho.Update(i);
                }
                foreach (TONKHOTONG i in lsTonKhoTong)
                {
                    frmTonKhoTong.Update(i);
                }
                frmTonKho.Commit();
                frmTonKhoTong.Commit();
            }
            return item.XuLyKho.ChinhKhoID;
        }
예제 #8
0
 private int Xoa(BOXuLyKho item, Transit mTransit)
 {
     item.XuLyKho.Deleted = true;
     frmXuLyKho.Update(item.XuLyKho);
     return item.XuLyKho.ChinhKhoID;
 }
예제 #9
0
 private int Them(BOXuLyKho item, Transit mTransit)
 {
     frmXuLyKho.AddObject(item.XuLyKho);
     return item.XuLyKho.ChinhKhoID;
 }
예제 #10
0
 private int Sua(BOXuLyKho item, Transit mTransit)
 {
     item.XuLyKho.Edit = false;
     frmXuLyKho.Update(item.XuLyKho);
     return item.XuLyKho.ChinhKhoID;
 }