예제 #1
0
        //##### Chen Production Codes Ends #####

        //########## Amin Codes Starts ##########
        public FGReduceLotDetails CheckFGReduceLotNum(string Company, string LotNum)
        {
            FGReduceLotDetails fgReduceLotDetails = new FGReduceLotDetails();
            DAL objDAL = new DAL();

            fgReduceLotDetails = objDAL.CheckFGReduceLotNum(Company, LotNum);

            return(fgReduceLotDetails);
        }
예제 #2
0
        //Ashraf Start Here
        public string GenerateFGReduceCSV(List <FGReduceLotDetails> objFGReduceInvTransList)
        {
            string msg = string.Empty;

            string date_Day   = "";
            string date_Month = "";
            string date_Year  = "";

            int yyyyMMdd = 0; //date in correct format to compare

            int oldest_Date = 0;

            string lblWeekMonth = "";
            string tempMonth    = "";
            string tempWeek     = "";

            bool isValidProdDate = true;


            FGReduceLotDetails objFGReduce = null;

            if (objFGReduceInvTransList.Count > 1)
            {
                for (int i = 0; i < objFGReduceInvTransList.Count; i++)
                {
                    objFGReduce = new FGReduceLotDetails();
                    StringBuilder sbQry = new StringBuilder();

                    /// Get Lot No details in the system
                    //sbQry.Append("select TOP(1) * from erp.partbin ");
                    //sbQry.Append($"where Company = '{objFGReduceInvTransList[i].Company}' and LotNum = '{objFGReduceInvTransList[i].LotNum}' ");

                    sbQry.Append("select TOP(1) pb.Company, pb.PartNum, pb.LotNum, pb.OnhandQty, pb.DimCode, p.PartDescription, pl.FS_WeekMth_c, pl.FS_Month_c, pl.FS_ProdDate_c from erp.partbin pb ");
                    sbQry.Append("join PartLot pl on pl.LotNum = pb.LotNum and pl.PartNum = pb.PartNum join Part p on p.Company = pb.Company and p.PartNum = pb.PartNum ");
                    sbQry.Append($"where pb.Company = '{objFGReduceInvTransList[i].Company}' and pb.LotNum = '{objFGReduceInvTransList[i].LotNum}' and pb.PartNum = '{objFGReduceInvTransList[i].PartNum}'");


                    using (SqlConnection connection = new SqlConnection(EpicorConStr))
                    {
                        connection.Open();
                        SqlCommand command = new SqlCommand(sbQry.ToString(), connection);
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                objFGReduce.Company   = reader["Company"].ToString();
                                objFGReduce.LotNum    = reader["LotNum"].ToString();
                                objFGReduce.OnhandQty = Convert.ToDecimal(reader["OnhandQty"]);
                                objFGReduce.PartNum   = reader["PartNum"].ToString();

                                objFGReduce.Uom             = reader["DimCode"].ToString();
                                objFGReduce.PartDescription = reader["PartDescription"].ToString();
                                objFGReduce.WeekOfMonth     = reader["FS_WeekMth_c"].ToString();
                                objFGReduce.Month           = reader["FS_Month_c"].ToString();
                                objFGReduce.ProdDate        = reader["FS_ProdDate_c"].ToString();

                                //For testing purpose. Simply set date if there are no data in the table
                                if (objFGReduce.WeekOfMonth == "")
                                {
                                    objFGReduce.WeekOfMonth = "EmptyWeek";
                                }

                                if (objFGReduce.Month == "")
                                {
                                    objFGReduce.Month = "EmptyMonth";
                                }


                                if (!string.IsNullOrEmpty(objFGReduce.ProdDate)) //need to add extra check. If corrrect format as DDMMYYYY
                                {
                                    date_Day        = objFGReduce.ProdDate.Substring(0, 2);
                                    date_Month      = objFGReduce.ProdDate.Substring(2, 2);
                                    date_Year       = objFGReduce.ProdDate.Substring(4, 4);
                                    isValidProdDate = true;
                                }
                                else
                                {
                                    isValidProdDate = false;
                                    //objFGReduce.ProdDate = "99999999";
                                    //date_Day = objFGReduce.ProdDate.Substring(0, 2);
                                    //date_Month = objFGReduce.ProdDate.Substring(2, 2);
                                    //date_Year = objFGReduce.ProdDate.Substring(4, 4);
                                }

                                if (isValidProdDate == true)
                                {
                                    yyyyMMdd = Convert.ToInt32(date_Year + date_Month + date_Day);

                                    //first index is the ori lot,
                                    if (oldest_Date == 0)
                                    {
                                        oldest_Date = yyyyMMdd;
                                        tempWeek    = objFGReduce.WeekOfMonth;
                                        tempMonth   = objFGReduce.Month;
                                    }

                                    //No need to check i index. Because only 2 lot in this case
                                    if (yyyyMMdd < oldest_Date)
                                    {
                                        lblWeekMonth = objFGReduce.Month + objFGReduce.WeekOfMonth;
                                    }
                                    else
                                    {
                                        lblWeekMonth = tempMonth + tempWeek;
                                    }
                                }

                                else
                                {
                                    lblWeekMonth = "EmptyProdDate";
                                }

                                int tempOHQint = (int)objFGReduce.OnhandQty;

                                //string msg = string.Empty;
                                try
                                {
                                    string fileName = $@"\\{Conn.FGReduceLocation}\{objFGReduce.Company}\FGReduce\{objFGReduce.PartNum}_{objFGReduce.LotNum}_{tempOHQint}.csv";
                                    using (StreamWriter sw = System.IO.File.CreateText(fileName))
                                    {
                                        sw.WriteLine("Part Num,Lot Num,Qty,UOM,Part Description,WeekAndMonth");

                                        sw.WriteLine(string.Format("{0},{1},{2},{3},{4},{5}",
                                                                   objFGReduce.PartNum,
                                                                   objFGReduce.LotNum,
                                                                   tempOHQint,
                                                                   objFGReduce.Uom,
                                                                   objFGReduce.PartDescription,
                                                                   lblWeekMonth));
                                        //msg = $"\nLabel:{fileName} Generated Sucessfully!";
                                    }
                                }
                                catch (Exception ex)
                                {
                                    msg = $"Label Generate Failed. \nError : {ex.Message.ToString()}";
                                    //throw new Exception(msg);
                                }

                                //Ashraf End Here
                            }
                        }
                        connection.Close();
                    }
                }
            }
            return(msg);
        }
