Exemple #1
0
        /// <summary>
        /// Test whether the constraint is satisfied by a given value
        /// </summary>
        /// <param name="actual">The value to be tested</param>
        /// <returns>True for success, false for failure</returns>
        public override ConstraintResult ApplyTo <TActual>(TActual actual)
        {
            System.Reflection.PropertyInfo countProperty = actual?.GetType().GetProperty(CountPropertyName);
            int?countValue = (int?)countProperty?.GetValue(actual, null);

            return(new ConstraintResult(this, actual, countValue == 0));
        }
Exemple #2
0
        public virtual void ToIntermapperInfo(StringBuilder sb)
        {
            System.Reflection.PropertyInfo[] allProps = GetType().GetProperties();

            System.Reflection.PropertyInfo id = GetType().GetProperty("LineName");
            string idVal = (string)id.GetValue(this, null);

            System.Reflection.PropertyInfo time = GetType().GetProperty("TimeStamp");
            DateTime timeVal = (DateTime)time.GetValue(this, null);

            System.Reflection.PropertyInfo notSet = GetType().GetProperty("NotSetYet");
            bool notSetVal = (bool)notSet?.GetValue(this, null);


            if (NotSetYet)
            {
                sb.AppendLine($"{idVal} NotSetYet");
            }
            else
            {
                ToIntermapperInfo_FilterOrAdd(sb, $"{idVal}.UpdateTime", $"{timeVal}");
                TimeSpan age = DateTime.Now - timeVal;
                ToIntermapperInfo_FilterOrAdd(sb, $"{idVal}.UpdateAgeSec", $"{(int)age.TotalSeconds}");

                foreach (var p in allProps)
                {
                    if ((p.Name != "DisplayItem") && (p.Name != "TimeStamp") && (p.Name != "LineName") && (p.Name != "NotSetYet") && (p.Name != "MergeSupported") && (p.Name != "ReportTo"))
                    {
                        string _key = "";
                        string _val = "";
                        object val  = null;

                        switch (p.PropertyType.ToString())
                        {
                        case "System.String":
                        case "System.Int32":
                        case "System.Int64":
                        case "System.Boolean":
                            val  = p.GetValue(this, null);
                            _key = $"{idVal}.{p.Name}";
                            _val = $"{val}";
                            break;

                        case "System.TimeSpan":
                            val  = p.GetValue(this, null);
                            _key = $"{idVal}.{p.Name}";
                            _val = $"{(int)(((System.TimeSpan)val).TotalSeconds)}";
                            break;

                        default:
                            System.Diagnostics.Debug.WriteLine($"{p.Name} {p.PropertyType} not supported");
                            _val = $"{p.Name} {p.PropertyType} not supported";
                            break;
                        }

                        ToIntermapperInfo_FilterOrAdd(sb, _key, _val);
                    }
                }
            }
        }
Exemple #3
0
        public static string GetLogDisplayName(this EventLogSession session, string logPath)
        {
            int           capacity = 0x200, bufferUsed = 0, error = 0;
            string        str         = logPath;
            StringBuilder displayName = new StringBuilder(capacity);

            // Get handle
            IntPtr hEvt = IntPtr.Zero;

            if (SessionHandlePI == null)
            {
                Type elhType = session?.GetType().Assembly.GetType("System.Diagnostics.Eventing.Reader.EventLogHandle");
                SessionHandlePI = session?.GetType().GetProperty("Handle", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic, null, elhType, Type.EmptyTypes, null);
            }
            object o = SessionHandlePI?.GetValue(session, null);

            if (o != null)
            {
                hEvt = ((SafeHandle)o).DangerousGetHandle();
            }

            if (!EvtIntGetClassicLogDisplayName(hEvt, logPath, 0, 0, capacity, displayName, ref bufferUsed))
            {
                error = Marshal.GetLastWin32Error();
                if (error == 0x7a)
                {
                    displayName = new StringBuilder(bufferUsed);
                    capacity    = bufferUsed;
                    error       = 0;
                    if (!EvtIntGetClassicLogDisplayName(hEvt, logPath, 0, 0, capacity, displayName, ref bufferUsed))
                    {
                        throw new System.ComponentModel.Win32Exception();
                    }
                }
            }

            if ((error == 0) && !string.IsNullOrEmpty(displayName.ToString()))
            {
                str = displayName.ToString();
            }
            return(str);
        }
Exemple #4
0
        /// <summary>
        /// Gets the named property from the given object. Attempts to recurse through
        /// an object if it is a complex type.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj">The object to get the property value of.</param>
        /// <param name="propertyName">The name of the property.</param>
        /// <returns>The property value, if found. Otherwise, default.</returns>
        public static T GetPropertyValue <T>(object obj, string propertyName)
        {
            if (obj == null)
            {
                throw new ArgumentException("Value cannot be null.", nameof(obj));
            }

            if (propertyName == null)
            {
                throw new ArgumentException("Value cannot be null.", nameof(propertyName));
            }

            // check for complex/nested type
            if (propertyName.Contains('.'))
            {
                string[] temp = propertyName.Split(new char[] { '.' }, 2);
                return((T)GetPropertyValue(GetPropertyValue(obj, temp[0]), temp[1]));
            }
            else
            {
                System.Reflection.PropertyInfo prop = obj.GetType().GetProperty(propertyName);
                return((T)prop?.GetValue(obj, null) ?? default);
            }
        }
Exemple #5
0
        private void GetBetAmount(ModelBetState modelBetState)
        {
            List <ModelBet> lsttempModelBet;

            Type t = modelBetState.GetType();

            for (int i = 0; i < 10; i++)
            {
                System.Reflection.PropertyInfo propertyInfoPlan   = t.GetProperty("Bet" + i + "PlanID");
                System.Reflection.PropertyInfo propertyInfoPeriod = t.GetProperty("Bet" + i + "PeriodID");
                System.Reflection.PropertyInfo propertyInfoAmount = t.GetProperty("Bet" + i + "Amount");


                if ((int)propertyInfoPlan.GetValue(modelBetState) == 1)
                {
                    lsttempModelBet = lstBet1;
                }
                else if ((int)propertyInfoPlan.GetValue(modelBetState) == 2)
                {
                    lsttempModelBet = lstBet2;
                }
                else if ((int)propertyInfoPlan.GetValue(modelBetState) == 3)
                {
                    lsttempModelBet = lstBet3;
                }
                else if ((int)propertyInfoPlan.GetValue(modelBetState) == 4)
                {
                    lsttempModelBet = lstBet4;
                }
                else if ((int)propertyInfoPlan.GetValue(modelBetState) == 5)
                {
                    lsttempModelBet = lstBet5;
                }
                else if ((int)propertyInfoPlan.GetValue(modelBetState) == 6)
                {
                    lsttempModelBet = lstBet6;
                }
                else
                {
                    lsttempModelBet = new List <ModelBet>();
                }

                ModelBet modetempbet = lsttempModelBet.Find(p => p.MyPeriodId == (int)propertyInfoPeriod.GetValue(modelBetState));

                if (modetempbet != null)
                {
                    //modelCurrentBetState.Bet0Amount = modetempbet.MyBetAmountPerBet;
                    propertyInfoAmount.SetValue(modelBetState, modetempbet.MyBetAmountPerBet.ToString());
                }
            }
        }
