Пример #1
0
 public int Save(Coupon coupon)
 {
     if (coupon.CouponID <= 0)
         return new CouponDL().Save(coupon);
     else
         return new CouponDL().Update(coupon);
 }
Пример #2
0
 public Coupon GetCoupon(string code)
 {
     Coupon coupon = null;
     using (SqlConnection objConn = new SqlConnection(WebConfigurationManager.ConnectionStrings["eshopConnectionString"].ConnectionString))
     {
         using (SqlCommand objComm = new SqlCommand("getCouponByCode", objConn))
         {
             objConn.Open();
             objComm.Parameters.Add("@code", SqlDbType.NChar, 10).Value = code;
             objComm.CommandType = CommandType.StoredProcedure;
             using (SqlDataReader reader = objComm.ExecuteReader())
             {
                 while (reader.Read())
                 {
                     coupon = new Coupon(reader.GetInt32(0), reader.GetString(1), reader.GetDouble(2), code);
                 }
             }
         }
     }
     return coupon;
 }
Пример #3
0
 public Coupon GetCoupon(int couponID)
 {
     Coupon coupon = null;
     using (SqlConnection objConn = new SqlConnection(WebConfigurationManager.ConnectionStrings["eshopConnectionString"].ConnectionString))
     {
         using (SqlCommand objComm = new SqlCommand("coupon_select", objConn))
         {
             objConn.Open();
             objComm.CommandType = CommandType.StoredProcedure;
             objComm.Parameters.Add("@couponID", SqlDbType.Int).Value = couponID;
             using (SqlDataReader reader = objComm.ExecuteReader())
             {
                 while (reader.Read())
                 {
                     coupon = new Coupon(reader.GetInt32(0), reader.GetString(1), reader.GetDouble(7), reader.GetString(2), reader.GetDateTime(3), reader.GetDateTime(4), new CouponType(reader.GetInt32(5), reader.GetString(6)), null);
                     coupon.Objects = getCouponObjects(coupon.CouponID);
                 }
             }
         }
     }
     return coupon;
 }
Пример #4
0
        private void saveCouponObjects(Coupon coupon)
        {
            deleteCouponObjects(coupon.CouponID);
            using (SqlConnection objConn = new SqlConnection(WebConfigurationManager.ConnectionStrings["eshopConnectionString"].ConnectionString))
            {
                using (SqlCommand objComm = new SqlCommand("couponObject_insert", objConn))
                {
                    objConn.Open();
                    objComm.CommandType = CommandType.StoredProcedure;
                    foreach(CouponObject couponObject in coupon.Objects)
                    {
                        objComm.Parameters.Clear();
                        objComm.Parameters.Add("@couponID", SqlDbType.Int).Value = coupon.CouponID;
                        objComm.Parameters.Add("@objectTypeID", SqlDbType.Int).Value = couponObject.ObjectTypeID;
                        objComm.Parameters.Add("@objectID", SqlDbType.Int).Value = couponObject.ObjectID;
                        objComm.Parameters.Add("@name", SqlDbType.NVarChar, 50).Value = couponObject.Name;

                        objComm.ExecuteNonQuery();
                    }
                }
            }
        }
Пример #5
0
        public int Update(Coupon coupon)
        {
            int status = 0;
            using (SqlConnection objConn = new SqlConnection(WebConfigurationManager.ConnectionStrings["eshopConnectionString"].ConnectionString))
            {
                using (SqlCommand objComm = new SqlCommand("coupon_update", objConn))
                {
                    objConn.Open();
                    objComm.CommandType = CommandType.StoredProcedure;
                    objComm.Parameters.Add("@name", SqlDbType.NVarChar, 50).Value = coupon.Name;
                    objComm.Parameters.Add("@code", SqlDbType.NVarChar, 50).Value = coupon.Code;
                    objComm.Parameters.Add("@dateFrom", SqlDbType.Date).Value = coupon.DateFrom;
                    objComm.Parameters.Add("@dateTo", SqlDbType.Date).Value = coupon.DateTo;
                    objComm.Parameters.Add("@couponTypeID", SqlDbType.Int).Value = coupon.CouponType.CouponTypeID;
                    objComm.Parameters.Add("@discount", SqlDbType.Float).Value = coupon.Discount;
                    objComm.Parameters.Add("@couponID", SqlDbType.Int).Value = coupon.CouponID;

                    status = objComm.ExecuteNonQuery();

                    saveCouponObjects(coupon);
                }
            }
            return coupon.CouponID;
        }
Пример #6
0
        private void save()
        {
            Coupon coupon = new Coupon();
            coupon.Name = txtName.Text;
            coupon.Code = txtCode.Text;
            coupon.DateFrom = DateTime.Parse(txtDateFrom.Text);
            coupon.DateTo = DateTime.Parse(txtDateTo.Text);
            coupon.CouponType = new CouponType(int.Parse(cmbCouponType.SelectedValue), cmbCouponType.SelectedItem.Text);
            coupon.Discount = double.Parse(txtDiscount.Text);
            coupon.Objects = ((List<CouponObject>)ViewState["objects"]);
            coupon.CouponID = ViewState["couponID"] != null ? int.Parse(ViewState["couponID"].ToString()) : -1;

            coupon.CouponID = new CouponBL().Save(coupon);
            ViewState["couponID"] = coupon.CouponID;

            setStatus("Kupon uspešno sačuvan", System.Drawing.Color.Green, true, "success");
        }