Пример #1
0
        public bool updateTran(VAN_OA.Model.EFrom.Tb_ExpInv model, VAN_OA.Model.EFrom.tb_EForm eform, tb_EForms forms, List <Tb_ExpInvs> proInvs, string IDS)
        {
            using (SqlConnection conn = DBHelp.getConn())
            {
                conn.Open();
                SqlTransaction tan        = conn.BeginTransaction();
                SqlCommand     objCommand = conn.CreateCommand();
                objCommand.Transaction = tan;


                Tb_ExpInvsService prosInvsSer = new Tb_ExpInvsService();
                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 < proInvs.Count; i++)
                    {
                        proInvs[i].PId = model.Id;
                        if (proInvs[i].IfUpdate == true && proInvs[i].Id != 0)
                        {
                            prosInvsSer.Update(proInvs[i], objCommand);
                        }
                        //else if (proInvs[i].Id == 0)
                        //{
                        //    prosInvsSer.Add(proInvs[i], objCommand);
                        //}
                    }
                    if (IDS != "")
                    {
                        IDS = IDS.Substring(0, IDS.Length - 1);
                        prosInvsSer.DeleteByIds(IDS, objCommand);
                    }

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

            return(true);
        }
Пример #2
0
        public int addTran(VAN_OA.Model.EFrom.Tb_ExpInv model, VAN_OA.Model.EFrom.tb_EForm eform, List <Tb_ExpInvs> proInvs)
        {
            int id     = 0;
            int MainId = 0;

            using (SqlConnection conn = DBHelp.getConn())
            {
                conn.Open();
                SqlTransaction tan        = conn.BeginTransaction();
                SqlCommand     objCommand = conn.CreateCommand();
                objCommand.Transaction = tan;
                Tb_ExpInvsService proInvsSer = new Tb_ExpInvsService();
                try
                {
                    tb_EFormService eformSer = new tb_EFormService();
                    objCommand.Parameters.Clear();
                    string proNo = eformSer.GetAllE_No("Tb_ExpInv", 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 < proInvs.Count; i++)
                    {
                        proInvs[i].PId = id;
                        proInvsSer.Add(proInvs[i], objCommand);
                    }
                    tan.Commit();
                }
                catch (Exception)
                {
                    tan.Rollback();
                    return(0);
                }
                return(id);
            }
        }