示例#1
0
        GetColsAndValues(IObjectProxy proxy, System.Data.SqlClient.SqlTransaction trans, OperationType operationType)
        {
            Dictionary <String, object> result = new Dictionary <string, object>();
            List <string> temp = new List <string>();

            ///简单数据
            ///

            //当check为真是用来校验是否已经存在,这时
            foreach (var property in proxy.Model.Properties.Where(p =>

                                                                  p.IsArray == false
                                                                  &&
                                                                  (string.IsNullOrEmpty(p.DBName) == false || p.IsMultiMap == true)
                                                                  ))
            {
                if (temp.Contains(property.Name))
                {
                    //已经包含
                    continue;
                }
                else
                {
                    temp.Add(property.Name);
                }
                if (property.PropertyType == PropertyType.RadomDECS)
                {
                    //加密,加入

                    var enDic = EncryptionClass.GetEncryptionValus(property, proxy[property]);
                    foreach (var str in enDic.Keys)
                    {
                        result.Add(str, enDic[str]);
                    }
                }
                else if (property.PropertyType == PropertyType.MD5)
                {
                    result.Add(property.DBName, EncryptionClass.ToMD5((proxy[property] ?? "").ToString()).ToString());
                }
                else if (property.PropertyType == PropertyType.DateTime ||
                         property.PropertyType == PropertyType.Date ||
                         property.PropertyType == PropertyType.Time)
                {
                    //日期
                    if (property.AutoGenerationType == Data.Discription.ORM.GenerationType.OnInSert &&
                        (operationType == OperationType.Insert || IsExits(proxy) == false))
                    {
                        result.Add(property.DBName, DateTime.Now);
                    }
                    else if ((property.AutoGenerationType == Data.Discription.ORM.GenerationType.OnInsertAndUpate ||
                              property.AutoGenerationType == Data.Discription.ORM.GenerationType.OnUpdate) && (operationType == OperationType.Update))
                    {
                        result.Add(property.DBName, DateTime.Now);
                    }
                    else if ((property.AutoGenerationType == Data.Discription.ORM.GenerationType.OnInSert) &&
                             operationType != OperationType.Insert)
                    {
                        continue;
                    }
                    else
                    {
                        var    str = (proxy[property] ?? DateTime.Now).ToString();
                        object ob  = DBNull.Value;
                        if (String.IsNullOrEmpty(str))
                        {
                            ob = DBNull.Value;
                        }
                        else
                        {
                            DateTime fmt;
                            if (DateTime.TryParseExact(str.Replace('/', ' ').Replace(':', ' ').Replace(" ", ""), "yyyyMMddHHmmss", null, System.Globalization.DateTimeStyles.AssumeLocal, out fmt) == true)
                            {
                                ob = fmt;
                            }
                        }
                        result.Add(property.DBName, ob);
                    }
                }
                else if (property.AutoGenerationType == Data.Discription.ORM.GenerationType.OnInSert &&
                         operationType != OperationType.CheckIsExits && property.PropertyType != PropertyType.SerialNo)
                {
                    continue;
                }
                else if (property.PropertyType == PropertyType.Guid &&
                         (String.IsNullOrEmpty((proxy[property] ?? "").ToString()) == true ||
                          Guid.Parse((proxy[property] ?? "").ToString()) == Guid.Empty) &&
                         operationType != OperationType.CheckIsExits)
                {
                    proxy[property] = Guid.NewGuid();//.ToString();
                    result.Add(property.DBName, proxy[property]);
                }
                else


                if (property.PropertyType != PropertyType.BusinessObject)
                {
                    if (String.IsNullOrEmpty((property.DBName ?? "").Replace("[", "").Replace("]", "")) == false)
                    {
                        var valueOb = proxy[property];
                        if (valueOb is DateTime && (DateTime)valueOb == DateTime.MinValue)
                        {
                            result.Add(property.DBName, DBNull.Value);
                        }
                        else
                        {
                            result.Add(property.DBName, valueOb ?? "");
                        }
                    }
                }
                else
                {
                    var objValue = proxy[property];

                    IObjectProxy propertyProxy = proxy[property] as IObjectProxy;
                    if (propertyProxy != null)
                    {
                        if (propertyProxy.ID == null ||
                            (propertyProxy.ID is long && System.Convert.ToInt64(propertyProxy.ID) == 0) ||
                            (propertyProxy.ID is Guid && (Guid)propertyProxy.ID == Guid.Empty))
                        {
                            //???
                            if (operationType == OperationType.CheckIsExits)
                            {
                                return(null);
                            }
                            //不存在,先加到里面
                            bool chk = IsExits(propertyProxy, trans);
                            if (chk == false)
                            {
                                if (propertyProxy.IsSave != SaveType.Exists)
                                {
                                    if (trans != null)
                                    {
                                        Create(propertyProxy, trans);
                                    }
                                    else
                                    {
                                        Create(propertyProxy);
                                    }
                                }
                                else
                                {
                                    if (trans != null)
                                    {
                                        save(propertyProxy, trans);
                                    }
                                    else
                                    {
                                        save(propertyProxy);
                                    }
                                }
                            }
                        }
                        if (property.IsMultiMap)
                        {
                            foreach (var propertymaps in property.DBMaps)
                            {
                                result.Add(propertymaps.DBColName, propertyProxy[propertyProxy.Model.Properties.First(p =>
                                                                                                                      p.Name == propertymaps.PropertyName ||
                                                                                                                      p.PropertyName == propertymaps.PropertyName)] ?? "");
                            }
                        }
                        else
                        {
                            result.Add(property.DBName, propertyProxy.ID);
                        }
                    }
                    if (objValue != null)
                    {
                        result.Add(property.DBName, objValue);
                    }
                    else
                    {
                        if (property.IsMultiMap)
                        {
                            foreach (var propertymaps in property.DBMaps)
                            {
                                result.Add(propertymaps.DBColName, DBNull.Value);
                            }
                        }
                        else
                        {
                            result.Add(property.DBName, DBNull.Value);
                        }
                    }
                }
            }
            return(result);
        }