コード例 #1
0
ファイル: AsnExcelIn.cs プロジェクト: wukenny/Aec
 void AddAsnToAsnList(int _Row, ASN asn)
 {
     string errorMsg = "";
     List<string> errorPropNames;
     if (!ASN.Validation(asn, out errorPropNames)) {
         List<int> _ColNoList = new List<int>();
         foreach (string errorPropName in errorPropNames) {
             errorMsg += (errorPropName + ", ");
             _ColNoList.Add(AsnTitleDict[errorPropName]);
         }
         errorMsg = errorMsg.Remove(errorMsg.Length - 2); // -2 to remove " & "
         AddAsnError(_Row, _ColNoList, errorMsg + " data error");
         return;
     }
     if (!ASN.WithinFilter(asn)) {
         return;
     }
     AsnList.Add(asn); // if it reaches this far, everything is ok.
 }
コード例 #2
0
ファイル: ASN.cs プロジェクト: wukenny/Aec
 /// <summary>
 /// check if all properties of the input asn within spec.
 /// </summary>
 /// <param name="asn">asn to be checked</param>
 /// <param name="errorPropNames">out: list of the error properties</param>
 /// <returns>true: PASS, error list is empty; false: FAILED, there are records at the error list</returns>
 public static bool Validation(ASN asn, out List<string> errorPropNames)
 {
     errorPropNames = new List<string>();
     if (asn.VendorCode.Length != AsnSpec.VendorCode_Length) {
         errorPropNames.Add("VendorCode");
     }
     if (asn.Po.Length > AsnSpec.Po_MaxLength || asn.Po.Length < AsnSpec.Po_MinLength) {
         errorPropNames.Add("Po");
     }
     if (asn.Pn.Length > AsnSpec.Pn_MaxLength || asn.Pn.Length < AsnSpec.Pn_MinLength) {
         errorPropNames.Add("Pn");
     }
     if (asn.Eta > AsnSpec.Eta_Max || asn.Eta < AsnSpec.Eta_Min) {
         errorPropNames.Add("Eta");
     }
     if (asn.Qty > AsnSpec.Qty_Max || asn.Qty < AsnSpec.Qty_Min) {
         errorPropNames.Add("Qty");
     }
     return (errorPropNames.Count == 0 ? true : false);
 }
コード例 #3
0
ファイル: ASN.cs プロジェクト: wukenny/Aec
        /// <summary>
        /// check if all properties of the input asn within filter.
        /// </summary>
        /// <param name="asn">asn to be checked</param>        
        /// <returns>true: within filter; false: out of filter</returns>
        public static bool WithinFilter(ASN asn)
        {
            DateTime Eta_Max_Date = DateTime.Now.AddDays(AsnFilter.Filter_Eta_Max_Day);
            DateTime Eta_Min_Date = DateTime.Now.AddDays(AsnFilter.Filter_Eta_Min_Day);

            if (asn.Eta < Eta_Min_Date || asn.Eta > Eta_Max_Date) {
                return false;
            }
            return true;
        }
コード例 #4
0
ファイル: AsnExcelIn.cs プロジェクト: wukenny/Aec
        /// <summary>        
        /// Fill AsnList for outside caller; AsnList will be ready.
        /// All errors will be displayed in Excel.
        /// </summary>        
        void FillAsnList()
        {
            string _VendorCode = "";
            string _Po = "";
            string _Pn = "";
            DateTime _Eta;
            int _Qty = 0;

            for (int _Row = TitleRow + 1; _Row <= ObjArray.GetLength(0); _Row++) {
                bool emptyRow = true;
                foreach (AsnTitle asnTitle in AsnTitleArray) { // to check if there is any empty row.
                    object obj = ObjArray[_Row, asnTitle.TitleCol];
                    if (obj != null) {
                        emptyRow = false;
                        break;
                    }
                }
                if (emptyRow == true) {  //ignore empty rows, do not report error.
                    continue;
                }
                // get object value from objArray then parse, null=>"", otherwise ToString()
                Func<string, string> GetValue = c => (ObjArray[_Row, AsnTitleDict[c]] ?? string.Empty).ToString();

                // leave valiations to the ASN class.
                _VendorCode = GetValue("VendorCode");
                _Po = GetValue("Po");  // set to 0 if failed.
                _Pn = GetValue("Pn");

                // DataTime returns from Excel is in type Double!
                double d;
                double.TryParse(GetValue("Eta"), out d);
                if (d < MinExcelDateTime || d > MaxExcelDateTime) {  // too small or too big for a DateTime.
                    d = MinExcelDateTime;
                }
                _Eta = DateTime.FromOADate(d); // must use FromOADate! OA=OLE Automation

                int.TryParse(GetValue("Qty"), out _Qty);

                ASN asn = new ASN(_VendorCode, _Po, _Pn, _Eta, _Qty);
                AddAsnToAsnList(_Row, asn);
            }
            if (this.AsnList.Count < 1) { // there are NO asn in the list
                AddAsnError(0, 0, "ther is NO data in the file!");
            }
        }