Exemple #6
0
        private void AddPeriod(ModelCurrentBetState modelCurrentBetState, ModelCurrentBetState modelNextBetState,
                               ModelSSCPeriods modelSSCPeriods, List <ModelSSCPeriods> lstTempmodelSSCPeriods, int iPeriodIndex)
        {
            //+1
            //Bet0PlanID
            //Bet0PeriodID
            //modelCurrentBetState.Bet0PeriodID += 1;
            //modelCurrentBetState.Bet1PeriodID += 1;
            //modelCurrentBetState.Bet2PeriodID += 1;
            //modelCurrentBetState.Bet3PeriodID += 1;
            //modelCurrentBetState.Bet4PeriodID += 1;
            //modelCurrentBetState.Bet5PeriodID += 1;
            //modelCurrentBetState.Bet6PeriodID += 1;
            //modelCurrentBetState.Bet7PeriodID += 1;
            //modelCurrentBetState.Bet8PeriodID += 1;
            //modelCurrentBetState.Bet9PeriodID += 1;
            bool bReset = false;

            if (iPeriodIndex == lstTempmodelSSCPeriods.Count - 1)
            {
                bReset = false;
            }
            else
            {
                if (RdbNoReset.Checked == true)
                {
                    bReset = false;
                }
                else if (RdbResetByDay.Checked == true)
                {
                    //20170101
                    if (lstTempmodelSSCPeriods[iPeriodIndex].PeriodDate.Substring(6, 2) != lstTempmodelSSCPeriods[iPeriodIndex + 1].PeriodDate.Substring(6, 2))
                    {
                        bReset = true;
                    }
                }
                else if (RdbResetByMonth.Checked == true)
                {
                    if (lstTempmodelSSCPeriods[iPeriodIndex].PeriodDate.Substring(4, 2) != lstTempmodelSSCPeriods[iPeriodIndex + 1].PeriodDate.Substring(4, 2))
                    {
                        bReset = true;
                    }
                }
                else if (RdbResetByYear.Checked == true)
                {
                    if (lstTempmodelSSCPeriods[iPeriodIndex].PeriodDate.Substring(0, 4) != lstTempmodelSSCPeriods[iPeriodIndex + 1].PeriodDate.Substring(0, 4))
                    {
                        bReset = true;
                    }
                }
            }

            List <ModelBet> lsttempCurrentModelBet;
            List <ModelBet> lsttempNextModelBet;

            Type tcurrent = modelCurrentBetState.GetType();
            Type tnext    = modelNextBetState.GetType();

            //0  -- 9
            for (int i = 0; i < 10; i++)
            {
                System.Reflection.PropertyInfo propertyInfoPlan   = tcurrent.GetProperty("Bet" + i + "PlanID");
                System.Reflection.PropertyInfo propertyInfoPeriod = tcurrent.GetProperty("Bet" + i + "PeriodID");
                System.Reflection.PropertyInfo propertyInfoAmount = tcurrent.GetProperty("Bet" + i + "Amount");

                System.Reflection.PropertyInfo propertyInfoNextPlan   = tnext.GetProperty("Bet" + i + "PlanID");
                System.Reflection.PropertyInfo propertyInfoNextPeriod = tnext.GetProperty("Bet" + i + "PeriodID");
                System.Reflection.PropertyInfo propertyInfoNextAmount = tnext.GetProperty("Bet" + i + "Amount");

                int icurrentplan   = (int)propertyInfoPlan.GetValue(modelCurrentBetState);
                int icurrentperiod = (int)propertyInfoPeriod.GetValue(modelCurrentBetState);
                //plan
                if (icurrentplan == 1)
                {
                    lsttempCurrentModelBet = lstBet1;
                    lsttempNextModelBet    = lstBet2;
                }
                else if (icurrentplan == 2)
                {
                    lsttempCurrentModelBet = lstBet2;
                    lsttempNextModelBet    = lstBet3;
                }
                else if (icurrentplan == 3)
                {
                    lsttempCurrentModelBet = lstBet3;
                    lsttempNextModelBet    = lstBet4;
                }
                else if (icurrentplan == 4)
                {
                    lsttempCurrentModelBet = lstBet4;
                    lsttempNextModelBet    = lstBet5;
                }
                else if (icurrentplan == 5)
                {
                    lsttempCurrentModelBet = lstBet5;
                    lsttempNextModelBet    = lstBet6;
                }
                else if (icurrentplan == 6)
                {
                    lsttempCurrentModelBet = lstBet6;
                    lsttempNextModelBet    = lstBet1;
                }
                else
                {
                    lsttempCurrentModelBet = new List <ModelBet>();
                    lsttempNextModelBet    = new List <ModelBet>();
                }

                if (modelSSCPeriods.No5 == i)//中
                {
                    if ((int)propertyInfoPeriod.GetValue(modelCurrentBetState) == 0)
                    {                                            //
                        if (icurrentplan == iMaxSetupPlanNo + 1) //最后一个,重来
                        {
                            propertyInfoNextPlan.SetValue(modelNextBetState, 1);
                            propertyInfoNextPeriod.SetValue(modelNextBetState, 1);

                            LblMaxReset.Text = LblMaxReset.Text + modelSSCPeriods.Period + ",";
                        }
                        else
                        {
                            propertyInfoNextPlan.SetValue(modelNextBetState, icurrentplan + 1); //+1
                            propertyInfoNextPeriod.SetValue(modelNextBetState, 1);
                        }
                    }
                    else
                    {
                        propertyInfoNextPlan.SetValue(modelNextBetState, 1);
                        propertyInfoNextPeriod.SetValue(modelNextBetState, 1);
                    }
                }
                else
                {
                    if (icurrentperiod == 0)
                    {
                        propertyInfoNextPlan.SetValue(modelNextBetState, icurrentplan);
                        propertyInfoNextPeriod.SetValue(modelNextBetState, 0);
                    }
                    else if (icurrentperiod == lsttempCurrentModelBet.Count)
                    {
                        propertyInfoNextPlan.SetValue(modelNextBetState, icurrentplan);
                        propertyInfoNextPeriod.SetValue(modelNextBetState, 0);
                    }
                    else
                    {
                        propertyInfoNextPlan.SetValue(modelNextBetState, icurrentplan);
                        propertyInfoNextPeriod.SetValue(modelNextBetState, icurrentperiod + 1);
                    }
                }

                if (bReset)
                {
                    propertyInfoNextPlan.SetValue(modelNextBetState, 1);
                    propertyInfoNextPeriod.SetValue(modelNextBetState, 1);
                }

                //if (cbbPlan.Items.Count == 0 && cbbPeriod.Items.Count == 0)
                //{
                //    return;
                //}

                ////没有bContinue正常增加
                ////bContinue    cbbPeriod.Parent.ForeColor == System.Drawing.Color.Red  暂停投注 --》 plan ++
                ////            cbbPeriod.Parent.ForeColor == System.Drawing.Color.Red  不是暂停投注  --》 reset
                //if (!bContinue)
                //{
                //    if (cbbPeriod.Items.Count == cbbPeriod.SelectedIndex + 1)
                //    {
                //        if (cbbPlan.Items.Count == cbbPlan.SelectedIndex + 1)//最大方案
                //        {
                //            return;
                //        }
                //        else if (cbbPlan.Items.Count > cbbPlan.SelectedIndex + 1)//
                //        {
                //            cbbPlan.SelectedIndex++;
                //        }
                //    }
                //    else
                //    {
                //        cbbPeriod.SelectedIndex++;
                //    }
                //    return;
                //}


                //if (cbbPeriod.Items.Count == cbbPeriod.SelectedIndex + 1)//最大期数
                //{
                //    //不中 ,
                //    if (cbbPeriod.Parent.ForeColor != System.Drawing.Color.Red)
                //    {
                //        return;
                //    }

                //    //中
                //    if (cbbPlan.Items.Count == cbbPlan.SelectedIndex + 1)//最大方案
                //    {

                //        BtnResetClick(cbbPlan, cbbPeriod);
                //        return;
                //    }
                //    else if (cbbPlan.Items.Count > cbbPlan.SelectedIndex + 1)//
                //    {
                //        cbbPlan.SelectedIndex++;
                //    }
                //    else
                //    {
                //        throw new Exception("出错 Plan");
                //    }
                //}
                //else if (cbbPeriod.Items.Count > cbbPeriod.SelectedIndex + 1)
                //{
                //    //不中 ,
                //    if (cbbPeriod.Parent.ForeColor != System.Drawing.Color.Red)
                //    {
                //        cbbPeriod.SelectedIndex++;
                //        return;
                //    }
                //    //中
                //    BtnResetClick(cbbPlan, cbbPeriod);
                //    return;
                //}
                //else
                //{
                //    throw new Exception("出错 Period");
                //}
            }
        }
 private bool GetPropertyValue(PropertyInfo pi, PropertyLookupParams paramBag, ref object @value)
 {
     try
     {
         @value = pi.GetValue(paramBag.instance, (object[]) null);
         return true;
     }
     catch(Exception ex)
     {
         paramBag.self.Error("Can't get property " + paramBag.propertyName
             + " as CLR property " + pi.Name + " from "
             + paramBag.prototype.FullName + " instance", ex);
     }
     return false;
 }
Exemple #8
0
        public static object GetPropertiesAndDoAction(string pluginFileName, out string name, out string text, out decimal version, out string description, out string actionType, out string shortcut, out System.Reflection.MethodInfo mi)
        {
            name        = null;
            text        = null;
            version     = 0;
            description = null;
            actionType  = null;
            shortcut    = null;
            mi          = null;
            System.Reflection.Assembly assembly;
            try
            {
                assembly = System.Reflection.Assembly.Load(File.ReadAllBytes(pluginFileName));
            }
            catch
            {
                return(null);
            }
            string objectName = Path.GetFileNameWithoutExtension(pluginFileName);

            if (assembly != null)
            {
                Type pluginType = assembly.GetType("Nikse.SubtitleEdit.PluginLogic." + objectName);
                if (pluginType == null)
                {
                    return(null);
                }
                object pluginObject = null;
                try
                {
                    pluginObject = Activator.CreateInstance(pluginType);
                }
                catch
                {
                    // ignore plugin that failed to load
                    return(pluginObject);
                }

                // IPlugin
                var t = pluginType.GetInterface("IPlugin");
                if (t == null)
                {
                    return(null);
                }

                System.Reflection.PropertyInfo pi = t.GetProperty("Name");
                if (pi != null)
                {
                    name = (string)pi.GetValue(pluginObject, null);
                }

                pi = t.GetProperty("Text");
                if (pi != null)
                {
                    text = (string)pi.GetValue(pluginObject, null);
                }

                pi = t.GetProperty("Description");
                if (pi != null)
                {
                    description = (string)pi.GetValue(pluginObject, null);
                }

                pi = t.GetProperty("Version");
                if (pi != null)
                {
                    version = Convert.ToDecimal(pi.GetValue(pluginObject, null));
                }

                pi = t.GetProperty("ActionType");
                if (pi != null)
                {
                    actionType = (string)pi.GetValue(pluginObject, null);
                }

                mi = t.GetMethod("DoAction");

                pi = t.GetProperty("Shortcut");
                if (pi != null)
                {
                    shortcut = (string)pi.GetValue(pluginObject, null);
                }

                return(pluginObject);
            }
            return(null);
        }
Exemple #9
0
        private static IEnumerable <Tag> ExtractTagsFromPropertyWithSpecificAttribute(object objValue, PropertyInfo objProperty, HubTagAttribute attribute)
        {
            if (objProperty != null)
            {
                objValue = objProperty.GetValue(objValue);
                if (objValue == null)
                {
                    //don't save "null" values
                    yield break;
                }
                if (objValue.GetType().IsAssignableFrom(typeof(bool)))
                {
                    if (objValue as bool? == false)
                    { //don't save "false" values
                        yield break;
                    }
                }
                if (objValue.GetType().IsAssignableFrom(typeof(int)))
                {
                    if (objValue as int? == 0)
                    {   //don't save "0" values
                        yield break;
                    }
                }
            }
            else if (objValue == null)
            {
                yield break;
            }
            Type objValueType = objValue.GetType();

            Tag tag = new Tag(objValue, attribute)
            {
                TagValue = !string.IsNullOrEmpty(attribute.TagValueFromProperty)
                    ? objValueType.GetProperty(attribute.TagValueFromProperty)?.GetValue(objValue, null)?.ToString() ?? string.Empty
                    : objValue.ToString(),
                TagName = !string.IsNullOrEmpty(attribute.TagName)
                    ? attribute.TagName
                    : !string.IsNullOrEmpty(objProperty?.Name)
                        ? objProperty.Name
                        : objValue.ToString()
            };

            tag.SetTagTypeEnumFromCLRType(objValueType);
            if (!string.IsNullOrEmpty(attribute.TagNameFromProperty))
            {
                try
                {
                    tag.TagName += objValueType.GetProperty(attribute.TagNameFromProperty)?.GetValue(objValue, null)?.ToString() ?? string.Empty;
                }
                catch (Exception)
                {
#if DEBUG
                    Debugger.Break();
#else
                    throw;
#endif
                }
            }

            if (objProperty != null)
            {
                tag.Tags = new List <Tag>(ExtractTagsFromAttributes(objValue));
            }
            yield return(tag);
        }
Exemple #10
0
        /// <summary>
        /// 导出Excel格式的学习卡信息
        /// </summary>
        /// <param name="path">导出文件的路径(服务器端)</param>
        /// <param name="orgid">机构id</param>
        /// <param name="lcsid">学习卡设置项的id</param>
        /// <returns></returns>
        public string Card4Excel(string path, int orgid, int lcsid)
        {
            HSSFWorkbook hssfworkbook = new HSSFWorkbook();
            //xml配置文件
            XmlDocument xmldoc  = new XmlDocument();
            string      confing = WeiSha.Common.App.Get["ExcelInputConfig"].VirtualPath + "学习卡.xml";

            xmldoc.Load(WeiSha.Common.Server.MapPath(confing));
            XmlNodeList nodes = xmldoc.GetElementsByTagName("item");
            //创建工作簿对象
            LearningCardSet rs    = Gateway.Default.From <LearningCardSet>().Where(LearningCardSet._.Lcs_ID == lcsid).ToFirst <LearningCardSet>();
            ISheet          sheet = hssfworkbook.CreateSheet(rs.Lcs_Theme);
            //sheet.DefaultColumnWidth = 30;
            //创建数据行对象
            IRow rowHead = sheet.CreateRow(0);

            for (int i = 0; i < nodes.Count; i++)
            {
                rowHead.CreateCell(i).SetCellValue(nodes[i].Attributes["Column"].Value);
            }
            //生成数据行
            ICellStyle style_size = hssfworkbook.CreateCellStyle();

            style_size.WrapText = true;
            WhereClip wc = LearningCard._.Org_ID == orgid;

            if (lcsid >= 0)
            {
                wc.And(LearningCard._.Lcs_ID == lcsid);
            }
            LearningCard[] rcodes = Gateway.Default.From <LearningCard>().Where(wc).OrderBy(LearningCard._.Lc_CrtTime.Desc).ToArray <LearningCard>();
            for (int i = 0; i < rcodes.Length; i++)
            {
                IRow row = sheet.CreateRow(i + 1);
                for (int j = 0; j < nodes.Count; j++)
                {
                    Type type = rcodes[i].GetType();
                    System.Reflection.PropertyInfo propertyInfo = type.GetProperty(nodes[j].Attributes["Field"].Value); //获取指定名称的属性
                    object obj = propertyInfo.GetValue(rcodes[i], null);
                    if (obj != null)
                    {
                        string format   = nodes[j].Attributes["Format"] != null ? nodes[j].Attributes["Format"].Value : "";
                        string datatype = nodes[j].Attributes["DataType"] != null ? nodes[j].Attributes["DataType"].Value : "";
                        string defvalue = nodes[j].Attributes["DefautValue"] != null ? nodes[j].Attributes["DefautValue"].Value : "";
                        string value    = "";
                        switch (datatype)
                        {
                        case "date":
                            DateTime tm = Convert.ToDateTime(obj);
                            value = tm > DateTime.Now.AddYears(-100) ? tm.ToString(format) : "";
                            break;

                        default:
                            value = obj.ToString();
                            break;
                        }
                        if (defvalue.Trim() != "")
                        {
                            foreach (string s in defvalue.Split('|'))
                            {
                                string h = s.Substring(0, s.IndexOf("="));
                                string f = s.Substring(s.LastIndexOf("=") + 1);
                                if (value.ToLower() == h.ToLower())
                                {
                                    value = f;
                                }
                            }
                        }
                        row.CreateCell(j).SetCellValue(value);
                    }
                }
            }
            FileStream file = new FileStream(path, FileMode.Create);

            hssfworkbook.Write(file);
            file.Close();
            return(path);
        }
