Exemplo n.º 1
0
        public string InsertMenu(IdentityMenu identity)
        {
            //Common syntax
            var conn   = new SqlConnection(_connectionString);
            var sqlCmd = @"Menu_Insert";

            //For parameters
            var parameters = new Dictionary <string, object>
            {
                { "@ParentId", identity.ParentId },
                { "@Area", identity.Area },
                { "@Name", identity.Name },
                { "@Title", identity.Title },
                { "@Desc", identity.Desc },
                { "@Action", identity.Action },
                { "@Controller", identity.Controller },
                { "@Visible", identity.Visible },
                { "@Authenticate", identity.Authenticate },
                { "@CssClass", identity.CssClass },
                { "@SortOrder", identity.SortOrder },
                { "@AbsoluteUri", identity.AbsoluteUri },
                { "@Active", identity.Active },
                { "@IconCss", identity.IconCss },
            };

            try
            {
                MsSqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, sqlCmd, parameters);
            }
            catch (Exception ex)
            {
                var strError = "Failed to execute Menu_Insert. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }

            return(string.Empty);
        }
Exemplo n.º 2
0
        public int ExecuteText(string connection_string, MsDatParameters db_params, params string[] command_texts)
        {
            var _result = 0;

            using (SqlConnection _sqlconn = new SqlConnection(connection_string))
            {
                _sqlconn.Open();
                SqlTransaction transaction = _sqlconn.BeginTransaction();

                try
                {
                    for (int i = 0; i < command_texts.Length; i++)
                    {
                        if (command_texts[i] != null && command_texts[i] != "")
                        {
                            MsSqlHelper.ExecuteNonQuery(transaction, CommandType.Text, command_texts[i], (SqlParameter[])db_params);
                            _result++;
                        }
                    }

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    _result = -1;

                    throw new Exception("ExecuteText", ex);
                }
                finally
                {
                    _sqlconn.Close();
                }
            }

            return(_result);
        }
Exemplo n.º 3
0
        public bool Update(IdentityProject identity)
        {
            var sqlCmd = @"Project_Update";

            var strNow = DateTime.Now.ToString("dd/mm/yyyy h:mm");

            var parameters = new Dictionary <string, object>
            {
                { @"Id", identity.Id },
                { @"Code", identity.Code },
                { @"ProjectCategoryId", identity.ProjectCategoryId },
                { @"CompanyId", identity.CompanyId },
                { @"Name", identity.Name },
                { @"ShortDescription", identity.ShortDescription },
                { @"Detail", identity.Detail },
                { @"BeginDate", identity.BeginDate },
                { @"FinishDate", identity.FinishDate },
                { @"CreatedBy", identity.CreatedBy },
                { @"CreatedDate", strNow },
                { @"Status", identity.Status },
            };

            try
            {
                using (var conn = new SqlConnection(_connectinString))
                {
                    MsSqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, sqlCmd, parameters);
                }
            }
            catch (Exception ex)
            {
                var strError = "Failed to execute Project_Update. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }

            return(true);
        }
Exemplo n.º 4
0
        public bool Delete(int Id)
        {
            var sqlCmd = @"Project_Delete";

            var parameters = new Dictionary <string, object>
            {
                { @"Id", Id }
            };

            try
            {
                using (var conn = new SqlConnection(_connectinString))
                {
                    MsSqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, sqlCmd, parameters);
                }
            }
            catch (Exception ex)
            {
                var strError = "Failed to execute Project_Delete. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }

            return(true);
        }
Exemplo n.º 5
0
        public static int ExecuteNonQuery(string cmdText)
        {
            int      re  = 0;
            DateTime dt1 = DateTime.Now;

            try
            {
                //SMSGLog.Error(cmdText);
                SqlErrMsg = "";
                re        = MsSqlHelper.ExecuteNonQuery(ConnectionstringLocalTransaction, CommandType.Text, cmdText, null);
                if ((DateTime.Now - dt1).TotalMilliseconds > 3000)
                {
                    SMSLog.Debug("SqlDBExec =>ExecuteNonQuery 耗时:" + (DateTime.Now - dt1).TotalMilliseconds + "毫秒,result=" + re + ",sql=" + cmdText);
                }
                return(re);
            }
            catch (SqlException ex)
            {
                SqlErrMsg = ex.Message;
                SMSLog.Error("SqlDBExec =>ExecuteNonQuery Exception:" + cmdText);
                SMSLog.Error("SqlDBExec =>ExecuteNonQuery Exception: ", ex.Message);
            }
            return(0);
        }
Exemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="connection_string"></param>
 /// <param name="stored_procedure_name"></param>
 /// <param name="args"></param>
 /// <returns></returns>
 public int ExecuteProc(string connection_string, string stored_procedure_name, params object[] args)
 {
     return(MsSqlHelper.ExecuteNonQuery(connection_string, stored_procedure_name, args));
 }
Exemplo n.º 7
0
 public int ExecuteText(string connection_string, string command_text, MsDatParameters db_params)
 {
     return(MsSqlHelper.ExecuteNonQuery(connection_string, CommandType.Text, command_text, (SqlParameter[])db_params));
 }
Exemplo n.º 8
0
 //-----------------------------------------------------------------------------------------------------------------------------
 /// ExecuteText
 //-----------------------------------------------------------------------------------------------------------------------------
 public int ExecuteText(string connection_string, string command_text)
 {
     return(MsSqlHelper.ExecuteNonQuery(connection_string, CommandType.Text, command_text));
 }