示例#1
0
 public void DeleteGroupTransaction(NZString OrderNo)
 {
     try
     {
         Common.CurrentDatabase.KeepConnection = true;
         Common.CurrentDatabase.BeginTransaction();
         CustomerOrderBIZ            biz = new CustomerOrderBIZ();
         List <CustomerOrderViewDTO> dto = biz.LoadCustomerOrderEntry(OrderNo, false);
         biz.DeleteCustomerOrderHeader(Common.CurrentDatabase, dto);
         Common.CurrentDatabase.Commit();
     }
     catch (Exception ex)
     {
         Common.CurrentDatabase.Rollback();
         throw ex;
     }
 }
示例#2
0
        public CustomerOrderEntryUIDM LoadData(NZString orderNo)
        {
            CustomerOrderBIZ            biz         = new CustomerOrderBIZ();
            CustomerOrderViewDTO        ViewDTO     = biz.LoadCustomerOrderHeader(orderNo, false);
            List <CustomerOrderViewDTO> listViewDTO = biz.LoadCustomerOrderEntry(orderNo, false);

            if (ViewDTO != null)
            {
                CustomerOrderEntryUIDM model = MapDTOToUIDM(ViewDTO);
                model.DATA_VIEW = DTOUtility.ConvertListToDataTable(listViewDTO);

                //== Ensure that data has not modified.
                model.DATA_VIEW.AcceptChanges();

                return(model);
            }
            return(new CustomerOrderEntryUIDM());
        }
示例#3
0
        private void OnDelete()
        {
            try
            {
                NZString OrderNo       = new NZString(null, shtCustomerOrderList.GetValue(shtCustomerOrderList.ActiveRowIndex, (int)eColView.ORDER_NO));
                NZString OrderDetailNo = new NZString(null, shtCustomerOrderList.GetValue(shtCustomerOrderList.ActiveRowIndex, (int)eColView.ORDER_DETAIL_NO));

                MessageDialogResult dr = MessageDialog.ShowConfirmation(this, new Message(Messages.eConfirm.CFM9002.ToString()), MessageDialogButtons.YesNo);
                if (dr == MessageDialogResult.No)
                {
                    return;
                }

                m_controller.DeleteItem(OrderNo, OrderDetailNo);

                // When detail row <= 0 then delete header row
                CustomerOrderBIZ biz = new CustomerOrderBIZ();
                if (biz.LoadCustomerOrderEntry(OrderNo, false).Count <= 0)
                {
                    biz.DeleteCustomerOrderHeader(Common.CurrentDatabase, OrderNo);
                }

                shtCustomerOrderList.RemoveRows(shtCustomerOrderList.ActiveRowIndex, 1);

                MessageDialog.ShowInformation(this, null, new Message(Messages.eInformation.INF9003.ToString()).MessageDescription);
            }
            catch (BusinessException err)
            {
                MessageDialog.ShowBusiness(this, err.Error.Message);
                err.Error.FocusOnControl();
            }
            catch (ValidateException err)
            {
                MessageDialog.ShowBusiness(this, err.ErrorResults[0].Message);
                err.ErrorResults[0].FocusOnControl();
            }
            catch (Exception err)
            {
                MessageDialog.ShowBusiness(this, err.Message);
            }
        }
示例#4
0
        public void DeleteItem(NZString OrderNo, NZString OrderDetailNo)
        {
            try
            {
                Common.CurrentDatabase.KeepConnection = true;
                Common.CurrentDatabase.BeginTransaction();

                CustomerOrderBIZ     biz        = new CustomerOrderBIZ();
                CustomerOrderViewDTO dtoDelItem = new CustomerOrderViewDTO();
                dtoDelItem.ORDER_NO        = OrderNo;
                dtoDelItem.ORDER_DETAIL_NO = OrderDetailNo;
                biz.DeleteCustomerOrderDetail(Common.CurrentDatabase, dtoDelItem);
                biz.UpdateCustomerHeaderTotal(Common.CurrentDatabase, dtoDelItem);
                Common.CurrentDatabase.Commit();
            }
            catch (Exception ex)
            {
                Common.CurrentDatabase.Rollback();
                throw ex;
            }
        }
示例#5
0
        private void LoadData(NZDateTime from, NZDateTime to, NZInt filterType)
        {
            if (dtPeriodBegin.NZValue.IsNull || dtPeriodEnd.NZValue.IsNull)
            {
                if (dtPeriodBegin.NZValue.IsNull && dtPeriodEnd.NZValue.IsNull)
                {
                    MessageDialog.ShowBusiness(this, Message.LoadMessage(TKPMessages.eValidate.VLM0105.ToString(), new object[] { "Period date begin and Delivery date end" }));
                }
                else if (dtPeriodBegin.NZValue.IsNull)
                {
                    MessageDialog.ShowBusiness(this, Message.LoadMessage(TKPMessages.eValidate.VLM0105.ToString(), new object[] { "Period date begin" }));
                }
                else
                {
                    MessageDialog.ShowBusiness(this, Message.LoadMessage(TKPMessages.eValidate.VLM0105.ToString(), new object[] { "Period date end" }));
                }
                return;
            }

            CustomerOrderBIZ biz = new CustomerOrderBIZ();
            DataTable        dt  = DTOUtility.ConvertListToDataTable <CustomerOrderViewDTO>(biz.LoadCustomerOrderList(from, to, filterType, false));

            shtCustomerOrderList.RowCount   = 0;
            shtCustomerOrderList.DataSource = null;
            m_dtAllData = dt;
            FindDataFromMemory();
            CalculateTotal();
            //List<InventoryTransactionViewDTO> list = m_controller.LoadReceivingList(from, to);
            ////DataTable dt = DTOUtility.ConvertListToDataTable(list);
            //m_dtAllData = DTOUtility.ConvertListToDataTable(list);
            //shtCustomerOrderList.RowCount = 0;
            //shtCustomerOrderList.DataSource = null;
            //FindDataFromMemory();
            //shtView.DataSource = m_dtAllData;

            // CtrlUtil.SpreadUpdateColumnSorting(shtView);
        }
