コード例 #1
0
ファイル: frm_DataMig.cs プロジェクト: WFR79/EngieEducation
        private void CopyProperties(object dest, object src)
        {
            Type srctype = src.GetType();

            foreach (PropertyInfo pi in dest.GetType().GetProperties())
            {
                if (pi.CanWrite)
                {
                    if (pi.PropertyType.ToString() != "SynapseCore.Database.LabelBag")
                    {
                        pi.SetValue(dest, srctype.GetProperty(pi.Name).GetValue(src, null), null);
                    }
                    else
                    {
                        if (chk_save.Checked)
                        {
                            //--------------------------------------------
                            Int64     labelID     = 0;
                            string    DefaultText = null;
                            LabelId[] ids         = (LabelId[])pi.GetCustomAttributes(typeof(LabelId), true);
                            foreach (LabelId id in ids)
                            {
                                PropertyInfo field = src.GetType().GetProperty(id.IDField);
                                labelID = (Int64)field.GetValue(src, null);
                                if (id.DefaultField != null)
                                {
                                    PropertyInfo defaultfield = src.GetType().GetProperty(id.DefaultField);
                                    DefaultText = (string)defaultfield.GetValue(src, null);
                                }
                            }

                            ACCLabelBag srclb = new ACCLabelBag();
                            srclb.load(labelID, DefaultText);
                            //--------------------------------------------
                            LabelBag destlb = new LabelBag();
                            destlb.Labels = new List <SynapseLabel>();
                            //CopyProperties(destlb, srclb);
                            foreach (ACCSynapseLabel a_lbl in srclb.Labels)
                            {
                                SynapseLabel p_lbl = new SynapseLabel();
                                CopyProperties(p_lbl, a_lbl);

                                destlb.Labels.Add(p_lbl);
                            }
                            Int64 nextid = SynapseLabel.GetNextID();
                            foreach (LabelId id in ids)
                            {
                                dest.GetType().GetProperty(id.IDField).SetValue(dest, nextid, null);
                            }
                            foreach (SynapseLabel lbl in destlb.Labels)
                            {
                                lbl.LABELID = nextid;
                            }
                            CreateLinkEntry(srclb, labelID, nextid);
                        }
                    }
                }
            }
        }
コード例 #2
0
        public frm_SynapseObjectEdit(object SynapseObject)
        {
            InitializeComponent();
            _SynapseObject = SynapseObject;
            bags           = new Hashtable();
            languages      = SynapseLanguage.Load();
            IList <PropertyInfo> properties      = SynapseObject.GetType().GetProperties();
            IList <FieldInfo>    fields          = SynapseObject.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
            List <Control>       labelBagControl = new List <Control>();

            foreach (FieldInfo fi in fields)
            {
                if (fi.Name == "_IDproperty")
                {
                    _IDproperty = fi.GetValue(SynapseObject).ToString();
                }
                if (fi.Name == "_EcludeForSave")
                {
                    _EcludeForSave = fi.GetValue(SynapseObject).ToString();
                }
                if (fi.Name == "_tableName")
                {
                    _tableName = fi.GetValue(SynapseObject).ToString().Trim(new char[] { '[', ']' });
                }
            }
            foreach (PropertyInfo pi in from x in properties where x.PropertyType.ToString() == "SynapseCore.Database.LabelBag" select x)
            {
                uc_LabelBag bag   = new uc_LabelBag();
                object      value = pi.GetValue(SynapseObject, null);
                LabelBag    lbl   = (LabelBag)value;
                Int64       lblid = lbl.GetLabelID();
                if (lblid == 0)
                {
                    lblid = SynapseLabel.GetNextID();
                }

                LabelId[] ids = (LabelId[])pi.GetCustomAttributes(typeof(LabelId), true);
                foreach (LabelId id in ids)
                {
                    PropertyInfo field = SynapseObject.GetType().GetProperty(id.IDField);
                    field.SetValue(SynapseObject, lblid, null);
                    bags.Add(id.IDField, id);
                }

                if (lbl.Labels.Count < languages.Count)
                {
                    foreach (SynapseLanguage lang in languages)
                    {
                        if (lbl.GetLabel(lang.CODE) == null)
                        {
                            SynapseLabel newlabel = new SynapseLabel();

                            newlabel.LABELID = lblid;

                            newlabel.LANGUAGE = lang.CODE;
                            newlabel.TEXT     = "";
                            newlabel.save();
                            lbl.Labels.Add(newlabel);
                        }
                    }
                    _NewLabels = true;
                }

                bag.FieldName = pi.Name;
                bag.LblBag    = lbl;
                labelBagControl.Add(bag);
                //flowLayoutPanel1.Controls.Add(bag);
            }

            foreach (PropertyInfo pi in from x in properties where x.PropertyType.ToString() != "SynapseCore.Database.LabelBag" select x)
            {
                if (!bags.ContainsKey(pi.Name))
                {
                    EntityFieldType FieldType = ((EntityFieldType[])pi.GetCustomAttributes(typeof(EntityFieldType), true)).SingleOrDefault();

                    uc_Field field;
                    if (FieldType != null)
                    {
                        field = new uc_Field(FieldType);
                    }
                    else
                    {
                        field = new uc_Field();
                    }
                    field.FieldName   = pi.Name;
                    field.DisplayName = SynapseForm.GetLabel(_tableName.ToUpperInvariant() + "." + pi.Name.ToUpperInvariant());
                    object value = pi.GetValue(SynapseObject, null);
                    if (value != null)
                    {
                        field.FieldValue = value;
                    }
                    if (pi.Name == _IDproperty)
                    {
                        field.Enabled = false;
                    }
                    flowLayoutPanel1.Controls.Add(field);
                }
            }
            flowLayoutPanel1.Controls.AddRange(labelBagControl.ToArray());
            if (_NewLabels)
            {
                SynapseObject.GetType().InvokeMember("save", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public, null, SynapseObject, null);
            }
        }