Exemple #11
0
    {//慎用,这个速度快不了
        public virtual void CopyFrom(ICopyable src)
        {
            Type type = GetType();

            if (src.GetType() != type)
            {
                return;
            }

            System.Reflection.PropertyInfo[] props = type.GetProperties();
            foreach (System.Reflection.PropertyInfo i in props)
            {
                var attrs = i.GetCustomAttributes(typeof(DoNotCopyAttribute), true);
                if (attrs != null && attrs.Length > 0)
                {
                    continue;
                }

                attrs = i.GetCustomAttributes(typeof(System.ComponentModel.ReadOnlyAttribute), true);
                if (attrs == null || attrs.Length != 0)
                {
                    continue;
                }

                if (!i.CanWrite)
                {
                    continue;
                }

                if (i.PropertyType.IsSubclassOf(typeof(ICopyable)))
                {
                    ICopyable value     = System.Activator.CreateInstance(i.PropertyType) as ICopyable;
                    ICopyable subObject = i.GetValue(src, null) as ICopyable;
                    value.CopyFrom(subObject);
                    i.SetValue(this, value, null);
                }
                else if (i.PropertyType.IsGenericType)
                {
                    var lst    = System.Activator.CreateInstance(i.PropertyType);
                    var srclst = i.GetValue(src, null);
                    System.Reflection.MethodInfo mi = i.PropertyType.GetMethod("Add");
                    if (mi == null)
                    {
                        continue;
                    }
                    System.Reflection.PropertyInfo pi = i.PropertyType.GetProperty("Count");
                    if (pi == null)
                    {
                        continue;
                    }
                    System.Reflection.PropertyInfo tisPI2 = i.PropertyType.GetProperty("Item");
                    if (tisPI2 == null)
                    {
                        continue;
                    }

                    Type     gnType = i.PropertyType.GetGenericArguments()[0];
                    object[] args   = new object[1];
                    int      Count  = (int)pi.GetValue(srclst, null);
                    for (int j = 0; j < Count; j++)
                    {
                        if (gnType.IsValueType || gnType.IsEnum)
                        {
                            object elem    = System.Activator.CreateInstance(gnType);
                            object elemSrc = tisPI2.GetValue(srclst, new object[] { j });
                            elem    = elemSrc;
                            args[0] = elem;
                            mi.Invoke(lst, args);
                        }
                        else if (gnType.IsSubclassOf(typeof(ICopyable)))
                        {
                            ICopyable elem    = System.Activator.CreateInstance(gnType) as ICopyable;
                            ICopyable elemSrc = tisPI2.GetValue(srclst, new object[] { j }) as ICopyable;
                            elem.CopyFrom(elemSrc);
                            args[0] = elem;
                            mi.Invoke(lst, args);
                        }
                    }
                    i.SetValue(this, lst, null);
                }
                else
                {
                    i.SetValue(this, i.GetValue(src, null), null);
                }
            }
        }
Exemple #12
0
        public virtual void Modify(ref ValidationErrors errors, Apps.Models.SCV.AR.AR_RECEIPT_HEADER_MODEL model, params string[] updateProperties)
        {
            Apps.Models.AR_RECEIPT_HEADER entity = m_Rep.GetById(model.INTERNAL_RECEIPT_NUM);
            if (entity == null)
            {
                errors.Add(Resource.Disable);
                return;
            }
            if (updateProperties.Count() <= 0)
            {
                entity.INTERNAL_RECEIPT_NUM = model.INTERNAL_RECEIPT_NUM;
                entity.WAREHOUSE            = model.WAREHOUSE;
                entity.COMPANY                 = model.COMPANY;
                entity.RECEIPT_ID              = model.RECEIPT_ID;
                entity.RECEIPT_TYPE            = model.RECEIPT_TYPE;
                entity.PRIORITY                = model.PRIORITY;
                entity.LEADING_STS             = model.LEADING_STS;
                entity.TRAILING_STS            = model.TRAILING_STS;
                entity.ERP_ORDER_ID            = model.ERP_ORDER_ID;
                entity.SHIP_FROM               = model.SHIP_FROM;
                entity.SHIP_FROM_ADDRESS1      = model.SHIP_FROM_ADDRESS1;
                entity.SHIP_FROM_ADDRESS2      = model.SHIP_FROM_ADDRESS2;
                entity.SHIP_FROM_CITY          = model.SHIP_FROM_CITY;
                entity.SHIP_FROM_STATE         = model.SHIP_FROM_STATE;
                entity.SHIP_FROM_COUNTRY       = model.SHIP_FROM_COUNTRY;
                entity.SHIP_FROM_POSTAL_CODE   = model.SHIP_FROM_POSTAL_CODE;
                entity.SHIP_FROM_NAME          = model.SHIP_FROM_NAME;
                entity.SHIP_FROM_ATTENTION_TO  = model.SHIP_FROM_ATTENTION_TO;
                entity.SHIP_FROM_EMAIL_ADDRESS = model.SHIP_FROM_EMAIL_ADDRESS;
                entity.SHIP_FROM_PHONE_NUM     = model.SHIP_FROM_PHONE_NUM;
                entity.SHIP_FROM_FAX_NUM       = model.SHIP_FROM_FAX_NUM;
                entity.SCHEDULED_ARRIVE_DATE   = model.SCHEDULED_ARRIVE_DATE;
                entity.ACTUAL_ARRIVE_DATE      = model.ACTUAL_ARRIVE_DATE;
                entity.USER_STAMP              = model.USER_STAMP;
                entity.DATE_TIME_STAMP         = model.DATE_TIME_STAMP;
                entity.RECV_DOCK               = model.RECV_DOCK;
                entity.CLOSE_DATE              = model.CLOSE_DATE;
                entity.CREATE_DATE             = model.CREATE_DATE;
                entity.START_CHECKIN_DATE      = model.START_CHECKIN_DATE;
                entity.END_CHECKIN_DATE        = model.END_CHECKIN_DATE;
                entity.USER_DEF1               = model.USER_DEF1;
                entity.USER_DEF2               = model.USER_DEF2;
                entity.USER_DEF3               = model.USER_DEF3;
                entity.USER_DEF4               = model.USER_DEF4;
                entity.USER_DEF5               = model.USER_DEF5;
                entity.USER_DEF6               = model.USER_DEF6;
                entity.USER_DEF7               = model.USER_DEF7;
                entity.USER_DEF8               = model.USER_DEF8;
                entity.TOTAL_QTY               = model.TOTAL_QTY;
                entity.TOTAL_LINES             = model.TOTAL_LINES;
                entity.UPLOAD_INTERFACE_FLAG   = model.UPLOAD_INTERFACE_FLAG;
            }
            else
            {
                Type type  = typeof(Apps.Models.SCV.AR.AR_RECEIPT_HEADER_MODEL);
                Type typeE = typeof(Apps.Models.AR_RECEIPT_HEADER);
                foreach (var item in updateProperties)
                {
                    System.Reflection.PropertyInfo pi  = type.GetProperty(item);
                    System.Reflection.PropertyInfo piE = typeE.GetProperty(item);
                    piE.SetValue(entity, pi.GetValue(model), null);
                }
            }


            m_Rep.Modify(entity, updateProperties);
        }
        public virtual void Modify(ref ValidationErrors errors, Apps.Models.SCV.AR.AR_UPLOAD_INVENTORY_TRANS_MODEL model, params string[] updateProperties)
        {
            Apps.Models.AR_UPLOAD_INVENTORY_TRANS entity = m_Rep.GetById(model.INTERFACE_RECORD_ID);
            if (entity == null)
            {
                errors.Add(Resource.Disable);
                return;
            }
            if (updateProperties.Count() <= 0)
            {
                entity.INTERFACE_RECORD_ID   = model.INTERFACE_RECORD_ID;
                entity.INTERFACE_ACTION_CODE = model.INTERFACE_ACTION_CODE;
                entity.INTERFACE_CONDITION   = model.INTERFACE_CONDITION;
                entity.PROCESS_STAMP         = model.PROCESS_STAMP;
                entity.INTERFACE_ERROR       = model.INTERFACE_ERROR;
                entity.COMPANY            = model.COMPANY;
                entity.ITEM               = model.ITEM;
                entity.LOCATION           = model.LOCATION;
                entity.ATTRIBUTE1         = model.ATTRIBUTE1;
                entity.ATTRIBUTE2         = model.ATTRIBUTE2;
                entity.ATTRIBUTE3         = model.ATTRIBUTE3;
                entity.ATTRIBUTE4         = model.ATTRIBUTE4;
                entity.ATTRIBUTE5         = model.ATTRIBUTE5;
                entity.ATTRIBUTE6         = model.ATTRIBUTE6;
                entity.ATTRIBUTE7         = model.ATTRIBUTE7;
                entity.ATTRIBUTE8         = model.ATTRIBUTE8;
                entity.QUANTITY           = model.QUANTITY;
                entity.QUANTITY_UM        = model.QUANTITY_UM;
                entity.REFERENCE_ID       = model.REFERENCE_ID;
                entity.REFERENCE_LINE_NUM = model.REFERENCE_LINE_NUM;
                entity.REFERENCE_TYPE     = model.REFERENCE_TYPE;
                entity.REFERENCE_NUM_TYPE = model.REFERENCE_NUM_TYPE;
                entity.TRANSACTION_TYPE   = model.TRANSACTION_TYPE;
                entity.USER_STAMP         = model.USER_STAMP;
                entity.WAREHOUSE          = model.WAREHOUSE;
                entity.ZONE               = model.ZONE;
                entity.USER_DEF1          = model.USER_DEF1;
                entity.USER_DEF2          = model.USER_DEF2;
                entity.USER_DEF3          = model.USER_DEF3;
                entity.USER_DEF4          = model.USER_DEF4;
                entity.USER_DEF5          = model.USER_DEF5;
                entity.USER_DEF6          = model.USER_DEF6;
                entity.USER_DEF7          = model.USER_DEF7;
                entity.USER_DEF8          = model.USER_DEF8;
                entity.DATE_TIME_STAMP    = model.DATE_TIME_STAMP;
                entity.ACTIVITY_DATE_TIME = model.ACTIVITY_DATE_TIME;
                entity.DIRECTION          = model.DIRECTION;
                entity.LPN = model.LPN;
                entity.BEFORE_INVENTORY_STS = model.BEFORE_INVENTORY_STS;
                entity.AFTER_INVENTORY_STS  = model.AFTER_INVENTORY_STS;
            }
            else
            {
                Type type  = typeof(Apps.Models.SCV.AR.AR_UPLOAD_INVENTORY_TRANS_MODEL);
                Type typeE = typeof(Apps.Models.AR_UPLOAD_INVENTORY_TRANS);
                foreach (var item in updateProperties)
                {
                    System.Reflection.PropertyInfo pi  = type.GetProperty(item);
                    System.Reflection.PropertyInfo piE = typeE.GetProperty(item);
                    piE.SetValue(entity, pi.GetValue(model), null);
                }
            }


            m_Rep.Modify(entity, updateProperties);
        }
        /// <summary>
        ///     Updates the page configuration.
        /// </summary>
        public void Update(ArrayList customFields)
        {
            foreach (Dictionary <String, Object> customField in customFields)
            {
                // Get the custom field object
                LocalScreenCustomFieldModel fieldObject = null;

                if (customField.ContainsKey("Id"))
                {
                    int    Id  = 0;
                    string sId = customField["Id"].ConvertTo <String>().TrimOrNullify(); // TODO: can simplify this if Id is already an int?
                    if (int.TryParse(sId, out Id))
                    {
                        fieldObject = this.Provider.UserInterface.ScreenCustomField.FetchById(Id);
                    }
                }

                if (customField.ContainsKey("DeleteMe") && customField["DeleteMe"].ToString() == "1")
                {
                    if (fieldObject != null)
                    {
                        fieldObject.Delete();
                    }
                }
                else
                {
                    if (fieldObject == null)
                    {
                        fieldObject = this.Provider.UserInterface.ScreenCustomField.Create();
                    }

                    Type objType = fieldObject.GetType();
                    // Apply the properties
                    foreach (string key in customField.Keys)
                    {
                        System.Reflection.PropertyInfo fieldInfo = objType.GetProperty(key);
                        if (fieldInfo != null &&
                            fieldInfo.SetMethod != null &&
                            key != "Cftype" &&
                            key != "CustomFieldValues" &&
                            key != "CustomFieldListItems"
                            )
                        {
                            object currValue = fieldInfo.GetValue(fieldObject);
                            if (currValue != null)
                            {
                                fieldInfo.SetValue(fieldObject, customField[key].ConvertTo(fieldInfo.PropertyType, fieldInfo.GetValue(fieldObject).ConvertTo(fieldInfo.PropertyType)));
                            }
                            else
                            {
                                fieldInfo.SetValue(fieldObject, customField[key].ConvertTo(fieldInfo.PropertyType));
                            }
                        }
                    }

                    if (customField.ContainsKey("CustomFieldListItems"))
                    {
                        ArrayList listItems = customField["CustomFieldListItems"] as ArrayList;
                        LocalCollection <LocalScreenCustomFieldListitemModel, IScreenCustomFieldListitemModel> listObjects = fieldObject.CustomFieldListItems;

                        foreach (Dictionary <string, object> listItem in listItems)
                        {
                            LocalScreenCustomFieldListitemModel listObject;

                            if (listItem.ContainsKey("Id") && !string.IsNullOrEmpty(listItem["Id"].ToString()))
                            {
                                listObject = listObjects.FirstOrDefault(i => i.Id == listItem["Id"].ConvertTo <int>());

                                if (listItem.ContainsKey("DeleteMe") && listItem["DeleteMe"].ToString() == "1")
                                {
                                    listObject.Delete();
                                    listObjects.Remove(listObject);
                                }
                                else
                                {
                                    if (listItem.ContainsKey("IdValue"))
                                    {
                                        listObject.IdValue = listItem["IdValue"].ConvertTo <String>().TrimOrNullify();
                                    }
                                    if (listItem.ContainsKey("Text"))
                                    {
                                        listObject.Text = listItem["Text"].ConvertTo <String>().TrimOrNullify();
                                    }
                                }
                            }
                            else
                            {
                                if (!(listItem.ContainsKey("DeleteMe") && listItem["DeleteMe"].ToString() == "1"))
                                {
                                    listObject = this.Provider.UserInterface.ScreenCustomFieldListitem.Create();
                                    if (listItem.ContainsKey("IdValue"))
                                    {
                                        listObject.IdValue = listItem["IdValue"].ConvertTo <String>().TrimOrNullify();
                                    }
                                    if (listItem.ContainsKey("Text"))
                                    {
                                        listObject.Text = listItem["Text"].ConvertTo <String>().TrimOrNullify();
                                    }
                                    listObjects.Add(listObject);
                                }
                            }
                        }
                    }

                    // When creating a new record, ensure that the url and page are set
                    if (!fieldObject.IsPersisted && fieldObject.IsModified)
                    {
                        fieldObject.Page = customField["Page"].ConvertTo <String>();
                        fieldObject.Url  = customField["Url"].ConvertTo <String>();
                    }
                    fieldObject.Save();
                }
            }
        }
        public virtual void Modify(ref ValidationErrors errors, Apps.Models.SCV.INVENTORY.INVENTORY_TRANSACTION_MODEL model, params string[] updateProperties)
        {
            Apps.Models.INVENTORY_TRANSACTION entity = m_Rep.GetById(model.INTERNAL_INV_TRAN_ID);
            if (entity == null)
            {
                errors.Add(Resource.Disable);
                return;
            }
            if (updateProperties.Count() <= 0)
            {
                entity.INTERNAL_INV_TRAN_ID = model.INTERNAL_INV_TRAN_ID;
                entity.TRANSACTION_TYPE     = model.TRANSACTION_TYPE;
                entity.WAREHOUSE            = model.WAREHOUSE;
                entity.COMPANY               = model.COMPANY;
                entity.ITEM                  = model.ITEM;
                entity.ATTRIBUTE_NUM         = model.ATTRIBUTE_NUM;
                entity.ATTRIBUTE1            = model.ATTRIBUTE1;
                entity.ATTRIBUTE2            = model.ATTRIBUTE2;
                entity.ATTRIBUTE3            = model.ATTRIBUTE3;
                entity.ATTRIBUTE4            = model.ATTRIBUTE4;
                entity.ATTRIBUTE5            = model.ATTRIBUTE5;
                entity.ATTRIBUTE6            = model.ATTRIBUTE6;
                entity.ATTRIBUTE7            = model.ATTRIBUTE7;
                entity.ATTRIBUTE8            = model.ATTRIBUTE8;
                entity.QUANTITY              = model.QUANTITY;
                entity.QUANTITY_UM           = model.QUANTITY_UM;
                entity.LOCATION              = model.LOCATION;
                entity.LPN                   = model.LPN;
                entity.TASK_ID               = model.TASK_ID;
                entity.TASK_TYPE             = model.TASK_TYPE;
                entity.REFERENCE_ID          = model.REFERENCE_ID;
                entity.REFERENCE_NUM         = model.REFERENCE_NUM;
                entity.REFERENCE_TYPE        = model.REFERENCE_TYPE;
                entity.REFERENCE_LINE_NUM    = model.REFERENCE_LINE_NUM;
                entity.BEFORE_ON_HAND_QTY    = model.BEFORE_ON_HAND_QTY;
                entity.BEFORE_IN_TRANSIT_QTY = model.BEFORE_IN_TRANSIT_QTY;
                entity.BEFORE_ALLOC_QTY      = model.BEFORE_ALLOC_QTY;
                entity.BEFORE_STS            = model.BEFORE_STS;
                entity.AFTER_ON_HAND_QTY     = model.AFTER_ON_HAND_QTY;
                entity.AFTER_IN_TRANSIT_QTY  = model.AFTER_IN_TRANSIT_QTY;
                entity.AFTER_ALLOC_QTY       = model.AFTER_ALLOC_QTY;
                entity.AFTER_STS             = model.AFTER_STS;
                entity.USER_NAME             = model.USER_NAME;
                entity.USER_STAMP            = model.USER_STAMP;
                entity.DATE_TIME_STAMP       = model.DATE_TIME_STAMP;
            }
            else
            {
                Type type  = typeof(Apps.Models.SCV.INVENTORY.INVENTORY_TRANSACTION_MODEL);
                Type typeE = typeof(Apps.Models.INVENTORY_TRANSACTION);
                foreach (var item in updateProperties)
                {
                    System.Reflection.PropertyInfo pi  = type.GetProperty(item);
                    System.Reflection.PropertyInfo piE = typeE.GetProperty(item);
                    piE.SetValue(entity, pi.GetValue(model), null);
                }
            }


            m_Rep.Modify(entity, updateProperties);
        }
        private static void ProcessOneVariable(NotificationVariable variableNode, Guid entityId, DbContext context, List <NotificationVariable> notificationVariables,
                                               Dictionary <string, object> values, string relationEntityName,
                                               ref Guid relationId, Dictionary <string, object> oldValue, int languageId)
        {
            var  entityInfo = MetadataProvider.Instance.EntiyMetadata.Where(c => c.EntityId == variableNode.EntityId).First();
            Type entityType = DynamicTypeBuilder.Instance.GetDynamicType(entityInfo.PhysicalName);

            if (!string.IsNullOrEmpty(relationEntityName) && relationEntityName == entityInfo.PhysicalName)
            {
                relationId = entityId;
            }
            IQueryable     query          = context.Set(entityType).AsQueryable();
            BinaryOperator binaryOperator = new BinaryOperator();

            binaryOperator.OperatorType = BinaryOperatorType.Equal;
            binaryOperator.LeftOperand  = ConstantValue.Parse(entityInfo.Attributes.Where(c => c.IsPKAttribute == true).First().TableColumnName);
            binaryOperator.RightOperand = entityId;
            System.Linq.Expressions.Expression exception = GetExpression(query, binaryOperator);
            query = query.Provider.CreateQuery(exception);
            IEnumerator iter          = query.GetEnumerator();
            object      currentObject = null;
            int         iterIndex     = 0;

            while (iter.MoveNext())
            {
                if (iter.Current != null && iterIndex == 0)
                {
                    currentObject = iter.Current;
                }
                iterIndex++;
            }
            if (currentObject == null)
            {
                return;
            }
            Dictionary <string, object> properValueList = new Dictionary <string, object>();

            foreach (var att in entityInfo.Attributes)
            {
                System.Reflection.PropertyInfo pro = currentObject.GetType().GetProperty(att.PhysicalName);
                if (pro == null)
                {
                    continue;
                }
                var proValue = pro.GetValue(currentObject, null);
                if (att.OptionSet != null)
                {
                    if (proValue != null && !string.IsNullOrEmpty(proValue.ToString()))
                    {
                        var picValue   = att.OptionSet.AttributePicklistValues.Where(c => c.Value == int.Parse(proValue.ToString())).First();
                        var labelValue = MetadataProvider.Instance.LocalizedLabels.Where(c => c.ObjectId == picValue.AttributePicklistValueId && c.LanguageId == languageId);
                        if (labelValue.Count() <= 0)
                        {
                            labelValue = MetadataProvider.Instance.LocalizedLabels.Where(c => c.ObjectId == picValue.AttributePicklistValueId);
                        }
                        var lable = labelValue.First();
                        proValue = lable.Label;
                    }

                    if (oldValue != null && oldValue.Keys.Contains(att.PhysicalName))
                    {
                        var oldV = oldValue[att.PhysicalName];
                        if (oldV != null && !string.IsNullOrEmpty(oldV.ToString()))
                        {
                            var picValue   = att.OptionSet.AttributePicklistValues.Where(c => c.Value == int.Parse(oldV.ToString())).First();
                            var labelValue = MetadataProvider.Instance.LocalizedLabels.Where(c => c.ObjectId == picValue.AttributePicklistValueId && c.LanguageId == languageId);
                            if (labelValue.Count() <= 0)
                            {
                                labelValue = MetadataProvider.Instance.LocalizedLabels.Where(c => c.ObjectId == picValue.AttributePicklistValueId);
                            }
                            var lable = labelValue.First();
                            properValueList.Add("Old" + att.PhysicalName, lable.Label);
                        }
                    }
                }
                properValueList.Add(att.PhysicalName, proValue);
            }
            values.Add(entityInfo.PhysicalName, properValueList);
            var subVariables = notificationVariables.Where(c => c.ParentId == variableNode.NotificationVariableId);

            foreach (var subNode in subVariables)
            {
                var relatedAtt = entityInfo.Attributes.Where(c => c.AttributeId == subNode.RelatedAttributeId).FirstOrDefault();
                if (relatedAtt == null)
                {
                    continue;
                }
                Guid subEntityId = (Guid)properValueList[relatedAtt.PhysicalName];
                ProcessOneVariable(subNode, subEntityId, context, notificationVariables, properValueList, relationEntityName, ref relationId, oldValue, languageId);
            }
        }
Exemple #17
0
        /// <summary>
        /// This function searches recursively through the Object "obj" and generates Tags for each
        /// property found with an HubTag-Attribute.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns>A list of Tags (that may have a lot of child-Tags as well).</returns>
        internal static IEnumerable <Tag> ExtractTagsFromAttributes(object obj)
        {
            if (string.IsNullOrEmpty(obj as string))
            {
                if (obj.GetType().Assembly.FullName.Contains("Chummer"))
                {
                    //check, if the type has an HubClassTagAttribute
                    List <HubClassTagAttribute> classprops = new List <HubClassTagAttribute>();
                    foreach (object objCustomAttribute in obj.GetType().GetCustomAttributes(typeof(HubClassTagAttribute), true))
                    {
                        if (objCustomAttribute is HubClassTagAttribute objToAdd)
                        {
                            classprops.Add(objToAdd);
                        }
                    }
                    if (classprops.Count > 0)
                    {
                        foreach (var classprop in classprops)
                        {
                            Tag tag = new Tag(obj, classprop);
                            tag.SetTagTypeEnumFromCLRType(obj.GetType());
                            if (!string.IsNullOrEmpty(classprop.ListInstanceNameFromProperty))
                            {
                                tag.TagName = classprop.ListInstanceNameFromProperty;
                                PropertyInfo childprop = obj.GetType().GetProperties().FirstOrDefault(x => x.Name == classprop.ListInstanceNameFromProperty);
                                if (childprop == null)
                                {
                                    throw new ArgumentOutOfRangeException("Could not find property " + classprop.ListInstanceNameFromProperty + " on instance of type " + obj.GetType() + ".");
                                }
                                tag.TagValue += childprop.GetValue(obj);
                            }
                            if (string.IsNullOrEmpty(tag.TagName))
                            {
                                tag.TagName = obj.ToString();
                            }
                            tag.AddPropertyValuesToTagComment(obj, classprop);
                            tag.Tags = new List <Tag>(ExtractTagsFromExtraProperties(obj, classprop));
                            yield return(tag);
                        }
                        yield break;
                    }
                }

                if (obj is IEnumerable islist)
                {
                    foreach (var item in islist)
                    {
                        List <HubClassTagAttribute> classprops = new List <HubClassTagAttribute>();
                        foreach (object objCustomAttribute in item.GetType().GetCustomAttributes(typeof(HubClassTagAttribute), true))
                        {
                            if (objCustomAttribute is HubClassTagAttribute objToAdd)
                            {
                                classprops.Add(objToAdd);
                            }
                        }
                        foreach (var classprop in classprops)
                        {
                            var tag = new Tag(item, classprop)
                            {
                                TagType = 0,// "list",
                                //TagName = classprop.ListName
                            };
                            if (!string.IsNullOrEmpty(classprop.ListInstanceNameFromProperty))
                            {
                                tag.TagName = classprop.ListInstanceNameFromProperty;
                                var childprop = item.GetType().GetProperties().FirstOrDefault(x => x.Name == classprop.ListInstanceNameFromProperty);
                                if (childprop == null)
                                {
                                    throw new ArgumentOutOfRangeException("Could not find property " + classprop.ListInstanceNameFromProperty + " on instance of type " + item.GetType() + ".");
                                }
                                tag.TagValue += childprop.GetValue(item);
                            }
                            if (string.IsNullOrEmpty(tag.TagName))
                            {
                                tag.TagName = item.ToString();
                            }

                            tag.AddPropertyValuesToTagComment(item, classprop);
                            tag.Tags = new List <Tag>(ExtractTagsFromExtraProperties(item, classprop));
                            yield return(tag);
                        }
                    }
                    yield break;
                }
            }
            foreach (PropertyInfo property in obj.GetType().GetProperties())
            {
                object[] aCustomAttributes = property.GetCustomAttributes(typeof(HubTagAttribute), true);
                if (aCustomAttributes.Length > 0 && aCustomAttributes[0] is HubTagAttribute objAttribute)
                {
                    foreach (Tag objChild in ExtractTagsFromPropertyWithSpecificAttribute(obj, property, objAttribute))
                    {
                        if (!objAttribute.DeleteIfEmpty || objChild.Tags.Count > 0 || !string.IsNullOrEmpty(objChild.TagValue))
                        {
                            yield return(objChild);
                        }
                    }
                }
            }
        }
Exemple #18
0
 public static void Configure(this IConfigurable leftHand)
 {
     if (leftHand == null)
     {
         return;
     }
     if (leftHand.Properties == null)
     {
         return;
     }
     foreach (var property in leftHand.Properties)
     {
         System.Reflection.PropertyInfo prop = null;
         try
         {
             prop = leftHand.GetType().GetProperty(property);                   //can be null if property not exists, can throw exceptions
             var value = leftHand.Config.GetValue(leftHand.Section, prop.Name); //can throw exceptions
             prop.SetValue(leftHand, value);
         }
         catch
         {
             if (prop != null)
             {
                 leftHand.Config.SetValue(leftHand.Section, prop.Name, (string)prop.GetValue(leftHand));
             }
         }
     }
 }
        public virtual void Modify(ref ValidationErrors errors, Apps.Models.SCV.DOWNLOAD.DOWNLOAD_SHIPMENT_HEADER_MODEL model, params string[] updateProperties)
        {
            Apps.Models.DOWNLOAD_SHIPMENT_HEADER entity = m_Rep.GetById(model.INTERFACE_RECORD_ID);
            if (entity == null)
            {
                errors.Add(Resource.Disable);
                return;
            }
            if (updateProperties.Count() <= 0)
            {
                entity.INTERFACE_RECORD_ID   = model.INTERFACE_RECORD_ID;
                entity.INTERFACE_ACTION_CODE = model.INTERFACE_ACTION_CODE;
                entity.INTERFACE_CONDITION   = model.INTERFACE_CONDITION;
                entity.PROCESS_STAMP         = model.PROCESS_STAMP;
                entity.WAREHOUSE             = model.WAREHOUSE;
                entity.COMPANY                    = model.COMPANY;
                entity.INTERNAL_LOAD_NUM          = model.INTERNAL_LOAD_NUM;
                entity.SHIPMENT_ID                = model.SHIPMENT_ID;
                entity.ERP_ORDER                  = model.ERP_ORDER;
                entity.LEADING_STS                = model.LEADING_STS;
                entity.TRAILING_STS               = model.TRAILING_STS;
                entity.PROCESS_TYPE               = model.PROCESS_TYPE;
                entity.SHIPMENT_TYPE              = model.SHIPMENT_TYPE;
                entity.ROUTE                      = model.ROUTE;
                entity.SHIP_TO                    = model.SHIP_TO;
                entity.SHIP_TO_NAME               = model.SHIP_TO_NAME;
                entity.SHIP_TO_ADDRESS1           = model.SHIP_TO_ADDRESS1;
                entity.SHIP_TO_ADDRESS2           = model.SHIP_TO_ADDRESS2;
                entity.SHIP_TO_DISTRICT           = model.SHIP_TO_DISTRICT;
                entity.SHIP_TO_CITY               = model.SHIP_TO_CITY;
                entity.SHIP_TO_STATE              = model.SHIP_TO_STATE;
                entity.SHIP_TO_COUNTRY            = model.SHIP_TO_COUNTRY;
                entity.SHIP_TO_POSTAL_CODE        = model.SHIP_TO_POSTAL_CODE;
                entity.SHIP_TO_ATTENTION_TO       = model.SHIP_TO_ATTENTION_TO;
                entity.SHIP_TO_PHONE_NUM          = model.SHIP_TO_PHONE_NUM;
                entity.SHIP_TO_FAX_NUM            = model.SHIP_TO_FAX_NUM;
                entity.SHIP_TO_EMAIL_ADDRESS      = model.SHIP_TO_EMAIL_ADDRESS;
                entity.PRIORITY                   = model.PRIORITY;
                entity.USER_STAMP                 = model.USER_STAMP;
                entity.DATE_TIME_STAMP            = model.DATE_TIME_STAMP;
                entity.REQUESTED_DELIVERY_DATE    = model.REQUESTED_DELIVERY_DATE;
                entity.REQUESTED_DELIVERY_TYPE    = model.REQUESTED_DELIVERY_TYPE;
                entity.SCHEDULED_SHIP_DATE        = model.SCHEDULED_SHIP_DATE;
                entity.ACTUAL_SHIP_DATE_TIME      = model.ACTUAL_SHIP_DATE_TIME;
                entity.ACTUAL_DELIVERY_DATE_TIME  = model.ACTUAL_DELIVERY_DATE_TIME;
                entity.DELIVERY_NOTE              = model.DELIVERY_NOTE;
                entity.REJECTION_NOTE             = model.REJECTION_NOTE;
                entity.INTERNAL_WAVE_NUM          = model.INTERNAL_WAVE_NUM;
                entity.SHIP_DOCK                  = model.SHIP_DOCK;
                entity.ALLOCATE_COMPLETE          = model.ALLOCATE_COMPLETE;
                entity.TOTAL_QTY                  = model.TOTAL_QTY;
                entity.TOTAL_WEIGHT               = model.TOTAL_WEIGHT;
                entity.WEIGHT_UM                  = model.WEIGHT_UM;
                entity.TOTAL_VOLUME               = model.TOTAL_VOLUME;
                entity.VOLUME_UM                  = model.VOLUME_UM;
                entity.TOTAL_LINES                = model.TOTAL_LINES;
                entity.TOTAL_CONTAINERS           = model.TOTAL_CONTAINERS;
                entity.CARRIER                    = model.CARRIER;
                entity.CARRIER_SERVICE            = model.CARRIER_SERVICE;
                entity.USER_DEF1                  = model.USER_DEF1;
                entity.USER_DEF2                  = model.USER_DEF2;
                entity.USER_DEF3                  = model.USER_DEF3;
                entity.USER_DEF4                  = model.USER_DEF4;
                entity.USER_DEF5                  = model.USER_DEF5;
                entity.USER_DEF6                  = model.USER_DEF6;
                entity.USER_DEF7                  = model.USER_DEF7;
                entity.USER_DEF8                  = model.USER_DEF8;
                entity.BACK_ORDER_NUM             = model.BACK_ORDER_NUM;
                entity.LAST_WAVE_NUM              = model.LAST_WAVE_NUM;
                entity.GROUP_NUM                  = model.GROUP_NUM;
                entity.GROUP_INDEX                = model.GROUP_INDEX;
                entity.SIGN_VALUE                 = model.SIGN_VALUE;
                entity.SHIPMENT_SUB_TYPE          = model.SHIPMENT_SUB_TYPE;
                entity.SHIPMENT_CATEGORY1         = model.SHIPMENT_CATEGORY1;
                entity.SHIPMENT_CATEGORY2         = model.SHIPMENT_CATEGORY2;
                entity.SHIPMENT_CATEGORY3         = model.SHIPMENT_CATEGORY3;
                entity.SHIPMENT_CATEGORY4         = model.SHIPMENT_CATEGORY4;
                entity.SHIPMENT_CATEGORY5         = model.SHIPMENT_CATEGORY5;
                entity.SHIPMENT_CATEGORY6         = model.SHIPMENT_CATEGORY6;
                entity.SHIPMENT_CATEGORY7         = model.SHIPMENT_CATEGORY7;
                entity.SHIPMENT_CATEGORY8         = model.SHIPMENT_CATEGORY8;
                entity.SHIP_TO_MOBILE             = model.SHIP_TO_MOBILE;
                entity.TOTAL_VALUE                = model.TOTAL_VALUE;
                entity.USER_DEF9                  = model.USER_DEF9;
                entity.USER_DEF10                 = model.USER_DEF10;
                entity.UPLOAD_INTERFACE_FLAG      = model.UPLOAD_INTERFACE_FLAG;
                entity.SHIPMENT_NOTE              = model.SHIPMENT_NOTE;
                entity.STOP_SEQ                   = model.STOP_SEQ;
                entity.CREATE_DATE_TIME           = model.CREATE_DATE_TIME;
                entity.CREATE_USER                = model.CREATE_USER;
                entity.COD_REQUIRED               = model.COD_REQUIRED;
                entity.COD_VALUE                  = model.COD_VALUE;
                entity.DEIVERY_WINDOW             = model.DEIVERY_WINDOW;
                entity.ALLOW_CONSOLIDATE          = model.ALLOW_CONSOLIDATE;
                entity.CONSOLIDATED               = model.CONSOLIDATED;
                entity.INVOICE_REQUIRED           = model.INVOICE_REQUIRED;
                entity.INTERNAL_INVOICE_NUM       = model.INTERNAL_INVOICE_NUM;
                entity.HOST_COMPANY               = model.HOST_COMPANY;
                entity.UPLOAD_INTERFACE_DATE_TIME = model.UPLOAD_INTERFACE_DATE_TIME;
                entity.UPLOAD_INTERFACE_REQUIRED  = model.UPLOAD_INTERFACE_REQUIRED;
                entity.SO_OPERATOR                = model.SO_OPERATOR;
                entity.SO_OPERATOR_PHONE_NUM      = model.SO_OPERATOR_PHONE_NUM;
                entity.SO_EMAIL_ADDRESS           = model.SO_EMAIL_ADDRESS;
            }
            else
            {
                Type type  = typeof(Apps.Models.SCV.DOWNLOAD.DOWNLOAD_SHIPMENT_HEADER_MODEL);
                Type typeE = typeof(Apps.Models.DOWNLOAD_SHIPMENT_HEADER);
                foreach (var item in updateProperties)
                {
                    System.Reflection.PropertyInfo pi  = type.GetProperty(item);
                    System.Reflection.PropertyInfo piE = typeE.GetProperty(item);
                    piE.SetValue(entity, pi.GetValue(model), null);
                }
            }


            m_Rep.Modify(entity, updateProperties);
        }
Exemple #20
0
        public virtual void Modify(ref ValidationErrors errors, Apps.Models.SCV.ATTRIBUTE.ATTRIBUTE_TEMPLATE_MODEL model, params string[] updateProperties)
        {
            Apps.Models.ATTRIBUTE_TEMPLATE entity = m_Rep.GetById(model.INTERNAL_TEMPLATE_NUM);
            if (entity == null)
            {
                errors.Add(Resource.Disable);
                return;
            }
            if (updateProperties.Count() <= 0)
            {
                entity.INTERNAL_TEMPLATE_NUM   = model.INTERNAL_TEMPLATE_NUM;
                entity.ATTRIBUTE_TEMPLATE_NAME = model.ATTRIBUTE_TEMPLATE_NAME;
                entity.ACTIVE            = model.ACTIVE;
                entity.ATTRIBUTE_NAME1   = model.ATTRIBUTE_NAME1;
                entity.AUTO_FILL1        = model.AUTO_FILL1;
                entity.AUTO_FILL_FORMAT1 = model.AUTO_FILL_FORMAT1;
                entity.PATTERN1          = model.PATTERN1;
                entity.ACTIVE1           = model.ACTIVE1;
                entity.READY_ONLY1       = model.READY_ONLY1;
                entity.ATTRIBUTE_NAME2   = model.ATTRIBUTE_NAME2;
                entity.AUTO_FILL2        = model.AUTO_FILL2;
                entity.AUTO_FILL_FORMAT2 = model.AUTO_FILL_FORMAT2;
                entity.PATTERN2          = model.PATTERN2;
                entity.ACTIVE2           = model.ACTIVE2;
                entity.READY_ONLY2       = model.READY_ONLY2;
                entity.ATTRIBUTE_NAME3   = model.ATTRIBUTE_NAME3;
                entity.AUTO_FILL3        = model.AUTO_FILL3;
                entity.AUTO_FILL_FORMAT3 = model.AUTO_FILL_FORMAT3;
                entity.PATTERN3          = model.PATTERN3;
                entity.ACTIVE3           = model.ACTIVE3;
                entity.READY_ONLY3       = model.READY_ONLY3;
                entity.ATTRIBUTE_NAME4   = model.ATTRIBUTE_NAME4;
                entity.AUTO_FILL4        = model.AUTO_FILL4;
                entity.AUTO_FILL_FORMAT4 = model.AUTO_FILL_FORMAT4;
                entity.PATTERN4          = model.PATTERN4;
                entity.ACTIVE4           = model.ACTIVE4;
                entity.READY_ONLY4       = model.READY_ONLY4;
                entity.ATTRIBUTE_NAME5   = model.ATTRIBUTE_NAME5;
                entity.AUTO_FILL5        = model.AUTO_FILL5;
                entity.AUTO_FILL_FORMAT5 = model.AUTO_FILL_FORMAT5;
                entity.PATTERN5          = model.PATTERN5;
                entity.ACTIVE5           = model.ACTIVE5;
                entity.READY_ONLY5       = model.READY_ONLY5;
                entity.ATTRIBUTE_NAME6   = model.ATTRIBUTE_NAME6;
                entity.AUTO_FILL6        = model.AUTO_FILL6;
                entity.AUTO_FILL_FORMAT6 = model.AUTO_FILL_FORMAT6;
                entity.PATTERN6          = model.PATTERN6;
                entity.ACTIVE6           = model.ACTIVE6;
                entity.READY_ONLY6       = model.READY_ONLY6;
                entity.ATTRIBUTE_NAME7   = model.ATTRIBUTE_NAME7;
                entity.AUTO_FILL7        = model.AUTO_FILL7;
                entity.AUTO_FILL_FORMAT7 = model.AUTO_FILL_FORMAT7;
                entity.PATTERN7          = model.PATTERN7;
                entity.ACTIVE7           = model.ACTIVE7;
                entity.READY_ONLY7       = model.READY_ONLY7;
                entity.ATTRIBUTE_NAME8   = model.ATTRIBUTE_NAME8;
                entity.AUTO_FILL8        = model.AUTO_FILL8;
                entity.AUTO_FILL_FORMAT8 = model.AUTO_FILL_FORMAT8;
                entity.PATTERN8          = model.PATTERN8;
                entity.ACTIVE8           = model.ACTIVE8;
                entity.READY_ONLY8       = model.READY_ONLY8;
                entity.USER_STAMP        = model.USER_STAMP;
                entity.DATE_TIME_STAMP   = model.DATE_TIME_STAMP;
            }
            else
            {
                Type type  = typeof(Apps.Models.SCV.ATTRIBUTE.ATTRIBUTE_TEMPLATE_MODEL);
                Type typeE = typeof(Apps.Models.ATTRIBUTE_TEMPLATE);
                foreach (var item in updateProperties)
                {
                    System.Reflection.PropertyInfo pi  = type.GetProperty(item);
                    System.Reflection.PropertyInfo piE = typeE.GetProperty(item);
                    piE.SetValue(entity, pi.GetValue(model), null);
                }
            }


            m_Rep.Modify(entity, updateProperties);
        }
Exemple #21
0
        /// <summary>
        /// Get Property value
        /// </summary>
        /// <param name="property">Property</param>
        /// <param name="entity">Entity</param>
        /// <returns>Value</returns>
        private object GetPropertyValue(System.Reflection.PropertyInfo property, object entity)
        {
            object returnValue = property.GetValue(entity, null);

            return(returnValue);
        }
Exemple #22
0
        public static TDestination CopyProperties <TDestination>(object LinqSource)
        {
            Type SourceType      = LinqSource.GetType();
            Type DestinationType = typeof(TDestination);

            System.Reflection.ConstructorInfo ci = DestinationType.GetConstructor(new Type[0]);
            TDestination rez = (TDestination)ci.Invoke(new object[0]);

            object ComplexSourceProp     = null;
            Type   ComplexSourcePropType = null;

            System.Reflection.PropertyInfo[] SourceProps = SourceType.GetProperties();
            foreach (System.Reflection.PropertyInfo SourceProp in SourceProps)
            {
                if (SourceProp.PropertyType.IsClass)
                {
                    ComplexSourceProp     = SourceProp.GetValue(LinqSource, null);
                    ComplexSourcePropType = ComplexSourceProp.GetType();
                    break;
                }
            }

            System.Reflection.FieldInfo[] DestFields = typeof(TDestination).GetFields();
            foreach (System.Reflection.FieldInfo DestField in DestFields)
            {
                bool     DataIgnore = false;
                object[] attr       = DestField.GetCustomAttributes(typeof(DataIgnoreAttrib), true);
                if (attr.Length > 0)
                {
                    DataIgnore = true;
                }

                string DestPropName   = DestField.Name;
                string UpDestPropName = DestPropName.Substring(0, 1).ToUpper() + DestPropName.Substring(1);
                attr = DestField.GetCustomAttributes(typeof(DataNameAttrib), true);
                if (attr.Length > 0)
                {
                    DestPropName   = ((DataNameAttrib)attr[0]).DataName;
                    UpDestPropName = DestPropName.Substring(0, 1).ToUpper() + DestPropName.Substring(1);
                }

                System.Reflection.PropertyInfo SourceProp = SourceType.GetProperty(DestPropName);
                if (SourceProp == null)
                {
                    SourceProp = SourceType.GetProperty(UpDestPropName);
                }
                if (SourceProp == null && DataIgnore)
                {
                    continue;
                }
                if (SourceProp == null)
                {
                    SourceProp = ComplexSourcePropType.GetProperty(DestPropName);
                    if (SourceProp == null)
                    {
                        SourceProp = ComplexSourcePropType.GetProperty(UpDestPropName);
                    }
                    //**************************************************************************************************************************************************************************
                    //if (SourceProp == null) continue;//**************************************************************************************************************************************************************************
                    //if (SourceProp.PropertyType.IsClass) continue;
                    //**************************************************************************************************************************************************************************
                    object sv = SourceProp.GetValue(ComplexSourceProp, null);
                    DestField.SetValue(rez, sv);
                }
                else
                {
                    DestField.SetValue(rez, SourceProp.GetValue(LinqSource, null));
                }
            }
            return(rez);
        }
Exemple #23
0
        private void btnGuardar_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try {
                Cursor.Current = Cursors.WaitCursor;
                if (tipo.Equals('N'))
                {
                    CheckControls(tabPage2);
                    if (contT == 0)
                    {
                        vaciarCamposBusq();
                        SubGrupos s = new SubGrupos();
                        s.descripcion = editDescripcion.Text;
                        s.grupo       = Int16.Parse(editGrupo.Text);
                        s.subGrupo    = Int16.Parse(editSubGrupo.Text);

                        Object item = sg.guardarSubGrupo(s);

                        System.Reflection.PropertyInfo m = item.GetType().GetProperty("message");
                        System.Reflection.PropertyInfo c = item.GetType().GetProperty("code");
                        String message = (String)(m.GetValue(item, null));
                        int    code    = (int)(c.GetValue(item, null));

                        if (code == 1)
                        {
                            ResetControls(tabPage2);
                            DisableControls(tabPage2);
                            tipo = 's';
                            Recargar();
                            this.tabControl1.SelectTab(0);
                            MessageBox.Show(message, "OK", MessageBoxButtons.OK, MessageBoxIcon.None);
                        }
                        else if (code == 2)
                        {
                            MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Se deben de llenar todos los campos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    contT = 0;
                }
                else if (tipo.Equals('E'))
                {
                    CheckControls(tabPage2);
                    if (contT == 0)
                    {
                        vaciarCamposBusq();
                        SubGrupos s = new SubGrupos();
                        s.descripcion = editDescripcion.Text;
                        s.grupo       = Int16.Parse(editGrupo.Text);
                        s.subGrupo    = Int16.Parse(editSubGrupo.Text);

                        Object item = sg.editarSubGrupo(s, grupoA, subGrupoA);

                        System.Reflection.PropertyInfo m = item.GetType().GetProperty("message");
                        System.Reflection.PropertyInfo c = item.GetType().GetProperty("code");
                        String message = (String)(m.GetValue(item, null));
                        int    code    = (int)(c.GetValue(item, null));

                        if (code == 1)
                        {
                            ResetControls(tabPage2);
                            DisableControls(tabPage2);
                            tipo = 's';
                            Recargar();
                            this.tabControl1.SelectTab(0);
                            MessageBox.Show(message, "OK", MessageBoxButtons.OK, MessageBoxIcon.None);
                        }
                        else if (code == 2)
                        {
                            MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Se deben de llenar todos los campos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    contT = 0;
                }
                else if (tipo.Equals('s'))
                {
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #24
0
 protected virtual int GetEntityId(TEntity entity)
 {
     return((int)idGetter.GetValue(entity, null));
 }
Exemple #25
0
        /// <summary>
        /// Validates the specified property.
        /// </summary>
        /// <param name="property">The property that will its value validated.</param>
        /// <param name="sender">The sender who owns the property.</param>
        /// <returns>
        /// Returns a validation message if validation failed. Otherwise null is returned to indicate a passing validation.
        /// </returns>
        public override IValidationMessage Validate(System.Reflection.PropertyInfo property, IValidatable sender)
        {
            if (!this.CanValidate(sender))
            {
                return(null);
            }

            // Set up localization if available.
            this.PrepareLocalization();

            var validationMessage =
                Activator.CreateInstance(this.ValidationMessageType, this.FailureMessage) as IValidationMessage;

            // Get the property value.
            var propertyValue = property.GetValue(sender, null);

            // Ensure the property value is the same data type we are comparing to.
            if (!this.ValidateDataTypesAreEqual(propertyValue))
            {
                var error = string.Format(
                    "The property '{0}' data type is not the same as the data type ({1}) specified for validation checks. They must be the same Type.",
                    property.PropertyType.Name,
                    this.numberDataType.ToString());
                throw new ArgumentNullException(error);
            }

            // Check if we need to compare against another property.
            object alternateProperty = null;

            if (!string.IsNullOrEmpty(this.ComparisonProperty))
            {
                // Fetch the value of the secondary property specified.
                alternateProperty = this.GetComparisonValue(sender, this.ComparisonProperty);
            }

            IValidationMessage result = null;

            if (this.numberDataType == ValidationNumberDataTypes.Short)
            {
                result = ValidateMinimumShortValue(propertyValue, alternateProperty, validationMessage);
            }
            else if (this.numberDataType == ValidationNumberDataTypes.Int)
            {
                result = this.ValidateMinimumIntegerValue(propertyValue, alternateProperty, validationMessage);
            }
            else if (this.numberDataType == ValidationNumberDataTypes.Long)
            {
                result = this.ValidateMinimumLongValue(propertyValue, alternateProperty, validationMessage);
            }
            else if (this.numberDataType == ValidationNumberDataTypes.Float)
            {
                result = this.ValidateMinimumFloatValue(propertyValue, alternateProperty, validationMessage);
            }
            else if (this.numberDataType == ValidationNumberDataTypes.Double)
            {
                result = this.ValidateMinimumDoubleValue(propertyValue, alternateProperty, validationMessage);
            }
            else if (this.numberDataType == ValidationNumberDataTypes.Decimal)
            {
                result = this.ValidateMinimumDecimalValue(propertyValue, alternateProperty, validationMessage);
            }

            return(this.RunInterceptedValidation(sender, property, result));
        }
            /// <summary>
            /// Recupera o valor da propriedade da instancia.
            /// </summary>
            /// <param name="instance"></param>
            /// <returns></returns>
            public object GetValue(object instance)
            {
                var value = _info.GetValue(instance, null);

                return(ConvertValue(value));
            }
Exemple #27
0
 private object getProperty(object from_me, String get_me)
 {
     System.Reflection.PropertyInfo info = from_me.GetType().GetProperty(get_me);
     return(info.GetValue(from_me, null));
 }
Exemple #28
0
 /// <summary>
 /// GetPropertyValue
 /// </summary>
 protected override object GetPropertyValue(System.Reflection.PropertyInfo propertyInfo, object target, System.Globalization.CultureInfo culture)
 {
     return(propertyInfo.GetValue(target, System.Reflection.BindingFlags.Default, null, null, culture));
 }
Exemple #29
0
        public void AddDataOfType(Object o, Type rettype, string name, int depth, Type[] classtypeexcluded = null)
        {
            if (depth < 0)      // 0, list, class, object, .. limit depth
            {
                return;
            }

            if (classtypeexcluded != null && classtypeexcluded.Contains(rettype))
            {
                return;
            }

            //System.Diagnostics.Debug.WriteLine("Object " + name + " " + rettype.Name);

            System.Globalization.CultureInfo ct = System.Globalization.CultureInfo.InvariantCulture;

            try // just to make sure a strange type does not barfe it
            {
                if (rettype.UnderlyingSystemType.FullName.Contains("System.Collections.Generic.Dictionary"))
                {
                    if (o == null)
                    {
                        values[name + "Count"] = "0";                           // we always get a NameCount so we can tell..
                    }
                    else
                    {
                        var data = (System.Collections.IDictionary)o;           // lovely to work out

                        values[name + "Count"] = data.Count.ToString(ct);       // purposely not putting a _ to distinguish it from the entries

                        foreach (Object k in data.Keys)
                        {
                            if (k is string)
                            {
                                Object v = data[k as string];
                                AddDataOfType(v, v.GetType(), name + "_" + (string)k, depth - 1, classtypeexcluded);
                            }
                        }
                    }
                }
                else if (rettype.UnderlyingSystemType.FullName.Contains("System.Collections.Generic.List"))
                {
                    if (o == null)
                    {
                        values[name + "Count"] = "0";                           // we always get a NameCount so we can tell..
                    }
                    else
                    {
                        var data = (System.Collections.IList)o;           // lovely to work out

                        values[name + "Count"] = data.Count.ToString(ct); // purposely not putting a _ to distinguish it from the entries

                        for (int i = 0; i < data.Count; i++)
                        {
                            AddDataOfType(data[i], data[i].GetType(), name + "[" + (i + 1).ToString(ct) + "]", depth - 1, classtypeexcluded);
                        }
                    }
                }
                else if (rettype.IsArray)
                {
                    if (o == null)
                    {
                        values[name + "_Length"] = "0";                         // always get a length
                    }
                    else
                    {
                        Array b = o as Array;
                        if (b != null)  // should not fail but just in case..
                        {
                            values[name + "_Length"] = b.Length.ToString(ct);

                            for (int i = 0; i < b.Length; i++)
                            {
                                object oa = b.GetValue(i);
                                AddDataOfType(oa, oa.GetType(), name + "[" + i.ToString(ct) + "]", depth - 1, classtypeexcluded);
                            }
                        }
                    }
                }
                else if (o == null)
                {
                    values[name] = "";
                }
                else if (o is string)     // string is a class, so intercept first
                {
                    values[name] = o as string;
                }
                else if (rettype.IsClass)
                {
                    foreach (System.Reflection.PropertyInfo pi in rettype.GetProperties())
                    {
                        if (pi.GetIndexParameters().GetLength(0) == 0 && pi.PropertyType.IsPublic)       // only properties with zero parameters are called
                        {
                            System.Reflection.MethodInfo getter = pi.GetGetMethod();
                            AddDataOfType(getter.Invoke(o, null), pi.PropertyType, name + "_" + pi.Name, depth - 1, classtypeexcluded);
                        }
                    }

                    foreach (System.Reflection.FieldInfo fi in rettype.GetFields())
                    {
                        AddDataOfType(fi.GetValue(o), fi.FieldType, name + "_" + fi.Name, depth - 1, classtypeexcluded);
                    }
                }
                else if (o is bool)
                {
                    values[name] = ((bool)o) ? "1" : "0";
                }
                else if (!rettype.IsGenericType || rettype.GetGenericTypeDefinition() != typeof(Nullable <>))
                {
                    var v = Convert.ChangeType(o, rettype);

                    if (v is Double)
                    {
                        values[name] = ((double)v).ToString(ct);
                    }
                    else if (v is int)
                    {
                        values[name] = ((int)v).ToString(ct);
                    }
                    else if (v is long)
                    {
                        values[name] = ((long)v).ToString(ct);
                    }
                    else if (v is DateTime)
                    {
                        values[name] = ((DateTime)v).ToString(System.Globalization.CultureInfo.CreateSpecificCulture("en-us"));
                    }
                    else
                    {
                        values[name] = v.ToString();
                    }
                }
                else
                {                                                                         // generic, get value type
                    System.Reflection.PropertyInfo pvalue = rettype.GetProperty("Value"); // value is second property of a nullable class

                    Type nulltype = pvalue.PropertyType;                                  // its type and value are found..
                    var  value    = pvalue.GetValue(o);
                    AddDataOfType(value, nulltype, name, depth - 1);                      // recurse to decode it
                }
            }
            catch { }
        }
Exemple #30
0
        /// <summary>
        /// 添加预约
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string AddOrder(HttpContext context)
        {
            try
            {
                string   id  = context.Request["id"]; //多个医生id
                string[] ids = new string[] { };      //多个医生id
                if (!string.IsNullOrEmpty(id))
                {
                    id  = id.TrimStart(',').TrimEnd(',');
                    ids = id.Split(',');
                }
                if (ids.Length >= 1)//检查是否可以预约
                {
                    foreach (var item in ids)
                    {
                        WXMallProductInfo productInfoCheck = bllMall.GetProduct(item);
                        if (productInfoCheck != null)
                        {
                            if (productInfoCheck.Stock <= 0)
                            {
                                apiResp.msg = string.Format("专家{0}的预约已满", productInfoCheck.PName);
                                return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp));
                            }
                        }
                    }
                }

                WXMallProductInfo productInfo = new WXMallProductInfo();
                WXMallOrderInfo   orderInfo   = bllMall.ConvertRequestToModel <WXMallOrderInfo>(new WXMallOrderInfo());
                if (string.IsNullOrEmpty(orderInfo.Consignee))
                {
                    apiResp.msg = "请填写姓名";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp));
                }
                if (string.IsNullOrEmpty(orderInfo.Ex1))
                {
                    apiResp.msg = "请填写年龄";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp));
                }
                if (string.IsNullOrEmpty(orderInfo.Ex2))
                {
                    apiResp.msg = "请选择性别";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp));
                }
                if (string.IsNullOrEmpty(orderInfo.Phone))
                {
                    apiResp.msg = "请填写手机号";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp));
                }
                if (!Common.MyRegex.PhoneNumLogicJudge(orderInfo.Phone))
                {
                    apiResp.msg = "请输入正确手机号";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp));
                }

                StringBuilder sbWhere = new StringBuilder();
                sbWhere.AppendFormat("  WebsiteOwner='{0}' And TableName ='ZCJ_WXMallOrderInfo' Order by Sort DESC", bllMall.WebsiteOwner);
                var fieldList = bllMall.GetList <TableFieldMapping>(sbWhere.ToString());
                if (fieldList != null && fieldList.Count > 0)
                {
                    Type type = orderInfo.GetType();
                    fieldList = fieldList.Where(p => p.FieldIsNull == 0).ToList();
                    foreach (var field in fieldList)
                    {
                        System.Reflection.PropertyInfo propertyInfo = type.GetProperty(field.Field); //获取指定名称的属性
                        var value = propertyInfo.GetValue(orderInfo, null);                          //获取属性值
                        if (value == null || string.IsNullOrEmpty(value.ToString()))
                        {
                            switch (field.FieldType)
                            {
                            case "text":
                                apiResp.msg = "请填写 " + field.MappingName;
                                break;

                            case "combox":    //下拉框
                                apiResp.msg = "请选择 " + field.MappingName;
                                break;

                            case "checkbox":    //下拉框
                                apiResp.msg = "请选择 " + field.MappingName;
                                break;

                            default:
                                break;
                            }

                            return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp));
                        }
                    }
                }



                orderInfo.OrderID      = bllMall.GetGUID(BLLJIMP.TransacType.AddMallOrder);
                orderInfo.WebsiteOwner = bllMall.WebsiteOwner;
                orderInfo.InsertDate   = DateTime.Now;
                orderInfo.OrderUserID  = "defualt";
                orderInfo.Status       = "未确认";
                if (bllMall.IsLogin)
                {
                    orderInfo.OrderUserID = bllUser.GetCurrUserID();
                }
                if (!string.IsNullOrEmpty(orderInfo.Ex6))//科系
                {
                    //推荐
                    int categoryId;
                    if (int.TryParse(orderInfo.Ex6, out categoryId))
                    {
                        WXMallCategory category = bllMall.Get <WXMallCategory>(string.Format(" AutoId={0}", categoryId));
                        if (category != null)
                        {
                            orderInfo.Ex6 = category.CategoryName;
                        }
                    }
                }
                else
                {
                    //正常预约
                    if (ids.Length == 1)
                    {
                        productInfo = bllMall.GetProduct(ids[0]);
                        if (productInfo != null)
                        {
                            if (!string.IsNullOrEmpty(productInfo.CategoryId))
                            {
                                WXMallCategory category = bllMall.Get <WXMallCategory>(string.Format(" AutoId={0}", productInfo.CategoryId));
                                if (category != null)
                                {
                                    orderInfo.Ex6 = category.CategoryName;
                                }
                            }
                        }
                    }
                }
                if (!string.IsNullOrEmpty(orderInfo.Ex5))//医生 名字或多个Id
                {
                    orderInfo.Ex5 = orderInfo.Ex5.TrimStart(',').TrimEnd(',');
                    string names = "";
                    foreach (var item in orderInfo.Ex5.Split(','))
                    {
                        int pId;
                        if (int.TryParse(item, out pId))
                        {
                            productInfo = bllMall.GetProduct(pId.ToString());
                            if (productInfo != null)
                            {
                                names += productInfo.PName + ",";
                                if (productInfo.Stock <= 0)
                                {
                                    apiResp.msg = string.Format("专家{0}的预约已满", productInfo.PName);
                                    return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp));
                                }
                            }
                        }
                    }
                    if (orderInfo.Ex5.Split(',').Length >= 1 && (!string.IsNullOrEmpty(names)))
                    {
                        orderInfo.Ex5 = names.TrimEnd(',');
                    }
                }

                ZentCloud.ZCBLLEngine.BLLTransaction tran = new ZCBLLEngine.BLLTransaction();
                if (!bllMall.Add(orderInfo, tran))
                {
                    apiResp.msg = "操作失败";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp));
                }
                if (ids.Length > 0)
                {
                    if (bllMall.Update(productInfo, string.Format("Stock-=1,SaleCount+=1"), string.Format("PID in({0})", id)) < ids.Length)
                    {
                        tran.Rollback();
                        apiResp.msg = "操作失败";
                        return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp));
                    }
                }

                tran.Commit();
                apiResp.status = true;
                bllWeixin.SendTemplateMessageToKefu("有新的预约", string.Format("姓名:{0}\\n手机:{1}", orderInfo.Consignee, orderInfo.Phone));
            }
            catch (Exception ex)
            {
                apiResp.msg = ex.Message;
            }

            return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp));
        }
