Пример #1
0
        public bool updateTran(VAN_OA.Model.EFrom.tb_QuotePrice model,
                               List <tb_QuotePrice_InvDetails> invsDetails, string invDetails_IDS)
        {
            using (SqlConnection conn = DBHelp.getConn())
            {
                conn.Open();
                SqlTransaction tan        = conn.BeginTransaction();
                SqlCommand     objCommand = conn.CreateCommand();
                objCommand.Transaction = tan;

                tb_QuotePrice_InvsService InvSer = new tb_QuotePrice_InvsService();

                tb_QuotePrice_InvDetailsService InvDetailSer = new tb_QuotePrice_InvDetailsService();
                try
                {
                    objCommand.Parameters.Clear();
                    if (model.IsYH)
                    {
                        model.Total = model.LastYH;
                    }
                    else
                    {
                        model.Total = invsDetails.Sum(t => t.Total) + model.LaborCost + model.EngineeringTax;
                    }

                    Update(model, objCommand);


                    #region 报价内容
                    for (int i = 0; i < invsDetails.Count; i++)
                    {
                        invsDetails[i].QuoteId = model.Id;
                        if (invsDetails[i].IfUpdate == true && invsDetails[i].Id != 0)
                        {
                            InvDetailSer.Update(invsDetails[i], objCommand);
                        }
                        else if (invsDetails[i].Id == 0)
                        {
                            InvDetailSer.Add(invsDetails[i], objCommand);
                        }
                    }
                    if (invDetails_IDS != "")
                    {
                        invDetails_IDS = invDetails_IDS.Substring(0, invDetails_IDS.Length - 1);
                        InvDetailSer.DeleteByIds(invDetails_IDS, objCommand);
                    }
                    #endregion


                    tan.Commit();
                }
                catch (Exception ex)
                {
                    tan.Rollback();
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
        public int addTran(VAN_OA.Model.EFrom.tb_QuotePrice model, List <tb_QuotePrice_InvDetails> invsDetails)
        {
            int id     = 0;
            int MainId = 0;

            using (SqlConnection conn = DBHelp.getConn())
            {
                conn.Open();
                SqlTransaction tan        = conn.BeginTransaction();
                SqlCommand     objCommand = conn.CreateCommand();
                objCommand.Transaction = tan;

                try
                {
                    objCommand.Parameters.Clear();
                    if (model.IsYH)
                    {
                        model.Total = model.LastYH;
                    }
                    else
                    {
                        model.Total = invsDetails.Sum(t => t.Total) + model.LaborCost + model.EngineeringTax;
                    }
                    id     = Add(model, objCommand);
                    MainId = id;



                    tb_QuotePrice_InvDetailsService InvDetailSer = new tb_QuotePrice_InvDetailsService();
                    for (int i = 0; i < invsDetails.Count; i++)
                    {
                        invsDetails[i].QuoteId = id;
                        InvDetailSer.Add(invsDetails[i], objCommand);
                    }
                    tan.Commit();
                }
                catch (Exception)
                {
                    tan.Rollback();
                    return(0);
                }
                return(id);
            }
        }