示例#6
0
        //public CustomerOrderEntryUIDM LoadData(NZString orderNo)
        //{

        //    CustomerOrderBIZ biz = new CustomerOrderBIZ();
        //    List<CustomerOrderViewDTO> listViewDTO = DTOUtility.ConvertDataTableToList<CustomerOrderViewDTO>(biz.LoadCustomerOrderEntry(orderNo, false));
        //    if (listViewDTO != null)
        //    {
        //        if (listViewDTO.Count > 0)
        //        {
        //            CustomerOrderEntryUIDM model = MapDTOToUIDM(listViewDTO[0]);
        //            model.DATA_VIEW = DTOUtility.ConvertListToDataTable(listViewDTO);

        //            //== Ensure that data has not modified.
        //            model.DATA_VIEW.AcceptChanges();

        //            return model;
        //        }
        //    }
        //    return new CustomerOrderEntryUIDM();
        //}

        #region SaveData
        public void Save(CustomerOrderEntryUIDM model, Common.eScreenMode Mode)
        {
            try
            {
                Common.CurrentDatabase.KeepConnection = true;
                Common.CurrentDatabase.BeginTransaction(IsolationLevel.Serializable);

                CustomerOrderBIZ biz = new CustomerOrderBIZ();

                #region Validate Data
                //== If data not has to processing.
                if (model.DATA_VIEW == null || model.DATA_VIEW.Rows.Count == 0)
                {
                    ValidateException.ThrowErrorItem(new ErrorItem(null, TKPMessages.eValidate.VLM0055.ToString()));
                }

                DataTable dtNonDelete = model.DATA_VIEW.GetChanges(DataRowState.Unchanged | DataRowState.Added | DataRowState.Modified);
                List <CustomerOrderViewDTO> listData = DTOUtility.ConvertDataTableToList <CustomerOrderViewDTO>(dtNonDelete);

                #endregion


                DataTable dtData   = model.DATA_VIEW.Copy();
                DataTable dtAdd    = dtData.GetChanges(DataRowState.Added);
                DataTable dtModify = dtData.GetChanges(DataRowState.Modified);
                DataTable dtDelete = dtData.GetChanges(DataRowState.Deleted);

                //ORDER_DETAIL_NO,
                //ITEM_CD,
                //ITEM_CD_BTN,
                //PART_NO,
                //ITEM_DELIVERY_DATE,
                //OLD_ITEM_DELIVERY_DATE,
                //QTY,
                //OLD_QTY,
                //PRICE,
                //AMOUNT,
                //PRICE_THB,
                //AMOUNT_THB

                // แก้บั๊ก GetChange แล้ว Data ไม่ถูกต้อง
                dtData.AcceptChanges();
                if (dtModify != null && dtModify.Rows.Count > 0)
                {
                    for (int i = 0; i < dtModify.Rows.Count; i++)
                    {
                        for (int j = 0; j < dtData.Rows.Count; j++)
                        {
                            if (Convert.ToString(dtModify.Rows[i]["ORDER_DETAIL_NO"]) == Convert.ToString(dtData.Rows[j]["ORDER_DETAIL_NO"]))
                            {
                                dtModify.Rows[i]["ITEM_CD"]            = dtData.Rows[j]["ITEM_CD"];
                                dtModify.Rows[i]["PART_NO"]            = dtData.Rows[j]["PART_NO"];
                                dtModify.Rows[i]["ITEM_DELIVERY_DATE"] = dtData.Rows[j]["ITEM_DELIVERY_DATE"];
                                dtModify.Rows[i]["QTY"]        = dtData.Rows[j]["QTY"];
                                dtModify.Rows[i]["PRICE"]      = dtData.Rows[j]["PRICE"];
                                dtModify.Rows[i]["AMOUNT"]     = dtData.Rows[j]["AMOUNT"];
                                dtModify.Rows[i]["PRICE_THB"]  = dtData.Rows[j]["PRICE_THB"];
                                dtModify.Rows[i]["AMOUNT_THB"] = dtData.Rows[j]["AMOUNT_THB"];
                            }
                        }
                    }
                }
                List <CustomerOrderViewDTO> listAdd    = new List <CustomerOrderViewDTO>();
                List <CustomerOrderViewDTO> listUpdate = new List <CustomerOrderViewDTO>();
                List <CustomerOrderViewDTO> listDelete = new List <CustomerOrderViewDTO>();


                //มีการปรับให้ทำคำสั่งทีละ set ของ add , update , delete เลย
                //ที่เริ่มจาก delete ก่อนเพราะ consumption จะได้มีการเอาไปใช้สำหรับตัวที่ add ได้เลย ไม่ต้องค้างไว้ lot หน้า
                //== Delete process.
                if (dtDelete != null && dtDelete.Rows.Count > 0)
                {
                    listDelete = DTOUtility.ConvertDataTableToList <CustomerOrderViewDTO>(dtDelete);
                    for (int i = 0; i < listDelete.Count; i++)
                    {
                        AssignHeaderToDTO(model, listDelete[i], Mode);
                    }

                    biz.SaveCustomerOrder(Common.CurrentDatabase, null, null, listDelete, Mode);

                    // When detail row <= 0 then delete header row

                    if ((dtAdd == null || dtAdd.Rows.Count == 0) &&
                        (dtModify == null || dtModify.Rows.Count == 0) &&
                        biz.LoadCustomerOrderEntry(listDelete[0].ORDER_NO, false).Count <= 0)
                    {
                        biz.DeleteCustomerOrderHeader(Common.CurrentDatabase, listDelete);
                    }
                }

                //== Insert process.
                if (dtAdd != null && dtAdd.Rows.Count > 0)
                {
                    listAdd = DTOUtility.ConvertDataTableToList <CustomerOrderViewDTO>(dtAdd);

                    List <CustomerOrderViewDTO> listAddEachDetail = null;

                    NZString         runningNo        = null;
                    RunningNumberBIZ runningNumberBIZ = new RunningNumberBIZ();

                    if (model.ORDER_NO.IsNull)
                    {
                        runningNo      = runningNumberBIZ.GetCompleteRunningNo((NZString)"CUSTOMER_ORDER_NO", (NZString)"TB_CUSTOMER_ORDERH_TR");
                        model.ORDER_NO = runningNo;
                        // Insert Header
                        AssignHeaderToDTO(model, listAdd[0], Mode);
                        biz.AddCustomerOrderHeader(Common.CurrentDatabase, listAdd[0]);
                    }
                    else
                    {
                        runningNo = model.ORDER_NO;
                    }


                    listAddEachDetail = new List <CustomerOrderViewDTO>();

                    for (int i = 0; i < listAdd.Count; i++)
                    {
                        CustomerOrderViewDTO dto = listAdd[i];

                        // Copy ค่า Header จาก Model ไปยัง DTO แต่ละตัว
                        AssignHeaderToDTO(model, dto, Mode);

                        //dto.TRANS_ID = runningNumberBIZ.GetCompleteRunningNo(DataDefine.TRANS_ID.ToNZString(), DataDefine.TRANSACTION_TABLE_NAME.ToNZString());

                        //add header ใส่ list
                        dto.CRT_BY      = Common.CurrentUserInfomation.UserCD;
                        dto.CRT_MACHINE = Common.CurrentUserInfomation.Machine;
                        dto.UPD_BY      = Common.CurrentUserInfomation.UserCD;
                        dto.UPD_MACHINE = Common.CurrentUserInfomation.Machine;

                        // Check all lines.


                        listAddEachDetail.Add(dto);
                    }

                    biz.SaveCustomerOrder(Common.CurrentDatabase, listAddEachDetail, null, null, Mode);
                }

                //== Update process.
                if (dtModify != null && dtModify.Rows.Count > 0)
                {
                    listUpdate = DTOUtility.ConvertDataTableToList <CustomerOrderViewDTO>(dtModify);


                    List <CustomerOrderViewDTO> listUpdateDetail = new List <CustomerOrderViewDTO>();


                    for (int i = 0; i < listUpdate.Count; i++)
                    {
                        CustomerOrderViewDTO dto = listUpdate[i];

                        CustomerOrderBIZ bizCustomer = new CustomerOrderBIZ();

                        CustomerOrderDDTO dtoDDTO = bizCustomer.LoadCustomerOrderDetail(dto.ORDER_NO.StrongValue, dto.ORDER_DETAIL_NO);

                        // Copy ค่า Header จาก Model ไปยัง DTO แต่ละตัว
                        AssignHeaderToDTO(model, dto, Mode);

                        dto.CRT_BY      = Common.CurrentUserInfomation.UserCD;
                        dto.CRT_MACHINE = Common.CurrentUserInfomation.Machine;
                        dto.UPD_BY      = Common.CurrentUserInfomation.UserCD;
                        dto.UPD_MACHINE = Common.CurrentUserInfomation.Machine;

                        //add header ใส่ list
                        listUpdateDetail.Add(dto);
                    }

                    biz.SaveCustomerOrder(Common.CurrentDatabase, null, listUpdateDetail, null, Mode);
                }


                //Update Header for Edit Case
                //if (Mode == Common.eScreenMode.EDIT && dtData != null && dtData.Rows.Count > 0)
                //{
                //    listUpdate = DTOUtility.ConvertDataTableToList<CustomerOrderViewDTO>(dtData);

                //    for (int i = 0; i < listUpdate.Count; i++)
                //    {
                //        CustomerOrderViewDTO dto = listUpdate[i];

                //        // Copy ค่า Header จาก Model ไปยัง DTO แต่ละตัว
                //        AssignHeaderToDTO(model, dto);

                //        dto.CRT_BY = Common.CurrentUserInfomation.UserCD;
                //        dto.CRT_MACHINE = Common.CurrentUserInfomation.Machine;
                //        dto.UPD_BY = Common.CurrentUserInfomation.UserCD;
                //        dto.UPD_MACHINE = Common.CurrentUserInfomation.Machine;

                //        biz.UpdateCustomerOrderHeader(Common.CurrentDatabase, dto);
                //    }
                //}

                Common.CurrentDatabase.Commit();
            }
            catch (Exception)
            {
                Common.CurrentDatabase.Rollback();
                throw;
            }
        }