Ejemplo n.º 1
0
        private DataTable GetTrSnInfo(string trSn)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();
            DataTable dt = new DataTable();

            try
            {
                dic.Add("tr_sn", trSn);
                SearchRInventoryDetail sr = new SearchRInventoryDetail(dic);
                sr.ExecuteQuery();
                dt = sr.GetResult();
                if (dt == null || dt.Rows.Count == 0)
                {
                    ShowHint("在r_inventory_detail表中查询不到该trSn:" + trSn, Color.Red);
                    return(null);
                }

                if (string.IsNullOrEmpty(dt.Rows[0]["KP_NO"].ToString()))
                {
                    ShowHint("该TrSn" + trSn + "在r_inventory_detail表中的料号为空!", Color.Red);
                    return(null);
                }
            }
            catch (Exception ex)
            {
                ShowHint("GetDataInfoByTrSn: " + ex.Message, Color.Red);
                return(null);
            }

            try
            {
                dic.Clear();

                dic.Add("material_no", dt.Rows[0]["KP_NO"].ToString());
                SearchBMaterial sb = new SearchBMaterial(dic);
                sb.ExecuteQuery();
                DataTable dt2 = sb.GetResult();

                dt.Rows[0]["KP_DESC"] = dt2.Rows[0]["material_desc"];

                if (string.IsNullOrEmpty(dt.Rows[0]["KP_DESC"].ToString().Trim()))
                {
                    ShowHint("料号:" + dt.Rows[0]["KP_NO"].ToString() + "在b_material中的物料描述为空!", Color.Red);
                    return(null);
                }
            }
            catch (Exception ex)
            {
                ShowHint("SearchBMaterial: " + ex.Message, Color.Red);
                return(null);
            }

            return(dt);
        }
Ejemplo n.º 2
0
        private DataTable GetDataInfoByTrSn(string trsn)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();
            DataTable dt = new DataTable();

            try
            {
                dic.Add("tr_sn", trsn);
                SearchRInventoryDetail sr = new SearchRInventoryDetail(dic);
                sr.ExecuteQuery();
                dt = sr.GetResult();
                if (dt == null || dt.Rows.Count == 0)
                {
                    return(null);
                }

                if (string.IsNullOrEmpty(dt.Rows[0]["KP_NO"].ToString()))
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                ShowHint("SearchRInventoryDetail: " + trsn + ", " + ex.Message, Color.Red);
                return(null);
            }

            try
            {
                dic.Clear();

                dic.Add("material_no", dt.Rows[0]["KP_NO"].ToString());
                SearchBMaterial sb = new SearchBMaterial(dic);
                sb.ExecuteQuery();
                DataTable dt2 = sb.GetResult();

                dt.Rows[0]["KP_DESC"] = dt2.Rows[0]["material_desc"];

                return(dt);
            }
            catch (Exception ex)
            {
                ShowHint("SearchBMaterial: " + ex.Message, Color.Red);
                return(null);
            }
        }
