Ejemplo n.º 1
0
 public void OrderDetail_Insert(OrderDetailBase orderDetailBase, ref int code, ref string msg)
 {
     adapter.OrderDetail_Insert(orderDetailBase, ref code, ref msg);
 }
Ejemplo n.º 2
0
        private void SaveData()
        {
            OrderBase    orderBase    = new OrderBase();
            OrderManager orderManager = new OrderManager();

            OrderDetailBase    orderDetailBase    = new OrderDetailBase();
            OrderDetailManager orderDetailManager = new OrderDetailManager();

            DataTable dtOrder       = new DataTable("dtOrder");
            DataTable dtOrderDetail = new DataTable("dtOrderDetail");

            int code = -1, orderId = 0; string msg = "";

            try
            {
                if (ViewState["dtOrderDetail"] != null)
                {
                    orderBase.AccountTypeId = int.Parse(ddlAccountType.SelectedValue);
                    orderBase.AccountId     = int.Parse(ddlAccount.SelectedValue);
                    orderBase.OrderCode     = txtOrderCode.Text.Trim();
                    orderBase.TransportFee  = decimal.Parse(txtTransportFee.Text.Trim().Replace(",", ""));
                    orderBase.Note          = txtNote.Text.Trim();
                    orderBase.CreateDate    = DateTimeParse(txtCreateDate.Text.Trim());
                    orderBase.CreateUser    = User.Identity.Name;

                    orderManager.Order_Insert(orderBase, ref code, ref msg);
                    SaveActionLog("Thêm mới Order", string.Format("code: {0}; msg: {1}", code, msg));

                    if (code == 0)
                    {
                        orderId       = int.Parse(msg.Split(';')[1].ToString());
                        dtOrderDetail = (DataTable)ViewState["dtOrderDetail"];

                        foreach (DataRow item in dtOrderDetail.Rows)
                        {
                            orderDetailBase.OrderId    = orderId;
                            orderDetailBase.ProductId  = int.Parse(item["ProductID"].ToString());
                            orderDetailBase.UnitTypeId = int.Parse(item["UnitTypeId"].ToString());
                            orderDetailBase.UnitId     = int.Parse(item["UnitId"].ToString());
                            orderDetailBase.UnitValue  = float.Parse(item["UnitValue"].ToString().Replace(",", ""));
                            orderDetailBase.Quantity   = int.Parse(item["Quantity"].ToString().Replace(",", ""));
                            orderDetailBase.Price      = decimal.Parse(item["Price"].ToString().Replace(",", ""));
                            orderDetailBase.Amount     = decimal.Parse(item["Amount"].ToString().Replace(",", ""));

                            orderDetailManager.OrderDetail_Insert(orderDetailBase, ref code, ref msg);

                            if (code != 0)
                            {
                                orderDetailManager.OrderDetail_Delete_OrderId(orderId, ref code, ref msg);
                                orderManager.Order_Delete(orderId, ref code, ref msg);
                                SaveActionLog("Xóa Order", string.Format("code: {0}; msg: {1}", code, msg));

                                ErrorBox.Message  = "Lưu dữ liệu thất bại";
                                NotifyBox.Message = string.Empty;

                                break;
                            }
                        }

                        if (ErrorBox.Message != "Lưu dữ liệu thất bại")
                        {
                            ErrorBox.Message  = string.Empty;
                            NotifyBox.Message = "Lưu dữ liệu thành công";
                        }
                    }
                    else
                    {
                        ErrorBox.Message  = "Lưu dữ liệu thất bại";
                        NotifyBox.Message = string.Empty;
                    }
                }
            }
            catch (Exception ex)
            {
                if (orderId != 0)
                {
                    orderDetailManager.OrderDetail_Delete_OrderId(orderId, ref code, ref msg);
                    orderManager.Order_Delete(orderId, ref code, ref msg);
                }

                ErrorBox.Message  = "Lỗi chức năng";
                NotifyBox.Message = string.Empty;
                SaveErrorLog(ex);
            }
        }
        public void OrderDetail_Insert(OrderDetailBase orderDetailBase, ref int code, ref string msg)
        {
            try
            {
                List <SqlParameter> paramList = new List <SqlParameter>();
                SqlParameter        param;

                param           = new SqlParameter("@OrderId", SqlDbType.Int, 4);
                param.Direction = ParameterDirection.Input;
                param.Value     = orderDetailBase.OrderId;
                paramList.Add(param);

                param           = new SqlParameter("@ProductId", SqlDbType.Int, 4);
                param.Direction = ParameterDirection.Input;
                param.Value     = orderDetailBase.ProductId;
                paramList.Add(param);

                param           = new SqlParameter("@UnitTypeId", SqlDbType.Int, 4);
                param.Direction = ParameterDirection.Input;
                param.Value     = orderDetailBase.UnitTypeId;
                paramList.Add(param);

                param           = new SqlParameter("@UnitId", SqlDbType.Int, 4);
                param.Direction = ParameterDirection.Input;
                param.Value     = orderDetailBase.UnitId;
                paramList.Add(param);

                param           = new SqlParameter("@UnitValue", SqlDbType.Float);
                param.Direction = ParameterDirection.Input;
                param.Value     = orderDetailBase.UnitValue;
                paramList.Add(param);

                param           = new SqlParameter("@Quantity", SqlDbType.Int, 4);
                param.Direction = ParameterDirection.Input;
                param.Value     = orderDetailBase.Quantity;
                paramList.Add(param);

                param           = new SqlParameter("@Price", SqlDbType.Decimal);
                param.Direction = ParameterDirection.Input;
                param.Value     = orderDetailBase.Price;
                paramList.Add(param);

                param           = new SqlParameter("@Amount", SqlDbType.Decimal);
                param.Direction = ParameterDirection.Input;
                param.Value     = orderDetailBase.Amount;
                paramList.Add(param);

                using (SqlDataReader dr = (SqlDataReader)Database.ExecuteReader("usp_OrderDetail_Insert", CommandType.StoredProcedure, paramList.ToArray()))
                {
                    if (dr.HasRows)
                    {
                        DataTable dt = new DataTable("dt");
                        dt.Load(dr);

                        DataRow row = dt.Rows[0];
                        code = int.Parse(row["code"].ToString());
                        msg  = row["msg"].ToString();
                    }

                    Database.CloseConn();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }