Commit() public abstract method

public abstract Commit ( ) : void
return void
Ejemplo n.º 1
0
        public bool DeleteProduct(int exchangeId, int productId)
        {
            bool result = false;

            using (System.Data.Common.DbConnection dbConnection = this.database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction    = dbConnection.BeginTransaction();
                System.Data.Common.DbCommand     sqlStringCommand = this.database.GetSqlStringCommand("delete from Hishop_PointExChange_Products where [exChangeId]= @exChangeId and [ProductId] = @ProductId ");
                this.database.AddInParameter(sqlStringCommand, "exChangeId", System.Data.DbType.Int32, exchangeId);
                this.database.AddInParameter(sqlStringCommand, "ProductId", System.Data.DbType.Int32, productId);
                System.Data.Common.DbCommand sqlStringCommand2 = this.database.GetSqlStringCommand("update Hishop_PointExChange_PointExChanges set ProductNumber=ProductNumber-1 where Id=@Id");
                this.database.AddInParameter(sqlStringCommand2, "Id", System.Data.DbType.Int32, exchangeId);
                try
                {
                    this.database.ExecuteNonQuery(sqlStringCommand, dbTransaction);
                    this.database.ExecuteNonQuery(sqlStringCommand2, dbTransaction);
                    dbTransaction.Commit();
                    result = true;
                }
                catch
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    if (dbTransaction.Connection != null)
                    {
                        dbConnection.Close();
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public bool DeleteProducts(int actId, string ProductIds)
        {
            bool result = false;

            using (System.Data.Common.DbConnection dbConnection = this.database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction     = dbConnection.BeginTransaction();
                System.Data.Common.DbCommand     sqlStringCommand  = this.database.GetSqlStringCommand(string.Format("Delete from Hishop_PointExChange_Products WHERE exChangeId ={0} and ProductId in ( {1} )", actId, ProductIds.ReplaceSingleQuoteMark()));
                System.Data.Common.DbCommand     sqlStringCommand2 = this.database.GetSqlStringCommand("update Hishop_PointExChange_PointExChanges set ProductNumber=ProductNumber-1 where Id=@Id");
                this.database.AddInParameter(sqlStringCommand2, "Id", System.Data.DbType.Int32, actId);
                try
                {
                    this.database.ExecuteNonQuery(sqlStringCommand, dbTransaction);
                    this.database.ExecuteNonQuery(sqlStringCommand2, dbTransaction);
                    dbTransaction.Commit();
                    result = true;
                }
                catch
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    if (dbTransaction.Connection != null)
                    {
                        dbConnection.Close();
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        public static bool UpdateVote(VoteInfo vote)
        {
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                VoteDao voteDao = new VoteDao();
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    if (!voteDao.UpdateVote(vote, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                    }
                    else
                    {
                        if (!voteDao.DeleteVoteItem(vote.VoteId, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = false;
                        }
                        else
                        {
                            int num = 0;
                            if (vote.VoteItems != null)
                            {
                                foreach (VoteItemInfo current in vote.VoteItems)
                                {
                                    current.VoteId    = vote.VoteId;
                                    current.ItemCount = 0;
                                    num += voteDao.CreateVoteItem(current, dbTransaction);
                                }
                                if (num < vote.VoteItems.Count)
                                {
                                    dbTransaction.Rollback();
                                    result = false;
                                    return(result);
                                }
                            }
                            dbTransaction.Commit();
                            result = true;
                        }
                    }
                }
                catch
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
Ejemplo n.º 4
0
 static void ConfirmOperation(DbTransaction transaction, string message)
 {
     if (Dialog.Warn(message)) {
         transaction.Commit();
         Program.Current.RefreshDatabase();
     } else
         transaction.Rollback();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// �ύ���ݿ�����
        /// </summary>
        /// <param name="tran">DbTransaction�������</param>
        public void CommitTransaction(DbTransaction tran)
        {
            if (tran == null)
            {
                throw new ArgumentNullException("tran");
            }

            tran.Commit();
        }
Ejemplo n.º 6
0
        public bool AddPO(PO po)
        {
            bool result = false;
            try
            {
                Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name);
                connection = db.CreateConnection();
                connection.Open();
                transaction = connection.BeginTransaction();

                DbCommand dbCommand = db.GetStoredProcCommand(Constant.SP_PO_Insert);

                db.AddInParameter(dbCommand, "@sPOCode", DbType.String, po.POCode);
                db.AddInParameter(dbCommand, "@mPOAmount", DbType.Currency, po.POAmount);
                db.AddInParameter(dbCommand, "@mBalanceAmount", DbType.Currency, po.BalanceAmount);
                db.AddInParameter(dbCommand, "@iPOCreatedUser", DbType.Int32, po.POCreatedUser);
                db.AddInParameter(dbCommand, "@iSupId", DbType.Int32, po.SupId);
                db.AddInParameter(dbCommand, "@dtPODate", DbType.DateTime, po.PODate);

                db.AddInParameter(dbCommand, "@iRequestedBy", DbType.Int32, po.RequestedBy.Value);
                db.AddInParameter(dbCommand, "@sPOComment", DbType.String, po.POComment);

                db.AddOutParameter(dbCommand, "@iPOId", DbType.Int32, 4);

                if (db.ExecuteNonQuery(dbCommand, transaction) > 0)
                {
                    Int32 newPOID = (Int32)db.GetParameterValue(dbCommand, "@iPOId");
                    if (newPOID > 0)
                    {
                        po.POId = newPOID;
                        if (this.UpdatePOItems(po, db, transaction))
                        {
                            transaction.Commit();
                            result = true;
                        }
                    }
                }

            }
            catch (System.Exception ex)
            {
                ex.Data.Add("BusinessLayerException", GetType().ToString() + Constant.Error_Seperator + "public bool AddPO(PO po)");
                transaction.Rollback();
                throw ex;
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }

            return result;
        }
Ejemplo n.º 7
0
        public bool AddPR(PurchaseReturns pr)
        {
            bool result = false;
            try
            {
                Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name);
                connection = db.CreateConnection();
                connection.Open();
                transaction = connection.BeginTransaction();

                DbCommand dbCommand = db.GetStoredProcCommand(Constant.SP_PR_Insert);

                db.AddInParameter(dbCommand, "@iGRNId", DbType.Int64, pr.GRNId);
                db.AddInParameter(dbCommand, "@iCreatedBy", DbType.Int32, pr.CreatedBy);
                db.AddInParameter(dbCommand, "@mTotalReturns", DbType.Currency, pr.TotalReturns);
                db.AddInParameter(dbCommand, "@sComment", DbType.String, pr.Comment);
                db.AddInParameter(dbCommand, "@dReturnDate", DbType.Date, pr.ReturnDate);

                db.AddOutParameter(dbCommand, "@iPRId", DbType.Int32, 4);
                db.AddOutParameter(dbCommand, "@sPRCode", DbType.String, 10);

                if (db.ExecuteNonQuery(dbCommand, transaction) > 0)
                {
                    Int32 newPRID = (Int32)db.GetParameterValue(dbCommand, "@iPRId");
                    string prCode = (string)db.GetParameterValue(dbCommand, "@sPRCode");
                    if (newPRID > 0)
                    {
                        pr.PRId = newPRID;
                        pr.PRCode = prCode;

                        if (this.UpdatePRItems(pr, db, transaction))
                        {
                            transaction.Commit();
                            result = true;
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                ex.Data.Add("BusinessLayerException", GetType().ToString() + Constant.Error_Seperator + "public bool AddPR(PurchaseReturns pr)");
                transaction.Rollback();
                throw ex;
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }

            return result;
        }
        public ActionResult DeleteOrder(int id)
        {
            try
            {
                db.Connection.Open();
                transaction = db.Connection.BeginTransaction();

                var resShipTo = (from i in db.shipTo
                                 where i.ID == id
                                 select i).FirstOrDefault();
                var resItCart = from i in db.itCart
                                where i.shipToID == id
                                select i;
                var resDB = from i in db.OrderDashBoards
                            where i.shipToID == id
                            select i;
                if (resShipTo.getOState.Descr.Contains("Создан заказ"))
                {

                    if (resDB != null)
                    {
                        foreach (var i in resDB)
                        {
                            db.DeleteObject(i);
                        }

                    }
                    if (resItCart != null)
                    {
                        foreach (var i in resItCart)
                        {
                            db.DeleteObject(i);
                        }

                    }
                    if (resShipTo != null)
                    {
                        db.DeleteObject(resShipTo);

                    }
                    db.SaveChanges();
                    transaction.Commit();
                }
            }
            catch
            {
                if (transaction != null)
                {
                    transaction.Rollback();
                }
            }
            return RedirectToAction("Index", new { parUser = User.Identity.Name });
        }
Ejemplo n.º 9
0
        public bool AddGetPass(GetPass getPass)
        {
            bool result = false;
            try
            {
                Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name);

                connection = db.CreateConnection();
                connection.Open();

                transaction = connection.BeginTransaction();

                DbCommand cmd = db.GetStoredProcCommand(Constant.SP_GetPass_Add);

                db.AddInParameter(cmd, "@sGPCode", DbType.String, getPass.GPCode);
                db.AddInParameter(cmd, "@iInvoiceId", DbType.Int32, getPass.InvoiceId);
                db.AddInParameter(cmd, "@iCreatedBy", DbType.Int32, getPass.CreatedBy);

                db.AddOutParameter(cmd, "@biGPId", DbType.Int64, 8);

                if (db.ExecuteNonQuery(cmd, transaction) > 0)
                {
                    Int32 newGatePassID = Convert.ToInt32(db.GetParameterValue(cmd, "@biGPId"));

                    if (newGatePassID > 0)
                    {
                        getPass.GPId = newGatePassID;
                        if (this.UpdateGetPassDetails(getPass, db, transaction))
                        {
                            transaction.Commit();
                            result = true;
                        }
                    }
                }

            }
            catch (System.Exception ex)
            {
                transaction.Rollback();
                result = false;
                throw ex;
            }

            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            return result;
        }
Ejemplo n.º 10
0
        public static bool UpdateGroupBuy(GroupBuyInfo groupBuy)
        {
            Globals.EntityCoding(groupBuy, true);
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    GroupBuyDao groupBuyDao = new GroupBuyDao();
                    if (!groupBuyDao.UpdateGroupBuy(groupBuy, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                    }
                    else
                    {
                        if (!groupBuyDao.DeleteGroupBuyCondition(groupBuy.GroupBuyId, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = false;
                        }
                        else
                        {
                            if (!groupBuyDao.AddGroupBuyCondition(groupBuy.GroupBuyId, groupBuy.GroupBuyConditions, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = false;
                            }
                            else
                            {
                                dbTransaction.Commit();
                                result = true;
                            }
                        }
                    }
                }
                catch (Exception var_4_99)
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
Ejemplo n.º 11
0
        public static bool UpdateLineItem(string string_0, OrderInfo order, int quantity)
        {
            ManagerHelper.CheckPrivilege(Privilege.EditOrders);
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;
            bool     flag;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    SalesProvider salesProvider = SalesProvider.Instance();
                    order.LineItems[string_0].Quantity          = quantity;
                    order.LineItems[string_0].ShipmentQuantity  = quantity;
                    order.LineItems[string_0].ItemAdjustedPrice = order.LineItems[string_0].ItemListPrice;
                    if (!salesProvider.UpdateLineItem(order.OrderId, order.LineItems[string_0], dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                        return(result);
                    }
                    if (!salesProvider.UpdateOrderAmount(order, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                        return(result);
                    }
                    dbTransaction.Commit();
                    flag = true;
                }
                catch (Exception)
                {
                    dbTransaction.Rollback();
                    flag = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            if (flag)
            {
                EventLogs.WriteOperationLog(Privilege.EditOrders, string.Format(CultureInfo.InvariantCulture, "修改了订单号为\"{0}\"的订单商品数量", new object[]
                {
                    order.OrderId
                }));
            }
            result = flag;
            return(result);
        }
Ejemplo n.º 12
0
        public void Add(Order order)
        {
            owner = GetOwner();
            vendor = GetVendor(order.VendorID);

            using (cn = dbContext.Database.Connection)
            {
                try
                {
                    cn.Open();
                    tran = cn.BeginTransaction();
                    DbCommand cmd = cn.CreateCommand();
                    cmd.Transaction = tran;
                    cmd.CommandText = @"INSERT INTO tblSO (SOCode, SODate, BranchId, CurrencyId, EmployeeId, VendorID, TermID, TaxID, SOGrossAmt, SONetAmt, StatusID, Operator, Computer, LastUpdate)
                      VALUES (@SOCode, @SODate, @BranchId, @CurrencyId, @EmployeeId, @VendorId, @TermId, 0, @SOGrossAmt, @SONetAmt, 0, @Operator, @Computer, @LastUpdate); SELECT IDENT_CURRENT('tblSO');";

                    cmd.Parameters.Add(new SqlParameter("@SOCode", order.SOCode));
                    cmd.Parameters.Add(new SqlParameter("@SODate", order.SODate));
                    cmd.Parameters.Add(new SqlParameter("@BranchId", order.BranchID));
                    cmd.Parameters.Add(new SqlParameter("@CurrencyId", order.CurrencyId));
                    cmd.Parameters.Add(new SqlParameter("@EmployeeId", owner.EmployeeId));
                    cmd.Parameters.Add(new SqlParameter("@VendorId", vendor.Id));
                    cmd.Parameters.Add(new SqlParameter("@TermId", owner.DefTerm));
                    cmd.Parameters.Add(new SqlParameter("@SOGrossAmt", order.SOGrossAmt));
                    cmd.Parameters.Add(new SqlParameter("@SONetAmt", order.SONetAmt));
                    cmd.Parameters.Add(new SqlParameter("@Operator", order.Username));
                    cmd.Parameters.Add(new SqlParameter("@Computer", System.Environment.MachineName));
                    cmd.Parameters.Add(new SqlParameter("@LastUpdate", DateTime.Now));

                    soId = Convert.ToInt32(cmd.ExecuteScalar());

                    foreach (OrderItem item in order.Items)
                    {
                        AddOrderItem(item);
                    }

                    tran.Commit();
                }
                catch (Exception ex)
                {
                    if (tran != null)
                        tran.Rollback();

                    throw ex;
                }
                finally
                {
                    cn.Close();
                }
            }
        }
Ejemplo n.º 13
0
        public static bool UpdateBundlingProduct(BundlingInfo bundlingInfo)
        {
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    BundlingDao bundlingDao = new BundlingDao();
                    if (!bundlingDao.UpdateBundlingProduct(bundlingInfo, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                    }
                    else
                    {
                        if (!bundlingDao.DeleteBundlingByID(bundlingInfo.BundlingID, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = false;
                        }
                        else
                        {
                            if (!bundlingDao.AddBundlingProductItems(bundlingInfo.BundlingID, bundlingInfo.BundlingItemInfos, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = false;
                            }
                            else
                            {
                                dbTransaction.Commit();
                                result = true;
                            }
                        }
                    }
                }
                catch (Exception var_4_91)
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Creates the cheque book and saves the cheques in tha dataset dsCheques property
        /// </summary>
        /// <param name="chqBook"></param>
        /// <returns></returns>
        public bool Create(ChequeBook chqBook)
        {
            bool success = true;
            try
            {
                Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name);
                connection = db.CreateConnection();
                connection.Open();
                transaction = connection.BeginTransaction();

                DbCommand dbCommand = db.GetStoredProcCommand(Constant.SP_Cheque_Insert);

                db.AddInParameter(dbCommand, "@iNoOfCheques", DbType.Int32, chqBook.NoOfCheques);
                db.AddInParameter(dbCommand, "@biFirstChqNo", DbType.Int64, chqBook.FirstChqNo);
                db.AddInParameter(dbCommand, "@biLastChqNo", DbType.Int64, chqBook.LastChqNo);
                db.AddInParameter(dbCommand, "@iCreatedBy", DbType.Int32, chqBook.CreatedBy);
                db.AddInParameter(dbCommand, "@sBankName", DbType.String, chqBook.BankName);
                db.AddInParameter(dbCommand, "@sBankBranch", DbType.String, chqBook.BankBranch);

                db.AddOutParameter(dbCommand, "@iChqBookId", DbType.Int32, 4);

                if (db.ExecuteNonQuery(dbCommand, transaction) > 0)
                {
                    Int32 newChqBookId = Convert.ToInt32(db.GetParameterValue(dbCommand, "@iChqBookId"));
                    if (newChqBookId > 0)
                    {
                        chqBook.ChqBookId = newChqBookId;
                        if (this.UpdateCheques(chqBook, db, transaction))
                        {
                            transaction.Commit();
                            success = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                success = false;
                transaction.Rollback();
                ex.Data.Add("BusinessLayerException", GetType().ToString() + Constant.Error_Seperator + "public bool Create(ChequeBook chqBook)");
                throw ex;
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            return success;
        }
Ejemplo n.º 15
0
 /// <summary>
 /// 保存设备信息
 /// </summary>
 /// <returns></returns>
 public bool SaveDeviceInfomation(Device device, PointInfo points, LogConfig log, List <AlarmConfig> alarm, List <DigitalSignature> ds)
 {
     using (System.Data.SQLite.SQLiteConnection conn = SQLiteHelper.SQLiteHelper.CreateConn())
     {
         PointTempBLL        _point   = new PointTempBLL();
         LogConfigBLL        _log     = new LogConfigBLL();
         AlarmConfigBLL      _alarm   = new AlarmConfigBLL();
         ReportEditorBLL     _report  = new ReportEditorBLL();
         DigitalSignatureBLL _digital = new DigitalSignatureBLL();
         if (conn.State != System.Data.ConnectionState.Open)
         {
             conn.Open();
         }
         System.Data.Common.DbTransaction tran = conn.BeginTransaction();
         try
         {
             //保存设备信息
             if (InsertDevice(device, tran) &&
                 //保存温度点信息
                 _point.InsertPoint(points, tran) &&
                 //保存log信息
                 _log.InsertLogConfig(log, tran) &&
                 //保存alarm信息
                 _alarm.InsertAlarmConfig(alarm, tran) &&
                 _digital.InsertDigitalSignature(ds, tran)
                 )
             {
                 tran.Commit();
             }
             else
             {
                 tran.Rollback();
             }
         }
         catch (Exception ex)
         {
             tran.Rollback();
             conn.Close();
             _tracing.Error(ex, "save data to db failed!");
             return(false);
         }
         finally
         {
             if (conn.State == ConnectionState.Open)
             {
                 conn.Close();
             }
         }
     }
     return(true);
 }
Ejemplo n.º 16
0
        public static bool AddSiteSettings(SiteSettings siteSettings, int requestId, int siteQty)
        {
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    DistributorProvider distributorProvider = DistributorProvider.Instance();
                    if (!distributorProvider.AcceptSiteRequest(siteQty, requestId, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                    }
                    else
                    {
                        if (!distributorProvider.AddSiteSettings(siteSettings, requestId, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = false;
                        }
                        else
                        {
                            if (!DistributorProvider.Instance().AddInitData(siteSettings.UserId.Value, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = false;
                            }
                            else
                            {
                                dbTransaction.Commit();
                                result = true;
                            }
                        }
                    }
                }
                catch
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
Ejemplo n.º 17
0
        public static bool UpdateGroupBuy(GroupBuyInfo groupBuy)
        {
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    if (!SubsitePromotionsProvider.Instance().UpdateGroupBuy(groupBuy, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                    }
                    else
                    {
                        if (!SubsitePromotionsProvider.Instance().DeleteGroupBuyCondition(groupBuy.GroupBuyId, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = false;
                        }
                        else
                        {
                            if (!SubsitePromotionsProvider.Instance().AddGroupBuyCondition(groupBuy.GroupBuyId, groupBuy.GroupBuyConditions, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = false;
                            }
                            else
                            {
                                dbTransaction.Commit();
                                result = true;
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
Ejemplo n.º 18
0
        public static bool ClearOrderGifts(OrderInfo order)
        {
            ManagerHelper.CheckPrivilege(Privilege.EditOrders);
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;
            bool     flag;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    SalesProvider salesProvider = SalesProvider.Instance();
                    order.Gifts.Clear();
                    if (!salesProvider.ClearOrderGifts(order.OrderId, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                        return(result);
                    }
                    if (!salesProvider.UpdateOrderAmount(order, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                        return(result);
                    }
                    dbTransaction.Commit();
                    flag = true;
                }
                catch
                {
                    dbTransaction.Rollback();
                    flag = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            if (flag)
            {
                EventLogs.WriteOperationLog(Privilege.EditOrders, string.Format(CultureInfo.InvariantCulture, "清空了订单号为\"{0}\"的订单礼品", new object[]
                {
                    order.OrderId
                }));
            }
            result = flag;
            return(result);
        }
Ejemplo n.º 19
0
        public static bool DeleteOrderGift(OrderInfo order, int giftId)
        {
            ManagerHelper.CheckPrivilege(Privilege.EditOrders);
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    SalesProvider salesProvider = SalesProvider.Instance();
                    OrderGiftInfo orderGift     = salesProvider.GetOrderGift(giftId, order.OrderId);
                    order.Gifts.Remove(orderGift);
                    if (!salesProvider.DeleteOrderGift(order.OrderId, orderGift.GiftId, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                    }
                    else
                    {
                        if (!salesProvider.UpdateOrderAmount(order, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = false;
                        }
                        else
                        {
                            dbTransaction.Commit();
                            EventLogs.WriteOperationLog(Privilege.EditOrders, string.Format(CultureInfo.InvariantCulture, "删除了订单号为\"{0}\"的订单礼品", new object[]
                            {
                                order.OrderId
                            }));
                            result = true;
                        }
                    }
                }
                catch
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
Ejemplo n.º 20
0
        public bool AddGroups(Group group)
        {
            bool result = false;
            try
            {
                Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name);
                connection = db.CreateConnection();
                connection.Open();

                transaction = connection.BeginTransaction();

                DbCommand dbCommand = db.GetStoredProcCommand(Constant.SP_Groups_Insert);

                db.AddInParameter(dbCommand, "@sGroupCode", DbType.String, group.GroupCode);
                db.AddInParameter(dbCommand, "@sGroupName", DbType.String, group.GroupName);
                db.AddInParameter(dbCommand, "@sDescription", DbType.String, group.Description);
                db.AddInParameter(dbCommand, "@tiItemCount", DbType.Int16, group.ItemCount);
                db.AddInParameter(dbCommand, "@bIsActive", DbType.Boolean, group.IsActive);

                db.AddOutParameter(dbCommand, "@tiGroupId", DbType.Int16, 4);

                if (db.ExecuteNonQuery(dbCommand, transaction) > 0)
                {
                    Int16 newGroupId = Convert.ToInt16(db.GetParameterValue(dbCommand, "@tiGroupId"));
                    if (newGroupId > 0)
                    {
                        group.GroupId = newGroupId;
                        if (this.UpdateGroupItems(group, db, transaction))
                        {
                            transaction.Commit();
                            result = true;
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            return result;
        }
Ejemplo n.º 21
0
        public bool AddItemTransfer(ItemTransfer itemTransfer)
        {
            bool result = false;
            try
            {
                Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name);
                connection = db.CreateConnection();
                connection.Open();

                transaction = connection.BeginTransaction();

                DbCommand dbCommand = db.GetStoredProcCommand(Constant.SP_Item_Transfer_Insert);

                db.AddInParameter(dbCommand, "@iInvoiceId", DbType.Int32, DBNull.Value);
                db.AddInParameter(dbCommand, "@iBranchFrom", DbType.Int32, itemTransfer.BranchFrom);
                db.AddInParameter(dbCommand, "@iBranchTo", DbType.Int32, itemTransfer.BranchTo);
                db.AddInParameter(dbCommand, "@iTransferQty", DbType.Int32, itemTransfer.TransferQty);
                db.AddInParameter(dbCommand, "@iTransferBy", DbType.Int32, itemTransfer.TransferBy);

                db.AddOutParameter(dbCommand, "@iTransferId", DbType.Int32, 4);

                if (db.ExecuteNonQuery(dbCommand, transaction) > 0)
                {
                    Int32 newTransferID = Convert.ToInt32(db.GetParameterValue(dbCommand, "@iTransferId"));
                    if (newTransferID > 0)
                    {
                        itemTransfer.TransferId = newTransferID;
                        if (this.AddItemTransferInvoice(itemTransfer, db, transaction))
                        {
                            transaction.Commit();
                            result = true;
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            return result;
        }
Ejemplo n.º 22
0
 public void CommitTransaction()
 {
     try
     {
         trans.Commit();
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         CloseConnection();
     }
 }
Ejemplo n.º 23
0
        public bool DeleteDeviceInformation(List <Device> device, List <PointInfo> points, List <LogConfig> log, List <AlarmConfig> alarm, List <DigitalSignature> digital)
        {
            //if(_digital.IsExist()
            using (System.Data.SQLite.SQLiteConnection conn = SQLiteHelper.SQLiteHelper.CreateConn())
            {
                PointTempBLL        _point     = new PointTempBLL();
                LogConfigBLL        _log       = new LogConfigBLL();
                AlarmConfigBLL      _alarm     = new AlarmConfigBLL();
                DigitalSignatureBLL _digital   = new DigitalSignatureBLL();
                ReportEditorBLL     _reportBll = new ReportEditorBLL();
                if (conn.State != System.Data.ConnectionState.Open)
                {
                    conn.Open();
                }
                System.Data.Common.DbTransaction tran = conn.BeginTransaction();
                try
                {
                    //删除设备信息
                    DeleteDevice(device, tran);
                    ////删除温度点信息
                    _point.DeletePointInfo(points, tran);
                    ////删除log信息
                    _log.DeleteLogConfig(log, tran);
                    ////删除alarm信息
                    _alarm.DeleteAlarmConfig(alarm, tran);
                    device.ForEach(p => _reportBll.DeleteReportEditorBySnTn(p.SerialNum, p.TripNum, tran));

                    _digital.DeleteDigitalSignature(digital, tran);
                    tran.Commit();
                }
                catch (Exception ex)
                {
                    _tracing.Error(ex, "delete the device info failed");
                    tran.Rollback();
                    conn.Close();
                    return(false);
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 24
0
 /// <summary>
 /// 执行更改命令,返回处理是否成功
 /// </summary>
 /// <param name="cmd">命令</param>
 /// <param name="_transaction">事务</param>
 /// <param name="submitaction">是否提交事务</param>
 /// <returns></returns>
 public bool ExeCuteCmd(SQLiteCommand cmd, DbTransaction _transaction, bool submitaction)
 {
     bool bolSucced = true;
     try
     {
         int _RecordRows = cmd.ExecuteNonQuery();
     }
     catch
     {
         bolSucced = false;
     }
     if (submitaction)
     {
         _transaction.Commit();
     }
     return bolSucced;
 }
Ejemplo n.º 25
0
        public static bool UpdateAdjustCommssions(string orderId, string itemid, decimal adjustcommssion)
        {
            bool     flag     = false;
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    OrderInfo orderInfo = OrderHelper.GetOrderInfo(orderId);
                    if (orderInfo == null)
                    {
                        result = false;
                        return(result);
                    }
                    LineItemInfo lineItemInfo = orderInfo.LineItems[itemid];
                    lineItemInfo.ItemAdjustedCommssion = adjustcommssion;
                    if (!new LineItemDao().UpdateLineItem(orderId, lineItemInfo, dbTransaction))
                    {
                        dbTransaction.Rollback();
                    }
                    if (!new OrderDao().UpdateOrder(orderInfo, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                        return(result);
                    }
                    dbTransaction.Commit();
                    flag = true;
                }
                catch (Exception var_6_9F)
                {
                    dbTransaction.Rollback();
                }
                finally
                {
                    dbConnection.Close();
                }
                result = flag;
            }
            return(result);
        }
Ejemplo n.º 26
0
        public bool UpdateDiscountStatus(int Id, DiscountStatus status)
        {
            bool result = false;

            using (System.Data.Common.DbConnection dbConnection = this.database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction    = dbConnection.BeginTransaction();
                System.Data.Common.DbCommand     sqlStringCommand = this.database.GetSqlStringCommand("update Hishop_LimitedTimeDiscount set Status=@Status WHERE LimitedTimeDiscountId = @Id");
                this.database.AddInParameter(sqlStringCommand, "Id", System.Data.DbType.Int32, Id);
                this.database.AddInParameter(sqlStringCommand, "Status", System.Data.DbType.Int32, (int)status);
                System.Data.Common.DbCommand sqlStringCommand2;
                if (DiscountStatus.Delete == status)
                {
                    sqlStringCommand2 = this.database.GetSqlStringCommand("delete Hishop_LimitedTimeDiscountProduct WHERE LimitedTimeDiscountId = @Id");
                    this.database.AddInParameter(sqlStringCommand2, "Id", System.Data.DbType.Int32, Id);
                }
                else
                {
                    sqlStringCommand2 = this.database.GetSqlStringCommand("update Hishop_LimitedTimeDiscountProduct set Status=@Status WHERE LimitedTimeDiscountId = @Id");
                    this.database.AddInParameter(sqlStringCommand2, "Id", System.Data.DbType.Int32, Id);
                    this.database.AddInParameter(sqlStringCommand2, "Status", System.Data.DbType.Int32, (int)status);
                }
                try
                {
                    this.database.ExecuteNonQuery(sqlStringCommand, dbTransaction);
                    this.database.ExecuteNonQuery(sqlStringCommand2, dbTransaction);
                    dbTransaction.Commit();
                    result = true;
                }
                catch
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    if (dbTransaction.Connection != null)
                    {
                        dbConnection.Close();
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 27
0
        public bool AddBrands(Brand brand)
        {
            bool result = false;
            try
            {
                Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name);
                connection = db.CreateConnection();
                connection.Open();

                transaction = connection.BeginTransaction();

                DbCommand dbCommand = db.GetStoredProcCommand(Constant.SP_Brands_Insert);

                db.AddInParameter(dbCommand, "@sBrandName", DbType.String, brand.BrandName);

                db.AddOutParameter(dbCommand, "@iBrandId", DbType.Int32, 4);

                if (db.ExecuteNonQuery(dbCommand, transaction) > 0)
                {
                    Int32 newBrandID = Convert.ToInt32(db.GetParameterValue(dbCommand, "@iBrandId"));
                    if (newBrandID > 0)
                    {
                        brand.BrandId = newBrandID;
                        if (this.UpdateBrandCategories(brand, db, transaction))
                        {
                            transaction.Commit();
                            result = true;
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            return result;
        }
Ejemplo n.º 28
0
        public static int AddPromotion(PromotionInfo promotion)
        {
            Database database = DatabaseFactory.CreateDatabase();
            int      result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    PromotionDao promotionDao = new PromotionDao();
                    int          num          = promotionDao.AddPromotion(promotion, dbTransaction);
                    if (num <= 0)
                    {
                        dbTransaction.Rollback();
                        result = -1;
                    }
                    else
                    {
                        if (!promotionDao.AddPromotionMemberGrades(num, promotion.MemberGradeIds, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = -2;
                        }
                        else
                        {
                            dbTransaction.Commit();
                            result = num;
                        }
                    }
                }
                catch (Exception var_5_76)
                {
                    dbTransaction.Rollback();
                    result = 0;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
Ejemplo n.º 29
0
        public static bool AddBundlingProduct(BundlingInfo bundlingInfo)
        {
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    int num = PromotionsProvider.Instance().AddBundlingProduct(bundlingInfo, dbTransaction);
                    if (num <= 0)
                    {
                        dbTransaction.Rollback();
                        result = false;
                    }
                    else
                    {
                        if (!PromotionsProvider.Instance().AddBundlingProductItems(num, bundlingInfo.BundlingItemInfos, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = false;
                        }
                        else
                        {
                            dbTransaction.Commit();
                            result = true;
                        }
                    }
                }
                catch (Exception)
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
Ejemplo n.º 30
0
        public static Boolean delFeeByPatientId(string patient_id,string admiss_times,string charge_code)
        {
            DbConnection con = db.open();
            command = con.CreateCommand();
            trans = con.BeginTransaction();
            command.Transaction = trans;
            try {
                            sql = string.Format("insert into zy_detail_charge_zzdelete(patient_id,admiss_times,ledger_sn,detail_sn,occ_time,confirm_time,happen_date,charge_code,bill_item_code,audit_code,orig_price,charge_price,charge_amount,charge_group,apply_opera,confirm_opera,charge_status,infant_flag,self_flag,separate_flag,suprice_flag,drug_flag,emergency_flag,ope_flag,apply_status,pay_self,serial,ward_sn,dept_sn,order_no,exec_unit,group_no,page_no,page_type,report_date,adt_dept_no,back_flag,orig_dept,orig_ward,cash_date,account_date,doctor_code,samp_id,occ_page_no,fit_flag,samp_barcode,samp_type,charge_fee,parent_detail_sn) select patient_id,admiss_times,ledger_sn,detail_sn,occ_time,confirm_time,happen_date,charge_code,bill_item_code,audit_code,orig_price,charge_price,charge_amount,charge_group,apply_opera,confirm_opera,charge_status,infant_flag,self_flag,separate_flag,suprice_flag,drug_flag,emergency_flag,ope_flag,apply_status,pay_self,serial,ward_sn,dept_sn,order_no,exec_unit,group_no,page_no,page_type,report_date,adt_dept_no,back_flag,orig_dept,orig_ward,cash_date,account_date,doctor_code,samp_id,occ_page_no,fit_flag,samp_barcode,samp_type,charge_fee,parent_detail_sn FROM view_zy_detail_charge_c   where patient_id ='{0}' and admiss_times = {1} and charge_code = '{2}' ", patient_id, admiss_times, charge_code);
                            //insert into zy_detail_charge_zzdelete select [patient_id] ,[admiss_times],[ledger_sn],[detail_sn],[occ_time],[confirm_time],[happen_date],[charge_code] ,[bill_item_code] ,[audit_code] ,[orig_price] ,[charge_price],[charge_amount],[charge_group] ,[apply_opera] ,[confirm_opera],[charge_status] ,[infant_flag] ,[self_flag],[separate_flag] ,[suprice_flag],[drug_flag] ,[emergency_flag],[ope_flag],[apply_status] ,[pay_self] ,[serial] ,[ward_sn],[dept_sn] ,[order_no] ,[exec_unit] ,[group_no] ,[page_no] ,[page_type],[report_date],[adt_dept_no] ,[back_flag],[orig_dept] ,[orig_ward],[cash_date] ,[account_date] ,[doctor_code] ,[samp_id] ,[occ_page_no],[fit_flag] ,[samp_barcode] ,[samp_type],[charge_fee] ,[parent_detail_sn] ,[exec_time],[exec_status],[charge_sort] from view_zy_detail_charge_c
                            if (db.ExecuteNonQueryByTrans(sql, null,command) > 0)
                            {
                                 sql = string.Format("delete from zy_detail_charge where patient_id ='{0}' and admiss_times ={1}  and charge_code ={2} ", patient_id, admiss_times, charge_code);
                                 if (db.ExecuteNonQueryByTrans(sql, null,command) > 0)
                                     isDelete = true;
                                 sql = string.Format("delete from zy_detail_charge_b where patient_id ='{0}' and admiss_times ={1}  and charge_code ={2} ", patient_id, admiss_times, charge_code);
                                 if (db.ExecuteNonQueryByTrans(sql, null,command)>0)
                                     isDelete = true;
                                 sql = string.Format("delete from zy_detail_charge_c where patient_id ='{0}' and admiss_times ={1}  and charge_code ={2} ", patient_id, admiss_times, charge_code);
                                 if (db.ExecuteNonQueryByTrans(sql, null,command) > 0)
                                     isDelete = true;
                            }
                            trans.Commit();

            }catch(Exception e)
            {
                try
                {
                    trans.Rollback();
                }
                catch (SqlException ex)
                {
                    if (con != null)
                        con.Close();
                    if (trans.Connection != null)
                    {
                        trans.Connection.Close();
                    }
                }
            }

            return isDelete;
        }
Ejemplo n.º 31
0
        public bool Delete(int Id)
        {
            bool result = false;

            using (System.Data.Common.DbConnection dbConnection = this.database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction    = dbConnection.BeginTransaction();
                System.Data.Common.DbCommand     sqlStringCommand = this.database.GetSqlStringCommand("DELETE FROM Hishop_Activities WHERE ActivitiesId = @Id");
                this.database.AddInParameter(sqlStringCommand, "Id", System.Data.DbType.Int32, Id);
                System.Data.Common.DbCommand sqlStringCommand2 = this.database.GetSqlStringCommand("DELETE FROM Hishop_Activities_Detail WHERE ActivitiesId = @Id");
                this.database.AddInParameter(sqlStringCommand2, "Id", System.Data.DbType.Int32, Id);
                System.Data.Common.DbCommand sqlStringCommand3 = this.database.GetSqlStringCommand("DELETE FROM Hishop_Activities_Product WHERE ActivitiesId = @Id");
                this.database.AddInParameter(sqlStringCommand3, "Id", System.Data.DbType.Int32, Id);
                try
                {
                    this.database.ExecuteNonQuery(sqlStringCommand, dbTransaction);
                    this.database.ExecuteNonQuery(sqlStringCommand2, dbTransaction);
                    this.database.ExecuteNonQuery(sqlStringCommand3, dbTransaction);
                    dbTransaction.Commit();
                    result = true;
                }
                catch
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    if (dbTransaction.Connection != null)
                    {
                        dbConnection.Close();
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 32
0
        internal static void CommitTransaction(DbTransaction dbTrans)
        {
            if (dbTrans == null)
            {
                throw new ArgumentNullException("dbTrans");
            }

            // Get transaction connection for closing before commit
            DbConnection dbConn = dbTrans.Connection;
        
            try
            {
                // Commit transaction
                dbTrans.Commit();
            }
            finally
            {
                // Close connection
                if (dbConn != null)
                {
                    dbConn.Close();
                }
            }
        }
Ejemplo n.º 33
0
        public bool InsertEmployee(FEPV_Employees_Data emp)
        {
            System.Data.Common.DbTransaction tran = gateFEPVOA.BeginTransaction();
            try
            {
                string[] Columns = new string[] { "[EmployeeID]", "[EmployeeName]", "[EmployeeName_Eng]", "[CostCenter]", "[CardNo]", "[State]", "[DepartmentName_EN]"
                                                  , "[DepartmentName_CN]", "[Email]", "[PositionName]", "[JoinDate]", "[Gender]", "[CompanyShortName]", "[CompanyFullName]", "[CompanyCode]"
                                                  , "[LastUpdateDate]", "[Workplace]", "[NumberOfUpdate]", "[Birthday]" };
                object[] Values = new object[] { emp.EmployeeID, emp.EmployeeName, emp.EmployeeName_Eng, emp.CostCenter, emp.CardNo, emp.State, emp.DepartmentName_EN
                                                 , emp.DepartmentName_CN, emp.Email, emp.PositionName, emp.JoinDate, emp.Gender, emp.CompanyShortName, emp.CompanyFullName, emp.CompanyCode
                                                 , emp.LastUpdateDate, emp.Workplace, emp.NumberOfUpdate, emp.Birthday };
                gateFEPVOA.DbHelper.Insert("FEPV_Employees_Data", Columns, Values, tran, "EmployeeID");
                tran.Commit();
                tran.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                tran.Rollback();
                throw new Exception(ex.Message);
            }

            return(true);
        }
Ejemplo n.º 34
0
        /// <summary>
        /// 执行多个存储过程
        /// </summary>
        /// <param name="args">存储过程列表</param>
        /// <returns></returns>
        public bool ExecuteNoQueryTranPro(List<CommandList> args)
        {
            bool bResult = false;
            try
            {
                Database db = GetDataBase();
                _cmd = db.DbProviderFactory.CreateCommand();
                _cmd.Connection = db.CreateConnection();
                _cmd.Connection.Open();
                _tran = _cmd.Connection.BeginTransaction();
                _cmd.Transaction = _tran;
                _cmd.CommandTimeout = TimeOut;

                foreach (CommandList command in args)
                {
                    _cmd.CommandType = command.Type;
                    _cmd.CommandText = command.strCommandText;
                    _cmd.Parameters.Clear();
                    if (null != command.Params)
                    {
                        _cmd.Parameters.AddRange(command.Params);
                    }
                    db.ExecuteNonQuery(_cmd, _tran);
                }

                _tran.Commit();
                bResult = true;
            }
            catch (Exception ex)
            {
                if(null != _tran)
                {
                    _tran.Rollback();
                }
                throw ex;
            }
            finally
            {
                Dispose();
            }
            return bResult;
        }
Ejemplo n.º 35
0
        /// <summary>
        /// 执行多条SQL脚本
        /// </summary>
        /// <param name="strCmdTexts"></param>
        /// <returns></returns>
        public bool ExecuteNoQueryTran(List<string> strCmdTexts)
        {
            bool bResult = false;
            try
            {
                Database db = GetDataBase();
                _cmd = db.DbProviderFactory.CreateCommand();
                _cmd.Connection = db.CreateConnection();
                _cmd.Connection.Open();
                _tran = _cmd.Connection.BeginTransaction();
                _cmd.CommandTimeout = TimeOut;
                _cmd.CommandType = CommandType.Text;

                foreach (string strCommandText in strCmdTexts)
                {
                    _cmd.CommandText = strCommandText;
                    db.ExecuteNonQuery(_cmd, _tran);
                }

                _tran.Commit();
                bResult = true;
            }
            catch (Exception ex)
            {
                if (null != _tran)
                {
                    _tran.Rollback();
                }
                throw ex;
            }
            finally
            {
                Dispose();
            }
            return bResult;
        }
Ejemplo n.º 36
0
        public bool UpdateItemsInBulk(DataSet dsItems)
        {
            bool result = false;
            try
            {
                Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name);

                connection = db.CreateConnection();
                connection.Open();

                transaction = connection.BeginTransaction();

                //todo:Insert,Delete if required!

                DbCommand updCommand = db.GetStoredProcCommand(Constant.SP_Items_UpdateAllById);
                db.AddInParameter(updCommand, "@iItemId", DbType.Int32, "ItemId", DataRowVersion.Current);
                db.AddInParameter(updCommand, "@biQuantityInHand", DbType.String, "QuantityInHand", DataRowVersion.Current);
                db.AddInParameter(updCommand, "@bIsActive", DbType.Boolean, "IsActive", DataRowVersion.Current);

                db.UpdateDataSet(dsItems, dsItems.Tables[0].TableName, null, updCommand, null, transaction);
                result = true;
                transaction.Commit();

            }
            catch (System.Exception ex)
            {
                transaction.Rollback();
                result = false;
                throw ex;
            }

            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            return result;
        }
Ejemplo n.º 37
0
        public bool UpdateAllCustomers(DataSet dsCustomers)
        {
            bool result = false;
            try
            {
                Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name);

                connection = db.CreateConnection();
                connection.Open();

                transaction = connection.BeginTransaction();

                DbCommand updCommand = db.GetStoredProcCommand(Constant.SP_Customers_UpdateAll_ByID);
                db.AddInParameter(updCommand, "@iCustomerID", DbType.Int32, "CustomerID", DataRowVersion.Current);
                db.AddInParameter(updCommand, "@mCus_CreditTotal", DbType.Currency, "Cus_CreditTotal", DataRowVersion.Current);

                db.UpdateDataSet(dsCustomers, dsCustomers.Tables[0].TableName, null, updCommand, null, transaction);
                result = true;
                transaction.Commit();

            }
            catch (System.Exception ex)
            {
                transaction.Rollback();
                result = false;
                throw ex;
            }

            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            return result;
        }
Ejemplo n.º 38
0
        /// <summary>
        /// 执行并加入事务
        /// </summary>
        ///      
        public void Commit()
        {
            if (_multiSqls.Count > 0)
            {
                using (DbConnection currentConnet = DbHelper.CreateConnection())
                {
                    DbHelper.OpenCon(currentConnet);
                    DbCommand command = DbHelper.CreateCommand(currentConnet);
                    _currentTransaction = command.Connection.BeginTransaction(IsolationLevel.Serializable);
                    command.Transaction = _currentTransaction;
                    foreach (string item in _multiSqls)
                    {
                        command.Parameters.Clear();
                        command.CommandText = item ;
                        command.CommandType = CommandType.Text;
                        command.ExecuteNonQuery();
                    }
                    if (_currentTransaction != null)
                    {
                        _currentTransaction.Commit();
                        _currentTransaction.Dispose();
                        _currentTransaction = null;
                    }
                    DbHelper.CloseCon(currentConnet);
                }
            }
            else
            {
                using (DbConnection currentConnet = DbHelper.CreateConnection())
                {
                    DbHelper.OpenCon(currentConnet);
                    DbCommand command = DbHelper.CreateCommand(currentConnet);
                    _currentTransaction = command.Connection.BeginTransaction();
                    command.Transaction = _currentTransaction;
                    foreach (DataBaseAction item in _multiActions)
                    {
                        command.Parameters.Clear();
                        item.DbHelper.MyDbCommand = command;
                        command.CommandText = item.CreateSql(item.CurrentOperate);
                        foreach (DataParameter itemparmeters in item.Parameters)
                        {
                            DbParameter newParameter = command.CreateParameter();
                            newParameter.ParameterName = itemparmeters.ParameterName;
                            newParameter.Value = itemparmeters.Value;
                            newParameter.DbType = itemparmeters.DbType;
                            if (itemparmeters.Size > -1)
                            {
                                newParameter.Size = itemparmeters.Size;
                            }
                            newParameter.Direction = itemparmeters.Direction;
                            command.Parameters.Add(newParameter);

                        }
                        command.ExecuteNonQuery();
                    }
                    if (_currentTransaction != null)
                    {
                        _currentTransaction.Commit();
                        _currentTransaction.Dispose();
                        _currentTransaction = null;
                    }
                    DbHelper.CloseCon(currentConnet);
                }
            }
        }
Ejemplo n.º 39
0
 public void CommitTransaction(DbTransaction transaction)
 {
     transaction.Commit();
 }
Ejemplo n.º 40
0
        public static bool Insert(Order order, string executedBy)
        {
            bool rslt = false;

            try
            {
                Database db = DatabaseFactory.CreateDatabase(Constants.DBConnection);
                DbCommand cmd = db.GetStoredProcCommand(Constants.SP_Order_Insert);

                connection = db.CreateConnection();
                connection.Open();
                transaction = connection.BeginTransaction();

                db.AddInParameter(cmd, "CustomerID", DbType.Int32, order.CustomerID);
                db.AddInParameter(cmd, "BranchID", DbType.Int32, order.BranchID);
                db.AddInParameter(cmd, "OrderDate", DbType.DateTime, order.OrderDate);
                db.AddInParameter(cmd, "OrderStatusID", DbType.Int32, order.OrderStatusID);
                db.AddInParameter(cmd, "TotalValue", DbType.Decimal, order.TotalValue);
                db.AddInParameter(cmd, "IsPaid", DbType.Boolean, order.IsPaid);
                db.AddInParameter(cmd, "CreatedBy", DbType.Boolean, order.CreatedBy);

                db.AddOutParameter(cmd, "NewID", DbType.Int32, 4);

                db.ExecuteNonQuery(cmd, transaction);

                int newID = 0;
                int.TryParse(db.GetParameterValue(cmd, "NewID").ToString(), out newID);

                if (newID > 0)
                {
                    bool dtlInserted;
                    foreach (OrderDetail orDtl in order.OrderItems)
                    {
                        dtlInserted = InsertDetail(orDtl, transaction, executedBy);
                        if (dtlInserted == false)
                        {
                            throw new Exception("Failed to insert order detail/s");
                        }
                    }

                    transaction.Commit();
                    rslt = true;
                }
            }

            catch (Exception ex)
            {
                transaction.Rollback();
                rslt = false;
                throw ex;
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }

            return rslt;
        }
Ejemplo n.º 41
0
 /// <summary>
 /// 对连接执行 Transact-SQL 语句并返回受影响的行数
 /// </summary>
 /// <param name="CmdType">指定如何解释命令字符串</param>
 /// <param name="CmdText">Transact-SQL 语句</param>
 /// <param name="CmdParameters">SqlCommand 的参数</param>
 /// <param name="Transaction">Transact-SQL 事务</param>
 /// <returns>返回受影响的行数</returns>
 public int ExecuteNonQuery(CommandType CmdType, string CmdText, DbParameter[] CmdParameters, DbTransaction Transaction)
 {
     this.CreateCmd(CmdType, CmdText, CmdParameters, (SQLiteTransaction)Transaction);
     int num2 = 0;
     Transaction = Conn.BeginTransaction();//默认设置为开启事务 如果出现神马异常情况再改掉 云飞提供思路 在此表示感谢
     if (Transaction != null)
     {
         try
         {
             num2 = this.Cmd.ExecuteNonQuery();
             Transaction.Commit();
         }
         catch (Exception exception1)
         {
             Exception exception = exception1;
             Transaction.Rollback();
         }
     }
     else
     {
         num2 = this.Cmd.ExecuteNonQuery();
     }
     this.Close();
     this.Dispose();
     return num2;
 }
Ejemplo n.º 42
0
        /// <summary>
        ///     Handles the Click event of the _btnCreateRoom control.
        /// </summary>
        /// <param name = "sender">The source of the event.</param>
        /// <param name = "e">The <see cref = "System.EventArgs" /> instance containing the event data.</param>
        protected void _btnCreateRoom_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid) return;

            var db = new UrbanDataContext();

            //Verify All sections from user are valid
            var validationCheck = VerifyRequiredFieldsSelected();
            switch (validationCheck)
            {
                case -1:
                    {
                        WriteFeedBackMaster(FeedbackType.Warning, "Please fill in required fields");
                        return;
                    }
                case -2:
                    {
                        WriteFeedBackMaster(FeedbackType.Warning, "Building already exists with this address information");
                        return;
                    }
                case -3:
                    {
                        WriteFeedBackMaster(FeedbackType.Warning, "Room already exists for this building and room number");
                        return;
                    }
                case 1:
                    {
                        break;
                    }
            }

            try
            {
                db.Connection.Open();
                _transac = db.Connection.BeginTransaction();
                db.Transaction = _transac;

                //Building Creation
                var buildingCreateParams = GetBuildingCreateParams();

                var buidlingResult = BuildingUtilities.ProcessBuildingCreation(ref db, Cu.Id, buildingCreateParams);
                if (buidlingResult != -1)
                {
                    //Room Creation
                    var roomCreateParams = GetRoomCreateParams();
                    var roomResult = RoomUtilities.ProcessRoomCreation(ref db, buidlingResult, Cu.Id, AvailabilityList, roomCreateParams);
                    if (roomResult == -1)
                    {
                        WriteFeedBackMaster(FeedbackType.Warning, "Room already exists with this number for this building please select another.");
                        _transac.Rollback();
                    }
                    else
                    {
                        //_transac.Rollback();
                        _transac.Commit();
                        //Move every temp image to full image
                        foreach (var file in ImageList)
                        {
                            var filesTemp = Server.MapPath("~/FilesTemp");
                            var imageToCopy = Path.Combine(filesTemp, file.ImageUrl);
                            var files = Server.MapPath("~/Files");
                            var imagePathToCopy = Path.Combine(files, file.ImageUrl);

                            File.Copy(imageToCopy, imagePathToCopy);

                            var f = new Files
                                        {
                                            Extension = file.Extension,
                                            FilesName = file.FileName,
                                            FileSubType = "Image",
                                            ServerFileName = file.ImageUrl
                                        };
                            db.Files.InsertOnSubmit(f);
                            db.SubmitChanges();
                            var link = new RoomImageLink
                                           {
                                               ImageDescription = file.Description,
                                               Title = file.Title,
                                               RoomID = roomResult,
                                               FileID = f.Id
                                           };
                            db.RoomImageLink.InsertOnSubmit(link);
                            db.SubmitChanges();
                        }


                        RadAjaxManager.GetCurrent(Page).Redirect(String.Format("~/App/Pages/MyAccount.aspx?message={0}", ("Room " + _txtRoomNumber.Text + " created")));
                    }
                }
                else
                {
                    WriteFeedBackMaster(FeedbackType.Warning, "This address information already eixsts for a different user. Please modify and resubmit");
                    _transac.Rollback();
                }
            }
            catch (Exception)
            {
                if (_transac != null)
                    _transac.Rollback();
                throw;
            }
            finally
            {
                if (db.Connection.State == ConnectionState.Open)
                    db.Connection.Close();
            }
        }
Ejemplo n.º 43
0
 public static void CommitTransaction(DbTransaction dbt)
 {
     if (dbt == null)
     {
         return;
     }
     dbt.Commit();
     //string threadName = Thread.CurrentThread.Name;
     //if (threadName != null)
     //{
     //    transactionList.Remove(threadName);
     //}
 }
Ejemplo n.º 44
0
        public void DBT_End(DbTransaction DBT)
        {
            try
            {
                DBT.Commit();
            }
            catch (Exception ex)
            {

                if (DBT != null)
                {
                    //獨立呼叫Transcation失敗
                    DBT.Rollback();
                }

                throw ex;
            }
            finally
            {
                //獨立呼叫Transcation,關閉連線
                if (Conn.State == ConnectionState.Connecting)
                {
                    Conn.Close();
                }
            }
        }
Ejemplo n.º 45
0
        //完成交易
        public void CommitDBT(DbTransaction DBT)
        {
            try
            {
                DBT.Commit();
            }
            catch (Exception ex)
            {
                if (DBT != null)
                    DBT.Rollback();

                throw ex;
            }
            finally
            {
                if (Conn.State == ConnectionState.Connecting)
                {
                    Conn.Close();
                }
            }
        }
Ejemplo n.º 46
0
 public static void CommitTransaction(DbTransaction dbTransaction)
 {
     dbTransaction.Commit();
 }
Ejemplo n.º 47
0
 /// <summary>
 /// Commits the specified <see cref="DbTransaction"/>.
 /// </summary>
 /// <param name="ta">The <see cref="DbTransaction"/> to be committed.</param>
 public override void Commit(DbTransaction ta)
 {
     ta.Commit();
 }
Ejemplo n.º 48
0
        public bool UpdateVoucher(VoucherRecievable voucher)
        {
            bool result = false;
            try
            {
                Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name);
                connection = db.CreateConnection();
                connection.Open();

                transaction = connection.BeginTransaction();

                DbCommand cmd = db.GetStoredProcCommand(Constant.SP_Voucher_InsVoucher);

                db.AddInParameter(cmd, "@mPaymentAmount", DbType.Currency, voucher.PaymentAmount);
                db.AddInParameter(cmd, "@dtPaymentDate", DbType.DateTime, voucher.PaymentDate);
                db.AddInParameter(cmd, "@iPaymentTypeId", DbType.Int32, (int)voucher.PaymentTypeId);
                switch (voucher.PaymentTypeId)
                {
                    case Structures.PaymentTypes.CASH:
                        db.AddInParameter(cmd, "@sChequeNo", DbType.String, DBNull.Value);//null
                        db.AddInParameter(cmd, "@dtChequeDate", DbType.DateTime, DBNull.Value);//null
                        db.AddInParameter(cmd, "@sCardType", DbType.String, DBNull.Value);//null
                        db.AddInParameter(cmd, "@dCardCommisionRate", DbType.Decimal, DBNull.Value);
                        break;
                    case Structures.PaymentTypes.CHEQUE:
                        db.AddInParameter(cmd, "@sChequeNo", DbType.String, voucher.ChequeNo);
                        db.AddInParameter(cmd, "@dtChequeDate", DbType.DateTime, voucher.ChequeDate);
                        db.AddInParameter(cmd, "@sCardType", DbType.String, DBNull.Value);//null
                        db.AddInParameter(cmd, "@dCardCommisionRate", DbType.Decimal, DBNull.Value);//null
                        break;
                    case Structures.PaymentTypes.CREDIT_CARD:
                        db.AddInParameter(cmd, "@sChequeNo", DbType.String,voucher.ChequeNo);
                        db.AddInParameter(cmd, "@dtChequeDate", DbType.DateTime, DBNull.Value);//null
                        db.AddInParameter(cmd, "@sCardType", DbType.String, voucher.CardType);
                        db.AddInParameter(cmd, "@dCardCommisionRate", DbType.Decimal, voucher.CardCommisionRate);
                        break;
                    default:
                        break;
                }

                db.AddInParameter(cmd, "@sComment", DbType.String, voucher.Comment);
                db.AddInParameter(cmd, "@iCreatedBy", DbType.Int32, voucher.CreatedBy);
                db.AddInParameter(cmd, "@inewPaymentID", DbType.Int64, voucher.PaymentID);

                if (db.ExecuteNonQuery(cmd, transaction) > 0)
                {
                    Int64 newVoucherID = 0;
                    Int64.TryParse(db.GetParameterValue(cmd, "@inewPaymentID").ToString().Trim(), out newVoucherID);

                    if (newVoucherID > 0)
                    {
                        voucher.PaymentID = newVoucherID;
                        voucher.PaymentCode = db.GetParameterValue(cmd, "@snewPaymentID").ToString().Trim();

                        if (this.UpdateVoucherDetails(voucher, db, transaction))
                        {
                            transaction.Commit();
                            result = true;
                        }
                    }

                }
            }
            catch (System.Exception ex)
            {
                transaction.Rollback();
                result = false;
                throw ex;
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            return result;
        }
Ejemplo n.º 49
0
        /// <summary>
        /// Updates cheque details, update individual cheques
        /// </summary>
        /// <param name="chqBook"></param>
        /// <param name="db"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public bool UpdateCheques(ChequeBook chqBook)
        {
            bool result = false;

            Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name);
             DbTransaction transaction;
            connection = db.CreateConnection();
            connection.Open();
            transaction = connection.BeginTransaction();

            try
            {
                DbCommand insCommand = db.GetStoredProcCommand(Constant.SP_Cheque_InsertDetails);
                db.AddInParameter(insCommand, "@iChqBookId", DbType.Int32, chqBook.ChqBookId);
                db.AddInParameter(insCommand, "@tiChqStatusId", DbType.Int16, "ChqStatusId", DataRowVersion.Current);
                db.AddInParameter(insCommand, "@biChequeNo", DbType.Int64, "ChequeNo", DataRowVersion.Current);

                DbCommand updCommand = db.GetStoredProcCommand(Constant.SP_Cheque_UpdateDetails);
                db.AddInParameter(updCommand, "@iChqId", DbType.Int32, "ChqId", DataRowVersion.Current);
                db.AddInParameter(updCommand, "@mAmount", DbType.Currency, "Amount", DataRowVersion.Current);
                db.AddInParameter(updCommand, "@sComment", DbType.String, "Comment", DataRowVersion.Current);
                db.AddInParameter(updCommand, "@tiChqStatusId", DbType.Int16, "ChqStatusId", DataRowVersion.Current);
                db.AddInParameter(updCommand, "@iWrittenBy", DbType.Int32, "WrittenBy", DataRowVersion.Current);
                db.AddInParameter(updCommand, "@iModifiedBy", DbType.Int32, "ModifiedBy", DataRowVersion.Current);

                DbCommand delCommand = db.GetStoredProcCommand(Constant.SP_Cheque_DeleteDetails);
                db.AddInParameter(delCommand, "@iChqId", DbType.Int32, "ChqId", DataRowVersion.Current);

                int rowcount = 0;
                rowcount = db.UpdateDataSet(chqBook.DsCheques, chqBook.DsCheques.Tables[0].TableName, insCommand, updCommand, delCommand, transaction);
                if (rowcount > 0)
                {
                    result = true;
                    transaction.Commit();

                }
                else
                {
                    result = false;
                    transaction.Rollback();
                }

            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            return result;
        }