コード例 #1
0
ファイル: SqlRelator.cs プロジェクト: naushard/EclipsePOS
        private SqlCommand BuildCommandFromTypeMap(IRelatable relatee, ORMTypeMapping typeMap, string relationKey)
        {
            //	Logger.Write( MethodBase.GetCurrentMethod() );
            ORMCommandMap ocm = typeMap.GetMapByName(relationKey);

            if (ocm != null)
            {
                SqlCommand cmd = new SqlCommand(ocm.StoredProcedure, conn);
                cmd.CommandType = CommandType.StoredProcedure;
                foreach (object ob in ocm.PropertyMaps)
                {
                    ORMPropertyMap propMap  = (ORMPropertyMap)ob;
                    SqlParameter   newParam = CreateParameterFromPropertyMap(propMap);
                    if ((newParam.Direction == ParameterDirection.Input) ||
                        (newParam.Direction == ParameterDirection.InputOutput))
                    {
                        SetParameterValue(newParam, relatee, propMap.MemberName);
                    }
                    cmd.Parameters.Add(newParam);
                }
                return(cmd);
            }
            else
            {
                //ExceptionPolicy.HandleException( new NullReferenceException("No such command mapping: " + typeMap.FullName + ":" + relationKey), "Exception" );
            }
            return(null);
        }
コード例 #2
0
ファイル: SqlRelator.cs プロジェクト: naushard/EclipsePOS
        private void AssignOutputValuesToObject(SqlCommand cmd, IRelatable relatee, ORMTypeMapping typeMap, string relationKey)
        {
            //	Logger.Write( MethodBase.GetCurrentMethod() );
            ORMCommandMap ocm = typeMap.GetMapByName(relationKey);

            foreach (object ob in ocm.PropertyMaps)
            {
                ORMPropertyMap propMap = (ORMPropertyMap)ob;
                if ((propMap.DataDirection == ParameterDirection.Output) ||
                    (propMap.DataDirection == ParameterDirection.InputOutput))
                {
                    PropertyInfo prop;
                    Type         t = relatee.GetType();
                    prop = t.GetProperty(propMap.MemberName);
                    if (prop != null)
                    {
                        if (cmd.Parameters[propMap.Parameter].Value != DBNull.Value)
                        {
                            prop.SetValue(relatee, cmd.Parameters[propMap.Parameter].Value, null);
                        }
                    }
                    else
                    {
                        //	ExceptionPolicy.HandleException( new NullReferenceException(("Missing member " + t.FullName + "." + propMap.MemberName)), "Exception"  );
                    }
                }
            }
        }
コード例 #3
0
ファイル: ORMTypeMapping.cs プロジェクト: naushard/EclipsePOS
 public ORMCommandMap GetMapByName(string relationKey)
 {
     foreach (object ob in commandMappings)
     {
         ORMCommandMap ocm = (ORMCommandMap)ob;
         if (ocm.RelationKey.ToUpper() == relationKey.ToUpper())
         {
             return(ocm);
         }
     }
     return(null);
 }
コード例 #4
0
ファイル: ORMTypeMapping.cs プロジェクト: naushard/EclipsePOS
        public ORMTypeMapping(XmlNode typeMap)
        {
            commandMappings = new ArrayList();
            fullName        = typeMap.Attributes["fullname"].Value;

            // build command mappings
            XmlNodeList commandList = typeMap.SelectNodes("commandmap");

            foreach (XmlNode commandMap in commandList)
            {
                ORMCommandMap cmdMap = new ORMCommandMap(commandMap);
                commandMappings.Add(cmdMap);
            }
        }
コード例 #5
0
ファイル: SqlRelator.cs プロジェクト: naushard/EclipsePOS
        public override void Relate(IRelatable relatee, string relationKey)
        {
            //Logger.Write( MethodBase.GetCurrentMethod() );
            ORMTypeMapping typeMap = FetchTypeMap(relatee);
            ORMCommandMap  cmdMap  = typeMap.GetMapByName(relationKey);
            SqlCommand     cmd     = BuildCommandFromTypeMap(relatee, typeMap, relationKey);

            //Logger.Write(cmd.ToString());
            try
            {
                conn.Open();
                if (cmdMap.ReturnsMultiple)
                {
                    SqlDataAdapter da        = new SqlDataAdapter(cmd);
                    IRelatableSet  relateSet = (IRelatableSet)relatee;
                    da.Fill(relateSet.ResultSet);
                }
                else
                {
                    //	Logger.Write(cmd.CommandText);
                    //	Logger.Write(cmd.Parameters.ToString());
                    cmd.ExecuteNonQuery();
                }
                AssignOutputValuesToObject(cmd, relatee, typeMap, relationKey);
                //conn.Close();
            }
            catch (Exception e)
            {
                string b = e.ToString();
                MessageBox.Show(relationKey + "\\n" + e.ToString());
            }
            finally
            {
                conn.Close();
            }
        }