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); } }
private void btnCreateOrder_Click(object sender, EventArgs e) { if (ValidateInput() && MessageBox.Show(Constants.Messages.CREATE_ORDER_CONFIRMATION_MESSAGE, Constants.Messages.CREATE_ORDER_CONFIRMATION_CAPTION, MessageBoxButtons.OKCancel) == DialogResult.OK) { bool success = true; string saveResult = string.Empty; try { // Creates OrderBase instance and gets general info OrderBase order = new OrderBase(); order.id = rbtnOrderType_Regular.Checked ? IDGenerator.NewId <RegularOrder>() : IDGenerator.NewId <IrregularOrder>(); AppLogger.logDebug(this.ToString(), string.Format("Id: {0}", order.id)); order.payment_status = this.rbtnPaymentStatus_Paid.Checked ? Constants.PaymentStatus.Paid.ToString() : Constants.PaymentStatus.Unpaid.ToString(); order.order_status = Constants.DeliveryStatus.Waiting.ToString(); order.tour_id = cboDestination.SelectedValue.ToString(); order.created_date = DateTime.Now; order.created_by = SystemParam.CurrentUser.user_name; int totalQuantity = 0; decimal totalValue = 0; decimal totalCost = 0; foreach (var item in ucItemsList.OrderItems) { item.id = IDGenerator.NewOrderItemId(order.id, ucItemsList.OrderItems.IndexOf(item) + 1); item.order_id = order.id; totalQuantity += item.quantity; totalValue += item.value * item.quantity; totalCost += item.cost; } order.total_quantity = totalQuantity; order.total_value = totalValue; order.total_cost = totalCost; // Convert order info per order type if (rbtnOrderType_Regular.Checked) { RegularOrder regularOrder = order.ToRegular(); regularOrder.sender_id = Sender.id; regularOrder.recipient_id = Recipient.id; saveResult = _regularBusiness.Insert(regularOrder, ucItemsList.OrderItems); } else { IrregularOrder irregularOrder = order.ToIrregular(); irregularOrder.sender_name = tbSenderName.Text; irregularOrder.sender_phone = tbSenderPhoneNumber.Text; irregularOrder.sender_id_card_no = tbSenderIDCardNo.Text; irregularOrder.sender_address = tbSenderAddress.Text; irregularOrder.recipient_name = tbRecipientName.Text; irregularOrder.recipient_phone = tbRecipientPhoneNumber.Text; irregularOrder.recipient_id_card_no = tbRecipientIDCardNo.Text; irregularOrder.recipient_address = tbRecipientAddress.Text; if (rbtnPaymentStatus_Paid.Checked && (new IrregularOrderPaymentView(irregularOrder, ucItemsList.OrderItems)).ShowDialog() != System.Windows.Forms.DialogResult.OK) { AppLogger.logDebug(this.ToString(), "Payment process cancelled."); return; } saveResult = _irregularBusiness.Insert(irregularOrder, ucItemsList.OrderItems); } } catch (Exception ex) { AppLogger.logError(this.ToString(), ex.Message, ex); success = false; } if (success && string.IsNullOrEmpty(saveResult)) { AppLogger.logInfo(this.ToString(), "Finish inserting new order into database."); MessageBox.Show("Đã tạo thành công đơn hàng mới.", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None); this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } else { if (string.IsNullOrEmpty(saveResult)) { saveResult = Constants.Messages.CREATE_ORDER_ERROR_MESSAGE; } MessageBox.Show(saveResult, Constants.Messages.ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }