Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name">SqlLoadKey</param>
        /// <param name="dict"></param>
        /// <param name="tran"></param>
        /// <param name="connect"></param>
        public static void ExecuteProcedure(ProcedureItem pitem, DbTransaction tran = null, string connect = "")
        {
            var commd = Command(pitem.ProcedureName, tran, connect);

            commd.CommandType = CommandType.StoredProcedure;
            string paramstr = "(";

            foreach (var item in pitem.ParametersKeys)
            {
                var p     = pitem.Parameters[item];
                var param = commd.CreateParameter();
                param.ParameterName = p.ParameterName;
                param.Direction     = p.Direction;
                param.Value         = p.Value;
                param.DbType        = p.DataType;
                commd.Parameters.Add(param);
                paramstr += p.Value + ",";
            }
            //Debug.Write(paramstr.TrimEnd(',') + ")");
            commd.ExecuteNonQuery();
            if (tran == null)
            {
                commd.Connection.Close();
            }
            foreach (DbParameter item in commd.Parameters)
            {
                if (item.Direction != ParameterDirection.Input)
                {
                    pitem[item.ParameterName] = item.Value;
                }
            }
        }
Example #2
0
        /// <summary>
        /// 加载一个SQL脚本文件对象
        /// </summary>
        /// <param name="path">文件路径</param>
        /// <returns></returns>
        static bool Load(string path)
        {
            var xml = new XmlDocument();

            xml.Load(path);
            foreach (XmlNode item in xml.LastChild.ChildNodes)
            {
                if (item.Name.ToUpper() == "SQI")
                {
                    var id = item.Attributes["id"].Value;
                    Debug.WriteLine("SWSoft.Framework.SqlLoad -> [Sql][" + id + "]");
                    if (Items.ContainsKey(id))
                    {
                        //throw new Exception("已存在相同名称的脚本:" + id);
                    }
                    else
                    {
                        Items.Add(item.Attributes["id"].Value, item.InnerText);
                    }
                }
                else if (item.Name.ToUpper() == "PROC")
                {
                    var id = item.Attributes["id"].Value;
                    if (ProcItems.ContainsKey(id))
                    {
                        //throw new Exception("已存在相同名称的存储过程配置:" + id);
                    }
                    else
                    {
                        Debug.WriteLine("[Proc][" + id + "]");
                        var pitem = new ProcedureItem();
                        pitem.ProcedureName = item["name"].InnerText.ToUpper();
                        foreach (XmlNode paramnode in item.ChildNodes)
                        {
                            if (paramnode.Name.ToUpper() == "PARAM")
                            {
                                var p = new ProcedureParameter();
                                p.ParameterName = paramnode.Attributes["name"].Value.ToUpper();
                                p.DataType      = (DbType)Enum.Parse(typeof(DbType), paramnode.Attributes["type"].Value, true);
                                p.Direction     = (ParameterDirection)Enum.Parse(typeof(ParameterDirection), paramnode.Attributes["Direction"].Value, true);
                                pitem.AddParameter(p);
                            }
                        }
                        ProcItems.Add(id, pitem);
                    }
                }
            }
            return(true);
        }