Beispiel #1
0
        public CreateOrderView()
        {
            InitializeComponent();
            InitializeData();

            _regularBusiness   = new RegularOrderBusiness(SystemParam.CurrentUser);
            _irregularBusiness = new IrregularOrderBusiness(SystemParam.CurrentUser);
        }
        public List <TIrregularOrder> SyncIrregularOrder()
        {
            try
            {
                IEnumerable <OrderHistory> changedOrderIds;

                using (ThanhVanTranSysEntities context = new ThanhVanTranSysEntities())
                    using (IrregularOrderBusiness business = new IrregularOrderBusiness())
                    {
                        //insert/update records
                        changedOrderIds = context.OrderHistories
                                          .Where(i => i.date_time.Year == DateTime.Now.Year && i.date_time.Month == DateTime.Now.Month && i.date_time.Day == DateTime.Now.Day)
                                          .OrderBy(i => i.order_id).ThenBy(i => i.date_time);

                        var orders = (from io in business.GetAll()
                                      join co in changedOrderIds on io.id equals co.order_id
                                      select ThriftUtil.ConvertToTIrregularOrder(io, co.action == Constants.DELETE_ACTION)).ToList();

                        //deleted records
                        orders.AddRange((from o in changedOrderIds
                                         where o.action == Constants.DELETE_ACTION
                                         select new TIrregularOrder()
                        {
                            OrderId = o.order_id,
                            IsDeleted = true,
                            CloseDate = DateTime.Now.ToString(),
                            CreateBy = string.Empty,
                            CreateDate = DateTime.Now.ToString(),
                            Destination = string.Empty,
                            OrderStaus = string.Empty,
                            PaymentStatus = string.Empty,
                            RecipientIdNo = string.Empty,
                            RecipientName = string.Empty,
                            RecipientPhone = string.Empty,
                            SenderIdNo = string.Empty,
                            SenderName = string.Empty,
                            SenderPhone = string.Empty,
                            UserReponsitory = string.Empty,
                            TotalCost = 0,
                            TotalQuantity = 0,
                            TotalValue = 0,
                        }));

                        return(orders);
                    }
            }
            catch (Exception exc)
            {
                ServerLogger.logError("[LoadIrregularOrder]", exc);
                return(new List <TIrregularOrder>());
            }
        }
        public string CreateOrder(TOrder torder, List <TOrderItem> torderItems, string userId)
        {
            try
            {
                //Check Order
                string errorMessage = CheckOrder(torder);

                //check OrderItem
                List <OrderItem> orderItems = ThriftUtil.ConvertToOrderItemList(torderItems);
                errorMessage += CheckOrderItems(orderItems);

                if (string.IsNullOrEmpty(errorMessage) == false)
                {
                    return(errorMessage);
                }

                string orderId = string.Empty;
                //Insert Order
                if (torder.Type == Constants.VALUE_ORDER_TYPE_REGULAR)
                {
                    using (RegularOrderBusiness business = new RegularOrderBusiness())
                    {
                        business.Insert(ThriftUtil.ConvertToRegualrOrder(torder));
                    }
                }
                else
                {
                    using (IrregularOrderBusiness business = new IrregularOrderBusiness())
                    {
                        business.Insert(ThriftUtil.ConvertToIrregularOrder(torder));
                    }
                }

                using (OrderItemBusiness business = new OrderItemBusiness())
                {
                    business.Insert(orderItems);
                }

                //notify to the others client station
                //torder.OrderId = orderId;
                //BroadcastToClient(ClientAction.CreateOrder,order,orderItems);

                return("");
            }
            catch (Exception exc)
            {
                ServerLogger.logError("[CreateOrder]", exc);
                return(exc.Message);
            }
        }
 public List <TIrregularOrder> LoadIrregularOrder()
 {
     try
     {
         using (IrregularOrderBusiness business = new IrregularOrderBusiness())
         {
             return(business.GetAll().ToList().Select(i => ThriftUtil.ConvertToThriftObject(i) as TIrregularOrder).ToList());
         }
     }
     catch (Exception exc)
     {
         ServerLogger.logError("[LoadIrregularOrder]", exc);
         return(new List <TIrregularOrder>());
     }
 }
        public string UpdateOrderInfo(TOrder torder, List <TOrderItem> orderItems, string userId)
        {
            try
            {
                //Check Order
                string errorMessage = CheckOrder(torder, true);

                //check OrderItem
                errorMessage += orderItems.Count == 0 ? "Không có thông tin hàng hóa" : "";

                if (string.IsNullOrEmpty(errorMessage) == false)
                {
                    return(errorMessage);
                }

                if (torder.Type == Constants.VALUE_ORDER_TYPE_REGULAR)
                {
                    using (RegularOrderBusiness business = new RegularOrderBusiness())
                    {
                        business.Update(ThriftUtil.ConvertToEntityObject(torder) as RegularOrder);
                    }
                }
                else
                {
                    using (IrregularOrderBusiness business = new IrregularOrderBusiness())
                    {
                        business.Update(ThriftUtil.ConvertToEntityObject(torder) as IrregularOrder);
                    }
                }

                using (OrderItemBusiness business = new OrderItemBusiness())
                {
                    business.DeleteByOrderId(torder.OrderId);

                    business.Insert(ThriftUtil.ConvertToOrderItemList(orderItems).Cast <OrderItem>());
                }

                //notify to the others client station
                //BroadcastToClient(ClientAction.UpdateOrder,order,orderItems);

                return("");
            }
            catch (Exception exc)
            {
                ServerLogger.logError("[UpdateOrderInfo]", exc);
                return(exc.Message);
            }
        }
        private void InitializeData()
        {
            // Initializes object instance
            _business = new IrregularOrderBusiness(SystemParam.CurrentUser);

            // Disables created date range criteria
            dtpCreatedDateFrom.Enabled = false;
            dtpCreatedDateTo.Enabled   = false;

            // Binds data source for delivery status drop-down list
            var deliveryStatusesList = typeof(Constants.DeliveryStatus).ToList <string>();

            deliveryStatusesList.Insert(0, new KeyValuePair <string, string>("--", "Tất cả"));
            this.cboDeliveryStatusCriteria.DisplayMember = "Value";
            this.cboDeliveryStatusCriteria.ValueMember   = "Key";
            this.cboDeliveryStatusCriteria.DataSource    = deliveryStatusesList;

            // Binds data source for tour drop-down list
            List <KeyValuePair <string, string> > toursList = new List <KeyValuePair <string, string> >();

            foreach (var tour in (new TourBusiness()).GetAll())
            {
                string displayText = string.Format("{0} - {1}", tour.start, tour.destination);
                if (!toursList.Exists(e => e.Key.Equals(tour.destination)))
                {
                    toursList.Add(new KeyValuePair <string, string>(tour.id, displayText));
                }
            }
            cboTour.ValueMember   = "Key";
            cboTour.DisplayMember = "Value";
            cboTour.DataSource    = toursList;

            // Sets display text for Delivery Status radio buttons
            rbtnDeliveryStatus_Waiting.Text    = Constants.DeliveryStatus.Waiting.GetDescription();
            rbtnDeliveryStatus_Delivering.Text = Constants.DeliveryStatus.Delivering.GetDescription();
            rbtnDeliveryStatus_Arrived.Text    = Constants.DeliveryStatus.Arrived.GetDescription();
            rbtnDeliveryStatus_Delivered.Text  = Constants.DeliveryStatus.Delivered.GetDescription();
            rbtnDeliveryStatus_Closed.Text     = Constants.DeliveryStatus.Closed.GetDescription();

            // Sets display text for Payment Status radio buttons
            rbtnPaymentStatus_Unpaid.Text = Constants.PaymentStatus.Unpaid.GetDescription();
            rbtnPaymentStatus_Paid.Text   = Constants.PaymentStatus.Paid.GetDescription();

            // Disables order details
            ClearOrderDetails();
            ChangeOrderDetailsEditingStatus(false);
        }
        private void InitializeData()
        {
            try
            {
                AppLogger.logInfo(this.ToString(), "Begin initializing data.");
                _business = new IrregularOrderBusiness(SystemParam.CurrentUser);
                _revenueBusiness = new RevenueBusiness(SystemParam.CurrentUser);
                _checkedRows = new Collection<DataGridViewRow>();

                // Binds data source for tour drop-down list
                List<KeyValuePair<string, string>> toursList = new List<KeyValuePair<string, string>>();
                toursList.Add(new KeyValuePair<string, string>("--", "Tất cả"));
                foreach (var tour in (new TourBusiness()).GetAll())
                {
                    string displayText = string.Format("{0} - {1}", tour.start, tour.destination);
                    if (!toursList.Exists(e => e.Key.Equals(tour.destination)))
                    {
                        toursList.Add(new KeyValuePair<string, string>(tour.id, displayText));
                    }
                }
                cboTour.ValueMember = "Key";
                cboTour.DisplayMember = "Value";
                cboTour.DataSource = toursList;

                // Initializes checkbox header
                _chkOrdersListHeaderSelectAll = new CheckBox();
                var orderListFirstColumnHeaderCell = this.dgvOrdersList.Columns[0].HeaderCell;
                _chkOrdersListHeaderSelectAll.BackColor = orderListFirstColumnHeaderCell.Style.BackColor;
                _chkOrdersListHeaderSelectAll.Checked = true;
                //chkOrdersListHeaderSelectAll.Location = new Point((orderListFirstColumnHeaderCell.Size.Width - chkOrdersListHeaderSelectAll.Size.Width), (orderListFirstColumnHeaderCell.Size.Height - chkOrdersListHeaderSelectAll.Size.Height));
                _chkOrdersListHeaderSelectAll.Location = new Point(9, 5);
                _chkOrdersListHeaderSelectAll.Size = new Size(16, 16);//new Size(orderListFirstColumnHeaderCell.Size.Width, orderListFirstColumnHeaderCell.Size.Height);
                _chkOrdersListHeaderSelectAll.CheckedChanged += new EventHandler(chkOrdersListHeaderSelectAll_CheckedChanged);
                this.dgvOrdersList.Controls.Add(_chkOrdersListHeaderSelectAll);
                AppLogger.logInfo(this.ToString(), "Finish initializing data.");
            }
            catch (Exception ex)
            {
                AppLogger.logError(this.ToString(), ex);
            }
        }
        /// <summary>
        /// CompleteOrder (just using for Irregular Order)
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public string DeleteOrder(TOrder order, string userId)
        {
            try
            {
                // Check Order
                string errorMessage = CheckOrder(order, true);

                if (string.IsNullOrEmpty(errorMessage) == false)
                {
                    return(errorMessage);
                }

                // Delete
                if (order.Type == Constants.VALUE_ORDER_TYPE_REGULAR)
                {
                    RegularOrderBusiness business = new RegularOrderBusiness();
                    business.Delete(order.OrderId);
                }
                else
                {
                    IrregularOrderBusiness business = new IrregularOrderBusiness();
                    business.Delete(order.OrderId);
                }

                OrderItemBusiness itemBusiness = new OrderItemBusiness();
                itemBusiness.DeleteByOrderId(order.OrderId);

                ////notify to the others client station
                ////BroadcastToClient(ClientAction.CompleteOrder,order);

                return("");
            }
            catch (Exception exc)
            {
                ServerLogger.logError("[DeleteOrder]", exc);
                return(exc.Message);
            }
        }
        public string UpdateSingleOrderInfo(TOrder torder, string userId)
        {
            try
            {
                //Check Order
                string errorMessage = CheckOrder(torder, true);

                if (string.IsNullOrEmpty(errorMessage) == false)
                {
                    return(errorMessage);
                }

                if (torder.Type == Constants.VALUE_ORDER_TYPE_REGULAR)
                {
                    using (RegularOrderBusiness business = new RegularOrderBusiness())
                    {
                        business.Update(ThriftUtil.ConvertToEntityObject(torder) as RegularOrder);
                    }
                }
                else
                {
                    using (IrregularOrderBusiness business = new IrregularOrderBusiness())
                    {
                        business.Update(ThriftUtil.ConvertToEntityObject(torder) as IrregularOrder);
                    }
                }

                //notify to the others client station
                //BroadcastToClient(ClientAction.UpdateOrder,order,orderItems);

                return("");
            }
            catch (Exception exc)
            {
                ServerLogger.logError("[UpdateSingleOrderInfo]", exc);
                return(exc.Message);
            }
        }
        protected string CheckOrder(TOrder torder, bool isUpdated = false)
        {
            StringBuilder errorMessage = new StringBuilder();

            if (isUpdated)
            {
                EntityObject existOrder = null;
                if (torder.Type == Constants.VALUE_ORDER_TYPE_IRREGULAR)
                {
                    existOrder = new IrregularOrderBusiness().Get(torder.OrderId);
                }
                else
                {
                    existOrder = new RegularOrderBusiness().Get(torder.OrderId);
                }

                if (existOrder == null)
                {
                    errorMessage.AppendLine(string.Format("{0}Hóa đơn vận chuyển không tồn tại", Constants.SERVER_ERROR_CODE_SINGLE_DATA_NOT_SYNC));
                }
            }

            return(errorMessage.ToString());
        }