Exemple #31
0
        public void GetSearchQuery(ABCHelper.ConditionBuilder strBuilder, Control current)
        {
            if (current is ISearchControl)
            {
                String strResult = ((ISearchControl)current).SearchString;
                if (String.IsNullOrWhiteSpace(strResult) == false)
                {
                    strBuilder.AddCondition(strResult);
                }
            }
            else if (current is IABCBindableControl)
            {
                System.Reflection.PropertyInfo proInfo = current.GetType().GetProperty((current as IABCBindableControl).BindingProperty);
                if (proInfo != null)
                {
                    object objValue = proInfo.GetValue(current, null);
                    if (objValue != null)
                    {
                        String strType = DataStructureProvider.GetCodingType((current as IABCBindableControl).TableName, (current as IABCBindableControl).DataMember);
                        if (strType == "int" || strType == "Nullable<int>" || strType == "double" || strType == "Nullable<double>" || strType == "bool" || strType == "Nullable<bool>")
                        {
                            strBuilder.AddCondition(String.Format(" [{0}] = {1} ", (current as IABCBindableControl).DataMember, objValue));
                        }
                        if (strType == "String" || strType == "Nullable<String>")
                        {
                            strBuilder.AddCondition(String.Format(" [{0}]  LIKE '%{1}%' ", (current as IABCBindableControl).DataMember, objValue.ToString()));
                        }
                        if (strType == "Guid" || strType == "Nullable<Guid>")
                        {
                            strBuilder.AddCondition(String.Format(" [{0}]  = '{1}' ", (current as IABCBindableControl).DataMember, objValue.ToString()));
                        }
                        if (strType == "DateTime" || strType == "Nullable<DateTime>")
                        {
                            DataFormatProvider.FieldFormat   format     = DataFormatProvider.FieldFormat.None;
                            DataFormatProvider.ABCFormatInfo formatInfo = DataFormatProvider.GetFormatInfo((current as IABCBindableControl).TableName, (current as IABCBindableControl).DataMember);
                            if (formatInfo != null)
                            {
                                format = formatInfo.ABCFormat;
                            }
                            if (format == DataFormatProvider.FieldFormat.None)
                            {
                                format = DataFormatProvider.FieldFormat.Date;
                            }


                            DateTime dtValue1 = DateTime.MinValue;
                            DateTime dtValue2 = DateTime.MaxValue;
                            if (objValue is DateTime)
                            {
                                dtValue1 = Convert.ToDateTime(objValue);
                            }
                            if (objValue is Nullable <DateTime> && (objValue as Nullable <DateTime>).HasValue)
                            {
                                dtValue1 = (objValue as Nullable <DateTime>).Value;
                            }

                            if (format == DataFormatProvider.FieldFormat.Month || format == DataFormatProvider.FieldFormat.MonthAndYear)
                            {
                                dtValue1 = new DateTime(dtValue1.Year, dtValue1.Month, 1);
                                dtValue2 = dtValue1.AddMonths(1).AddSeconds(-30);
                            }
                            else if (format == DataFormatProvider.FieldFormat.Year)
                            {
                                dtValue1 = new DateTime(dtValue1.Year, 1, 1);
                                dtValue2 = dtValue1.AddYears(1).AddSeconds(-30);
                            }
                            else
                            {
                                dtValue1 = new DateTime(dtValue1.Year, dtValue1.Month, dtValue1.Day);
                                dtValue2 = dtValue1;
                            }

                            String strFrom = TimeProvider.GenCompareDateTime((current as IABCBindableControl).DataMember, ">=", dtValue1);
                            String strTo   = TimeProvider.GenCompareDateTime((current as IABCBindableControl).DataMember, "<=", dtValue2);
                            strBuilder.AddCondition(String.Format(" ( {0} AND {1} ) ", strFrom, strTo));
                        }
                    }
                }
            }


            foreach (Control ctrl in current.Controls)
            {
                GetSearchQuery(strBuilder, ctrl);
            }
        }