예제 #3
0
        public string UpdateFGReduce(FGReduceLotDetails obj)
        {
            string msg = "";

            if (obj == null)
            {
                return("Empty object.");
            }

            string newLotNum = obj.LotNum;

            /*
             * if (newLotNum.Length > 15)
             *  newLotNum = newLotNum.Substring(0, 15) + DateTime.Now.ToString("yyyyMMddHHmmss");
             * else
             *  newLotNum = newLotNum + DateTime.Now.ToString("yyyyMMddHHmmss");
             */
            newLotNum = newLotNum + 'X';

            //Check If Lot+X already exist or not in PartTran
            FGReduceLotDetails fgDetails = new FGReduceLotDetails();
            DAL objDAL = new DAL();

            fgDetails = objDAL.CheckLotInPartTran(obj.Company, newLotNum, obj.PartNum);

            //If not exist, create lot
            if (string.IsNullOrEmpty(fgDetails.LotNum))
            {
                //Lot Creation
                LotCreationServices lc = new LotCreationServices();
                lc.Begin(newLotNum, obj.Company, obj.Plant, obj.PartNum);
            }

            msg = $"{obj.LotNum} -> {newLotNum}";

            //TEST
            if (obj.Plant == null)
            {
                obj.Plant = "";
            }

            try
            {
                //Inventory Transfer
                InventoryTransferServices it = new InventoryTransferServices();
                InvTransfer invTransfer      = new InvTransfer();
                invTransfer.company      = obj.Company;
                invTransfer.plant        = obj.Plant;
                invTransfer.id           = "FG Reduce : " + msg;
                invTransfer.partNum      = obj.PartNum;
                invTransfer.qty          = obj.ModifiedQty;
                invTransfer.uom          = obj.Uom;
                invTransfer.frmWarehouse = obj.FromWarehouse;
                invTransfer.frmBinNum    = obj.FromBinNum;
                invTransfer.frmLotNum    = obj.LotNum;
                invTransfer.toWarehouse  = obj.ToWarehouse;
                invTransfer.toBinNum     = obj.ToBinNum;
                invTransfer.toLotNum     = newLotNum;

                it.doInvTransfer(invTransfer);

                msg = $"Successfully reduce. {obj.LotNum} -> {newLotNum}";

                //Ashraf Start Here
                List <FGReduceLotDetails> objFGReduceInvTransList = new List <FGReduceLotDetails>();

                FGReduceLotDetails objFG = new FGReduceLotDetails();
                objFG.LotNum  = obj.LotNum;
                objFG.Company = obj.Company;
                objFG.PartNum = obj.PartNum;
                objFGReduceInvTransList.Add(objFG);

                FGReduceLotDetails objFGNew = new FGReduceLotDetails();
                objFGNew.LotNum  = newLotNum;
                objFGNew.Company = obj.Company;
                objFGNew.PartNum = obj.PartNum;
                objFGReduceInvTransList.Add(objFGNew);

                msg = msg + GenerateFGReduceCSV(objFGReduceInvTransList);
                //Ashraf End Here
            }
            catch (Exception ex)
            {
                msg = ex.Message.ToString();
            }

            return(msg);
        }