コード例 #1
0
        public int addTran(VAN_OA.Model.EFrom.TB_POOrder model, VAN_OA.Model.EFrom.tb_EForm eform, List <TB_POOrders> orders, List <TB_POCai> caiOrders, out int MainId)
        {
            int id = 0;

            MainId = 0;
            using (SqlConnection conn = DBHelp.getConn())
            {
                conn.Open();
                SqlTransaction tan        = conn.BeginTransaction();
                SqlCommand     objCommand = conn.CreateCommand();
                objCommand.Transaction = tan;
                TB_POOrdersService OrdersSer = new TB_POOrdersService();

                TB_POCaiService caiSer = new TB_POCaiService();
                try
                {
                    objCommand.Parameters.Clear();
                    tb_EFormService eformSer = new tb_EFormService();
                    string          proNo    = eformSer.GetAllE_No("TB_POOrder", objCommand);
                    model.ProNo = proNo;
                    eform.E_No  = proNo;


                    id     = Add(model, objCommand);
                    MainId = id;

                    eform.allE_id = id;
                    eformSer.Add(eform, objCommand);
                    for (int i = 0; i < orders.Count; i++)
                    {
                        orders[i].Id = id;

                        OrdersSer.Add(orders[i], objCommand);

                        TB_POCai cai = new TB_POCai();
                        cai.GuestName = orders[i].GuestName;
                        cai.Num       = orders[i].Num;
                        cai.InvName   = orders[i].InvName;
                        cai.Id        = id;
                        caiSer.Add(cai, objCommand);
                    }


                    //for (int i = 0; i < caiOrders.Count; i++)
                    //{
                    //    caiOrders[i].Id = id;

                    //    caiSer.Add(caiOrders[i], objCommand);


                    //}



                    tan.Commit();
                }
                catch (Exception)
                {
                    tan.Rollback();
                    return(0);
                }
                return(id);
            }
        }
コード例 #2
0
        public bool updateTran(VAN_OA.Model.EFrom.TB_POOrder model, VAN_OA.Model.EFrom.tb_EForm eform, tb_EForms forms, List <TB_POOrders> orders, string IDS,
                               List <TB_POCai> Cais, string CAI_IDS)
        {
            using (SqlConnection conn = DBHelp.getConn())
            {
                conn.Open();
                SqlTransaction tan        = conn.BeginTransaction();
                SqlCommand     objCommand = conn.CreateCommand();
                objCommand.Transaction = tan;

                TB_POOrdersService OrdersSer = new TB_POOrdersService();
                TB_POCaiService    CaiSer    = new TB_POCaiService();
                try
                {
                    objCommand.Parameters.Clear();
                    Update(model, objCommand);
                    tb_EFormService eformSer = new tb_EFormService();
                    eformSer.Update(eform, objCommand);
                    tb_EFormsService eformsSer = new tb_EFormsService();
                    eformsSer.Add(forms, objCommand);


                    for (int i = 0; i < orders.Count; i++)
                    {
                        orders[i].Id = model.Id;
                        //if (orders[i].IfUpdate == true && orders[i].Ids != 0)
                        //{

                        OrdersSer.Update(orders[i], objCommand);

                        //}
                        //else if (orders[i].Ids == 0)
                        //{
                        //    OrdersSer.Add(orders[i], objCommand);

                        //}
                    }
                    if (IDS != "")
                    {
                        IDS = IDS.Substring(0, IDS.Length - 1);
                        OrdersSer.DeleteByIds(IDS, objCommand);
                    }



                    #region 采购
                    for (int i = 0; i < Cais.Count; i++)
                    {
                        Cais[i].Id = model.Id;
                        if (Cais[i].IfUpdate == true && Cais[i].Ids != 0)
                        {
                            CaiSer.Update(Cais[i], objCommand);
                        }
                        else if (Cais[i].Ids == 0)
                        {
                            CaiSer.Add(Cais[i], objCommand);
                        }
                    }
                    if (CAI_IDS != "")
                    {
                        CAI_IDS = CAI_IDS.Substring(0, CAI_IDS.Length - 1);
                        CaiSer.DeleteByIds(CAI_IDS, objCommand);
                    }
                    #endregion


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

            return(true);
        }