예제 #1
0
파일: BillDal.cs 프로젝트: SaintLoong/PFK
        public string GenBillFromTask(string billNo, string billType, string userID, string sysDate)
        {
            string newNo = null;
            using (PersistentManager pm = new PersistentManager())
            {
                BillDao billDao = new BillDao();
                ProductStateDao stateDao = new ProductStateDao();

                try
                {
                    pm.BeginTransaction();
                    DataTable stateTable = stateDao.FindBillDetail(billNo);

                    DataTable masterTable = billDao.FindMaster(billNo);

                    if (masterTable.Rows.Count != 0)
                    {
                        DataRow masterRow = masterTable.Rows[0];

                        string target = "";
                        if (billType == "002")//���ɵĵ���Ϊ���ⵥ
                            target = "3";

                        newNo = billDao.FindNewBillNo("P", sysDate);
                        billDao.InsertMaster(newNo, sysDate, billType, masterRow["SCHEDULENO"].ToString(),
                                         masterRow["BILLNO"].ToString(), masterRow["WAREHOUSECODE"].ToString(),
                                         target, "0", "1", userID);
                        int itemNo = 1;
                        foreach (DataRow stateRow in stateTable.Rows)
                        {
                            if (stateRow["REALQUANTITY"].ToString().Trim().Length != 0)
                            {
                                stateRow["REALQUANTITY"] = 0;
                                stateDao.Insert(newNo, billType, itemNo++, stateRow);
                            }
                        }

                        if (itemNo == 1)
                            throw new Exception("û���̰��ѳ��⣬����Ҫ�����˿ⵥ");

                        DataTable detailTable = stateDao.Find(newNo);
                        billDao.InsertDetail(newNo, detailTable);
                    }

                    pm.Commit();
                }
                catch (Exception e)
                {
                    pm.Rollback();
                    throw new Exception(e.Message);
                }
            }
            return newNo;
        }