Esempio n. 1
0
        public bool MoveQuantityToMorthNow(int type)
        {
            bool result = false;

            try
            {
                BTPDAO                btpDAO            = new BTPDAO();
                ClusterDAO            clusterDAO        = new ClusterDAO();
                var                   ngay              = DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year;
                var                   dateNow           = DateTime.Now;
                int                   morthNow          = dateNow.Month;
                int                   yearNow           = dateNow.Year;
                var                   dateOld           = dateNow.AddMonths(-1);
                int                   morthOld          = dateOld.Month;
                int                   yearOld           = dateOld.Year;
                string                strSQL            = "Select * From Chuyen_SanPham Where Thang=" + morthOld + " and Nam=" + yearOld + " and MaChuyen in (" + AccountSuccess.strListChuyenId.Trim() + ") and IsFinish=0 and IsDelete=0";
                List <Chuyen_SanPham> listChuyenSanPham = new List <Chuyen_SanPham>();
                DataTable             dtTable           = dbclass.TruyVan_TraVe_DataTable(strSQL);
                if (dtTable != null && dtTable.Rows.Count > 0)
                {
                    int sttThucHien = 1;
                    foreach (DataRow row in dtTable.Rows)
                    {
                        Chuyen_SanPham csp = new Chuyen_SanPham();
                        csp.STT = row["STT"].ToString();
                        int.TryParse(row["STTThucHien"].ToString(), out sttThucHien);
                        csp.STTThucHien = sttThucHien;
                        csp.MaChuyen    = row["MaChuyen"].ToString();
                        csp.MaSanPham   = row["MaSanPham"].ToString();
                        int sanLuongKH = 0;
                        int.TryParse(row["SanLuongKeHoach"].ToString(), out sanLuongKH);
                        csp.SanLuongKeHoach = sanLuongKH;
                        int luyKeTH = 0;
                        int.TryParse(row["LuyKeTH"].ToString(), out luyKeTH);
                        csp.LuyKeTH = luyKeTH;
                        float nangXuatSanXuat = 0;
                        float.TryParse(row["NangXuatSanXuat"].ToString(), out nangXuatSanXuat);
                        csp.NangXuatSanXuat = nangXuatSanXuat;
                        csp.Thang           = morthOld;
                        csp.Nam             = yearOld;
                        listChuyenSanPham.Add(csp);
                    }
                }
                if (listChuyenSanPham.Count > 0)
                {
                    listChuyenSanPham = listChuyenSanPham.OrderBy(c => c.STTThucHien).ToList();
                    int sttThucHien = 0;
                    foreach (var csp in listChuyenSanPham)
                    {
                        if (type == 1)
                        {
                            csp.IsFinish = 1;
                            csp.IsFinishBTPThoatChuyen = true;
                            //    SuaThongTinPhanCong(csp);
                        }
                        else
                        {
                            sttThucHien++;
                            int sumBTPOfLine = 0;
                            var listBTP      = btpDAO.GetListBTPBySTT(csp.STT);
                            if (listBTP != null && listBTP.Count > 0)
                            {
                                sumBTPOfLine = listBTP.Where(c => c.IsEndOfLine).Sum(c => c.BTPNgay);
                            }
                            var     listClusterOfLine = clusterDAO.GetCumOfChuyen(int.Parse(csp.MaChuyen));
                            Cluster clusterEndLine    = null;
                            if (listClusterOfLine != null && listClusterOfLine.Count > 0)
                            {
                                clusterEndLine = listClusterOfLine.First(c => c.IsEndOfLine);
                            }

                            if (csp.LuyKeTH == 0)
                            {
                                var cspNew = new Chuyen_SanPham();
                                Parse.CopyObject(csp, ref cspNew);
                                cspNew.TimeAdd = dateNow;
                                cspNew.Thang   = morthNow;
                                cspNew.Nam     = yearNow;
                                cspNew.IsMoveQuantityFromMorthOld = true;
                                cspNew.STTThucHien = sttThucHien;
                                // var resultAdd = ThemPhanCong(cspNew);
                                //if (resultAdd.IsSuccsess)
                                //{
                                //    csp.IsFinish = 1;
                                //    csp.IsFinishBTPThoatChuyen = true;
                                //    SuaThongTinPhanCong(csp);

                                //    string sttPCC = GetSTTChuyenSanPham(cspNew.MaChuyen, cspNew.MaSanPham, cspNew.Thang, cspNew.Nam);
                                //    if (sumBTPOfLine > 0)
                                //    {
                                //        BTP btp = new BTP();
                                //        btp.STTChuyen_SanPham = sttPCC;
                                //        btp.IsEndOfLine = true;
                                //        btp.Ngay = dateNow.Date;
                                //        btp.STT = 1;
                                //        btp.TimeUpdate = dateNow.TimeOfDay;
                                //        btp.BTPNgay = sumBTPOfLine;
                                //        btp.CommandTypeId = 8;
                                //        btp.CumId = clusterEndLine.Id;
                                //      btpDAO.ThemOBJ(btp);
                                //    }
                                //}
                            }
                            else
                            {
                                int soLuongTon = csp.SanLuongKeHoach - csp.LuyKeTH;
                                var cspExist   = CheckExistPCC(csp.MaChuyen, csp.MaSanPham, morthNow, yearNow);
                                if (cspExist != null)
                                {
                                    cspExist.SanLuongKeHoach += soLuongTon;
                                    var rsMove = SuaThongTinPhanCong(cspExist);
                                    if (rsMove > 0)
                                    {
                                        csp.SanLuongKeHoach        = csp.LuyKeTH;
                                        csp.IsFinish               = 1;
                                        csp.IsFinishBTPThoatChuyen = true;
                                        // SuaThongTinPhanCong(csp);

                                        int btpOnLine = sumBTPOfLine - csp.LuyKeTH;
                                        if (btpOnLine > 0)
                                        {
                                            BTP btp = new BTP();
                                            btp.STTChuyen_SanPham = cspExist.STT;
                                            btp.IsEndOfLine       = true;
                                            btp.Ngay          = ngay;
                                            btp.STT           = 1;
                                            btp.TimeUpdate    = dateNow.TimeOfDay;
                                            btp.BTPNgay       = btpOnLine;
                                            btp.CommandTypeId = 8;
                                            btp.CumId         = clusterEndLine.Id;
                                            //  btpDAO.ThemOBJ(btp);
                                        }
                                    }
                                }
                                else
                                {
                                    var cspNew = new Chuyen_SanPham();
                                    Parse.CopyObject(csp, ref cspNew);
                                    cspNew.TimeAdd                    = dateNow;
                                    cspNew.Thang                      = morthNow;
                                    cspNew.Nam                        = yearNow;
                                    cspNew.SanLuongKeHoach            = soLuongTon;
                                    cspNew.IsMoveQuantityFromMorthOld = true;
                                    cspNew.LuyKeTH                    = 0;
                                    csp.STTThucHien                   = sttThucHien;
                                    //var rsMove = ThemPhanCong(cspNew);
                                    //if (rsMove.IsSuccsess)
                                    //{
                                    //    csp.SanLuongKeHoach = csp.LuyKeTH;
                                    //    csp.IsFinish = 1;
                                    //    csp.IsFinishBTPThoatChuyen = true;
                                    //    SuaThongTinPhanCong(csp);

                                    //    string sttPCC = GetSTTChuyenSanPham(cspNew.MaChuyen, cspNew.MaSanPham, cspNew.Thang, cspNew.Nam);
                                    //    int btpOnLine = sumBTPOfLine - csp.LuyKeTH;
                                    //    if (btpOnLine > 0)
                                    //    {
                                    //        BTP btp = new BTP();
                                    //        btp.STTChuyen_SanPham = sttPCC;
                                    //        btp.IsEndOfLine = true;
                                    //        btp.Ngay = dateNow.Date;
                                    //        btp.STT = 1;
                                    //        btp.TimeUpdate = dateNow.TimeOfDay;
                                    //        btp.BTPNgay = btpOnLine;
                                    //        btp.CommandTypeId = 8;
                                    //        btp.CumId = clusterEndLine.Id;
                                    //        btpDAO.ThemOBJ(btp);
                                    //    }
                                    //}
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(result);
        }