Beispiel #1
0
        public string GenBill(string formulaCode, string scheduleNo, double quantity, String userID, string sysDate, string sysDate8)
        {
            string billNo = null;
            using (PersistentManager pm = new PersistentManager())
            {

                FormulaDao formulaDao = new FormulaDao();
                DataTable formulaTable = formulaDao.FindDetail(formulaCode);

                BillDao billDao = new BillDao();
                DataTable detailTable = billDao.FindDetailEmpty();

                int itemNo = 1;
                foreach (DataRow formulaRow in formulaTable.Rows)
                {
                    DataRow detailRow = detailTable.NewRow();

                    detailRow["ITEMNO"] = itemNo++;
                    detailRow["PRODUCTCODE"] = formulaRow["PRODUCTCODE"];
                    detailRow["QUANTITY"] = quantity * (Convert.ToDouble(formulaRow["QUANTITY"]) / 100.0);
                    detailRow["PACKAGECOUNT"] = 0;
                    detailRow["NCCOUNT"] = 0;
                    detailRow["OTHERCODE"] = formulaRow["OTHERCODE"];
                    detailTable.Rows.Add(detailRow);
                }
                try
                {
                    pm.BeginTransaction();

                    //string warehousePrefix = "C";
                    //billNo = warehousePrefix + sysDate8 + billDao.FindBillNo(sysDate, warehousePrefix).ToString().PadLeft(5, '0');
                    billNo = billDao.FindNewBillNo("C", sysDate);
                    billDao.InsertMaster(billNo, DateTime.Now.ToShortDateString(), "002", scheduleNo, scheduleNo, "", "", "1", "1", userID);
                    billDao.InsertDetail(billNo, detailTable);

                    ScheduleDao scheduleDao = new ScheduleDao();
                    scheduleDao.UpdateBillNo(scheduleNo, billNo);

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