Ejemplo n.º 3
0
        public static string SearchDescFromBMaterialByKpNo(string kpno)
        {
            try
            {
                Dictionary <string, object> dic = new Dictionary <string, object>();
                dic.Add("material_no", kpno);

                SearchBMaterial sb = new SearchBMaterial(dic);
                sb.ExecuteQuery();

                DataTable dt = sb.GetResult();
                if (dt != null && dt.Rows.Count > 0)
                {
                    return(dt.Rows[0]["material_desc"].ToString());
                }

                return(string.Empty);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 4
0
        static void Run()
        {
            try
            {
                Log.Debug(DateTime.Now.ToString() + " 启动运行物料过期扫描软件...");
                Trace.WriteLine(DateTime.Now.ToString() + " 启动运行物料过期扫描软件...");
                Console.WriteLine(DateTime.Now.ToString() + " 启动运行物料过期扫描软件...");

                //查询物料明细表
                Dictionary <string, object> dic = new Dictionary <string, object>();
                DataTable dt            = new DataTable();
                string    dateCode      = string.Empty;
                string    fifoDC        = string.Empty;
                string    message       = string.Empty;
                int       userdate      = 0;
                int       usedate_delay = 0;
                try
                {
                    dic.Add("status", "1"); //在库明细查询
                    SearchRInventoryDetail sr = new SearchRInventoryDetail(dic);
                    sr.ExecuteQuery();
                    dt = sr.GetResult();
                    if (dt == null || dt.Rows.Count == 0)
                    {
                        message = "异常:SearchRInventoryDetail结果集为空!";
                        Console.WriteLine(message);
                        Trace.WriteLine(message);
                        Log.Error(message);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    message = "异常:SearchRInventoryDetail: " + ex.Message;
                    Console.WriteLine(message);
                    Trace.WriteLine(message);
                    Log.Error(message);
                    return;
                }

                cntTotal = dt.Rows.Count;
                message  = "共查询到:" + cntTotal + " 条记录!";
                Console.WriteLine(message);
                Trace.WriteLine(message);
                Log.Error(message);

                int i = 0;
                foreach (DataRow dr in dt.Rows)
                {//根据物料明细,查询基础表,获取使用期限,物料等级等信息
                    i++;
                    //if (i == 100)
                    //{
                    //    break;
                    //}
                    //物料唯一条码,料号,周期非空判断
                    if (string.IsNullOrEmpty(dr["TR_SN"].ToString().Trim()) ||
                        string.IsNullOrEmpty(dr["KP_NO"].ToString().Trim()) ||
                        string.IsNullOrEmpty(dr["DATE_CODE"].ToString().Trim())
                        )
                    {
                        cntException++;
                        message = "异常:NO=" + i + ", 信息不全,TR_SN=" + dr["TR_SN"].ToString().Trim() +
                                  ", KP_NO=" + dr["KP_NO"].ToString().Trim() +
                                  ", DATE_CODE=" + dr["DATE_CODE"].ToString().Trim();
                        Console.WriteLine(message);
                        Trace.WriteLine(message);
                        Log.Error(message);
                        continue;
                    }
                    dateCode = dr["DATE_CODE"].ToString().Trim();
                    fifoDC   = DataCodeProcess.fifo_datecode(dateCode.ToUpper().Trim());

                    try
                    {
                        //查询使用期限,延长期限
                        dic.Clear();
                        dic.Add("material_no", dr["KP_NO"].ToString().Trim());
                        SearchBMaterial sb = new SearchBMaterial(dic);
                        sb.ExecuteQuery();
                        DataTable dt2 = sb.GetResult();
                        if (dt2 == null || dt.Rows.Count == 0)
                        {
                            cntException++;
                            message = "异常:NO=" + i + ", 查询使用期限失败, KP_NO=" + dr["KP_NO"].ToString().Trim();
                            Console.WriteLine(message);
                            Trace.WriteLine(message);
                            Log.Error(message);
                            continue;
                        }

                        if (string.IsNullOrEmpty(dt2.Rows[0]["material_level"].ToString().Trim()) ||
                            string.IsNullOrEmpty(dt2.Rows[0]["user_date"].ToString().Trim()))
                        {
                            cntException++;
                            message = "异常:NO=" + i + ", KP_NO=" + dr["KP_NO"].ToString().Trim() + "的物料等级或者使用期限为空, Level=" +
                                      dt2.Rows[0]["material_level"].ToString().Trim() + ", USER_DATE=" + dt2.Rows[0]["user_date"].ToString().Trim();
                            Console.WriteLine(message);
                            Trace.WriteLine(message);
                            Log.Error(message);
                            continue;
                        }

                        //如果物料等级为2,需要更新算法
                        if (dt2.Rows[0]["material_level"].ToString().Trim().Equals("2"))
                        {
                            fifoDC = DataCodeProcess.GetFirstDayOfMonth(fifoDC);
                        }

                        //使用期限从字符串转为int型
                        userdate = 0;
                        if (!Int32.TryParse(dt2.Rows[0]["user_date"].ToString().Trim(), out userdate))
                        {
                            cntException++;
                            message = "异常:NO=" + i + ", 使用期限转化为int失败, KP_NO=" + dr["KP_NO"].ToString().Trim() + ", USER_DATE=" + dt2.Rows[0]["user_date"].ToString().Trim();
                            Console.WriteLine(message);
                            Trace.WriteLine(message);
                            Log.Error(message);
                            continue;
                        }
                        if (!string.IsNullOrEmpty(dt2.Rows[0]["usedate_delay"].ToString().Trim()))
                        {
                            if (!Int32.TryParse(dt2.Rows[0]["usedate_delay"].ToString().Trim(), out usedate_delay))
                            {
                                cntException++;
                                message = "异常:NO=" + i + ", 延长期限转化为int失败, KP_NO=" + dr["KP_NO"].ToString().Trim() + ", USEDATE_DELAY=" + dt2.Rows[0]["usedate_delay"].ToString().Trim();
                                Console.WriteLine(message);
                                Trace.WriteLine(message);
                                Log.Error(message);
                                usedate_delay = 0; //continue;
                            }
                        }

                        //比较是否过期
                        int year       = (userdate + usedate_delay) / 360;
                        int month      = (userdate + usedate_delay) % 360 / 30;
                        int day        = (userdate + usedate_delay) % 30;
                        int fifoDay    = 0;
                        int CurrentDay = DateTime.Now.Year * 10000 + DateTime.Now.Month * 100 + DateTime.Now.Day;
                        if (!Int32.TryParse(fifoDC, out fifoDay))
                        {
                            cntException++;
                            message = "异常:NO=" + i + ", fifoDC转换成Int失败: fifoDC=" + fifoDC;
                            Console.WriteLine(message);
                            Trace.WriteLine(message);
                            Log.Error(message);
                            continue;
                        }

                        fifoDay = fifoDay + year * 10000 + month * 100 + day;
                        message = "NO=" + i + ", TR_SN=" + dr["TR_SN"].ToString().Trim() +
                                  ", KP_NO=" + dr["KP_NO"].ToString().Trim() +
                                  ", DateCode=" + dateCode +
                                  ", fifoDC=" + fifoDC +
                                  ", UserDate=" + userdate.ToString() +
                                  ", UseDate_Delay=" + usedate_delay.ToString() +
                                  ", 过期时间=" + fifoDay.ToString() +
                                  ", 当前时间=" + CurrentDay.ToString();
                        Trace.WriteLine(message);
                        if (fifoDay < CurrentDay)
                        {
                            cntGuoQi++;
                            Console.WriteLine(message);
                            Log.Error("物料过期:NO=" + i + ", " + message);

                            //将过期的物料状态从1更新为5
                            try
                            {
                                UpdateRInventoryDetailStatus ur = new UpdateRInventoryDetailStatus(dr["TR_SN"].ToString().Trim(), "1", "5");
                                ur.ExecuteUpdate();
                            }
                            catch (Exception ex)
                            {
                                cntException++;
                                message = "UpdateRInventoryDetailStatus: " + ex.Message;
                                Console.WriteLine("异常:" + ex.Message);
                                Trace.WriteLine("异常:" + ex.Message);
                                Log.Error("异常:" + ex.Message);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("异常:" + ex.Message);
                        Trace.WriteLine("异常:" + ex.Message);
                        Log.Error("异常:" + ex.Message);
                        continue;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("异常:" + ex.Message);
                Trace.WriteLine("异常:" + ex.Message);
                Log.Error("异常:" + ex.Message);
            }
            finally
            {
                Console.WriteLine(DateTime.Now.ToString() + " 结束运行物料过期扫描软件!");
                Trace.WriteLine(DateTime.Now.ToString() + " 结束运行物料过期扫描软件!");
                Log.Debug(DateTime.Now.ToString() + " 结束运行物料过期扫描软件!");
            }
        }