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

                CG_POOrdersService OrdersSer = new CG_POOrdersService();
                CG_POCaiService    CaiSer    = new CG_POCaiService();
                try
                {
                    objCommand.Parameters.Clear();

                    model.Status = eform.state;
                    Update(model, objCommand);
                    tb_EFormService eformSer = new tb_EFormService();
                    eformSer.Update(eform, objCommand);
                    tb_EFormsService eformsSer = new tb_EFormsService();
                    eformsSer.Add(forms, objCommand);

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

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

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

                        //}
                    }

                    //入库
                    if (eform.state == "通过")
                    {
                        tb_EForm eformMain = new tb_EForm();
                        int      proId     = 0;
                        string   sql       = "select Pro_Id from A_ProInfo where pro_Type='采购入库'";
                        objCommand.CommandText = sql;

                        proId = Convert.ToInt32(objCommand.ExecuteScalar());

                        eformMain.appPer     = eform.appPer;
                        eformMain.appTime    = DateTime.Now;
                        eformMain.createPer  = eform.appPer;
                        eformMain.createTime = DateTime.Now;
                        eformMain.proId      = proId;
                        eformMain.state      = "通过";
                        eformMain.toPer      = 0;
                        eformMain.toProsId   = 0;

                        CAI_OrderInHouseService orderInHouse = new CAI_OrderInHouseService();
                        sql = "select top 1 id from TB_HouseInfo where ifdefault=1 ";
                        objCommand.CommandText = sql;
                        int objhouseId = Convert.ToInt32(objCommand.ExecuteScalar());
                        CAI_OrderInHouse orderInModel = new CAI_OrderInHouse()
                        {
                            ChcekProNo   = model.ProNo,
                            CreateTime   = DateTime.Now,
                            CreateUserId = eform.appPer,
                            GuestName    = orders[0].GuestName,
                            HouseID      = objhouseId,
                            POName       = orders[0].POName,
                            PONo         = orders[0].PONo,
                            RuTime       = DateTime.Now,
                            Status       = "通过",
                            Supplier     = orders[0].SupplierName,
                            DoPer        = orders[0].CaiGouPer,
                            DaiLi        = orders[0].CaiGouPer,
                            FPNo         = "",
                            Remark       = ""
                        };
                        List <CAI_OrderInHouses> ordersInHouses = new List <CAI_OrderInHouses>();
                        foreach (var m in orders)
                        {
                            CAI_OrderInHouses orderM = new CAI_OrderInHouses()
                            {
                                GooId            = m.CheckGoodId,
                                GoodNum          = m.CheckNum,
                                GoodPrice        = m.CheckPrice,
                                OrderCheckIds    = m.Ids,
                                QingGouPer       = m.QingGou,
                                CaiLastTruePrice = m.CheckLastTruePrice
                            };
                            ordersInHouses.Add(orderM);
                        }

                        orderInHouse.addTran(orderInModel, eformMain, ordersInHouses, objCommand);
                    }
                    tan.Commit();
                }
                catch (Exception)
                {
                    tan.Rollback();
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
        public int addTran(VAN_OA.Model.JXC.CAI_OrderCheck model, VAN_OA.Model.EFrom.tb_EForm eform, List <CAI_OrderChecks> orders, out int MainId, List <string> ids = null)
        {
            int id = 0;

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


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

                    model.Status = eform.state;
                    id           = Add(model, objCommand);
                    model.Id     = id;
                    MainId       = id;

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

                    //入库
                    if (eform.state == "通过")
                    {
                        tb_EForm eformMain = new tb_EForm();
                        int      proId     = 0;
                        string   sql       = "select Pro_Id from A_ProInfo where pro_Type='采购入库'";
                        objCommand.CommandText = sql;

                        proId = Convert.ToInt32(objCommand.ExecuteScalar());

                        eformMain.appPer     = eform.appPer;
                        eformMain.appTime    = DateTime.Now.AddSeconds(1);
                        eformMain.createPer  = eform.appPer;
                        eformMain.createTime = DateTime.Now.AddSeconds(1);
                        eformMain.proId      = proId;
                        eformMain.state      = "通过";
                        eformMain.toPer      = 0;
                        eformMain.toProsId   = 0;
                        eform.E_LastTime     = DateTime.Now.AddSeconds(1);
                        CAI_OrderInHouseService orderInHouse = new CAI_OrderInHouseService();
                        sql = "select top 1 id from TB_HouseInfo where ifdefault=1 ";
                        objCommand.CommandText = sql;
                        int objhouseId = Convert.ToInt32(objCommand.ExecuteScalar());
                        CAI_OrderInHouse orderInModel = new CAI_OrderInHouse()
                        {
                            ChcekProNo   = model.ProNo,
                            CreateTime   = DateTime.Now.AddSeconds(1),
                            CreateUserId = eform.appPer,
                            GuestName    = orders[0].GuestName,
                            HouseID      = objhouseId,
                            POName       = orders[0].POName,
                            PONo         = orders[0].PONo,
                            RuTime       = DateTime.Now.AddSeconds(1),
                            Status       = "通过",
                            Supplier     = orders[0].SupplierName,
                            DoPer        = orders[0].CaiGouPer,
                            DaiLi        = orders[0].CaiGouPer,
                            FPNo         = "",
                            Remark       = ""
                        };
                        List <CAI_OrderInHouses> ordersInHouses = new List <CAI_OrderInHouses>();
                        foreach (var m in orders)
                        {
                            CAI_OrderInHouses orderM = new CAI_OrderInHouses()
                            {
                                GooId            = m.CheckGoodId,
                                GoodNum          = m.CheckNum,
                                GoodPrice        = m.CheckPrice,
                                OrderCheckIds    = m.Ids,
                                QingGouPer       = m.QingGou,
                                CaiLastTruePrice = m.CheckLastTruePrice
                            };
                            ordersInHouses.Add(orderM);
                        }
                        orderInHouse.addTran(orderInModel, eformMain, ordersInHouses, objCommand);
                        if (ids != null)
                        {
                            foreach (var ordersIn in ordersInHouses)
                            {
                                ids.Add(ordersIn.Ids.ToString());
                            }
                        }
                    }

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