原创

事务处理案例

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://david.blog.csdn.net/article/details/6321031

    private bool SaveQuotation()
    {

        bool saveReault = false;
        Quotation quo = new Quotation();
        quo.Pricingcode = txtpricingcode.Text.Trim();
        if (quo.DocumentNoExist())
        {
            JScript.Alert("该报价单已报过价格!", this.Page);
            return false;
        }
        using (SqlConnection cn = new SqlConnection(SqlHelper.conn))
        {
            cn.Open();
            SqlTransaction transaction = cn.BeginTransaction();
          
            try
            {
                //插入单头
                string strInsert = string.Format("insert Quo_Standardcost(ClientNo,[Description],PartNo,Rate,Engineer,PricingCode,[Date])values('{0}','{1}','{2}',{3},'{4}','{5}',{6})", txtclientno.Text.Trim(), txtdescription.Text.Trim(), txtpartno.Text.Trim(), txtrate.Text.Trim(),Engineer, txtpricingcode.Text.Trim(), txtdate.Text.Trim() );
                string tt = strInsert;
                SqlHelper.ExecuteNonQuery(transaction, CommandType.Text, strInsert);       
                //插入单身
                for (int i = 0; i <= gvquotation.Rows.Count - 1; i++)
                {

                    string pricingcode = txtpricingcode.Text.Trim().Replace("&nbsp;", "");
                    string Description = gvquotation.Rows[i].Cells[0].Text.Trim().Replace("&nbsp;", ""); ;
                    string Item = gvquotation.Rows[i].Cells[1].Text.Trim().Replace("&nbsp;", ""); ;
                    string Spec = gvquotation.Rows[i].Cells[2].Text.Trim().Replace("&nbsp;", ""); ;
                    decimal Usage = Convert.ToDecimal(gvquotation.Rows[i].Cells[3].Text.Trim());
                    string Uint = gvquotation.Rows[i].Cells[4].Text.Trim().Replace("&nbsp;", ""); ;
                    decimal Currency = Convert.ToDecimal(gvquotation.Rows[i].Cells[3].Text.Trim());

                    string strInserdetail = string.Format("Insert Quo_Standardcostdetail(PricingCode,[Description],Item,Spec,Usage,Currency)values('{0}','{1}','{2}','{3}',{4},{5})",pricingcode,Description ,Item,Spec,Usage,Currency);
                    SqlHelper.ExecuteNonQuery(transaction, CommandType.Text, strInserdetail);
                    
                }
               transaction.Commit();
               saveReault = true;
            }
            catch (Exception e)
            {
                JScript.Alert("报价单发生错误:"+e.Message.ToString()+"请检查数据或者与管理员联系!", this.Page);
                transaction.Rollback();

            }
            finally
            {
                transaction = null;
            }
        }
        return saveReault;

    }

 

今天在做报价单的时候发现,需要做一个事务处理!

特地做了一个列子供大家 交流学习

 

 

文章最后发布于: 2011-04-13 17:03:00
展开阅读全文
0 个人打赏
私信求帮助

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 鲸 设计师: meimeiellie

分享到微信朋友圈

×

扫一扫,手机浏览