Exemplo n.º 1
0
        public static T CreateItem <T>(DataRow row)
        {
            T obj = default(T);

            if (row != null)
            {
                obj = Activator.CreateInstance <T>();
                foreach (DataColumn column in row.Table.Columns)
                {
                    PropertyInfo prop = obj.GetType().GetProperty(column.ColumnName);
                    if (prop == null)
                    {
                        continue;
                    }
                    Type type = prop.PropertyType;
                    try
                    {
                        object value = row[column.ColumnName];
                        if (value != DBNull.Value)
                        {
                            if (column.ColumnName.Contains("json"))
                            {
                                prop.SetValue(obj, MessageConvert.DeserializeObject(("" + value).Replace("$", ""), type), null);
                            }
                            else if (type.Name == "String")
                            {
                                prop.SetValue(obj, Convert.ToString(value), null);
                            }
                            else if (type.Name == "Single")
                            {
                                prop.SetValue(obj, Convert.ToSingle(value), null);
                            }
                            else if (type.Name == "Nullable`1" || type.Name == "DateTime")
                            {
                                var t         = Nullable.GetUnderlyingType(type) ?? type;
                                var safeValue = (value == null) ? null : Convert.ChangeType(value, t);
                                prop.SetValue(obj, safeValue, null);
                            }
                            else
                            {
                                prop.SetValue(obj, value, null);
                            }
                        }
                    }
                    catch
                    {
                        // You can log something here
                        throw;
                    }
                }
            }

            return(obj);
        }
        public bool Create(HoaDonModel model)
        {
            string msgError = "";

            try
            {
                var result = _dbHelper.ExecuteScalarSProcedureWithTransaction(out msgError, "sp_hoa_don_create",
                                                                              "@ID", model.ID,
                                                                              "@Name", model.Name,
                                                                              "@Email", model.Email,
                                                                              "@Address", model.Address,
                                                                              "@Phone", model.Phone,
                                                                              "@Total", model.Total,
                                                                              "@Note", model.Note,
                                                                              //"@DateOrder", model.DateOrder,
                                                                              "@listjson_chitiet", model.listjson_chitiet != null ? MessageConvert.SerializeObject(model.listjson_chitiet) : null);
                if ((result != null && !string.IsNullOrEmpty(result.ToString())) || !string.IsNullOrEmpty(msgError))
                {
                    throw new Exception(Convert.ToString(result) + msgError);
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 3
0
        public bool Create(HoaDonModel model)
        {
            string msgError = "";

            try
            {
                var result = _dbHelper.ExecuteScalarSProcedureWithTransaction(out msgError, "sp_hoa_don_create",
                                                                              "@ma_hoa_don", model.ma_hoa_don,
                                                                              "@ho_ten", model.ho_ten,
                                                                              "@dia_chi", model.dia_chi,
                                                                              "@sdt", model.sdt,
                                                                              "@total", model.total,
                                                                              "@listjson_chitiet", model.listjson_chitiet != null ? MessageConvert.SerializeObject(model.listjson_chitiet) : null);
                if ((result != null && !string.IsNullOrEmpty(result.ToString())) || !string.IsNullOrEmpty(msgError))
                {
                    throw new Exception(Convert.ToString(result) + msgError);
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 4
0
        public DonHangModel Them(DonHangModel dh)
        {
            string msgError = "";

            try
            {
                var dt = _dbHelper.ExecuteSProcedureReturnDataTable(out msgError, "themdonhang",
                                                                    "@MaKH", dh.MaKH,
                                                                    "@MaShop", dh.MaShop,
                                                                    "@ThanhToan", dh.ThanhToan,
                                                                    "@MaDiaChi", dh.MaDiaChi,
                                                                    "@chitiet", dh.chitiet != null ? MessageConvert.SerializeObject(dh.chitiet) : null,
                                                                    "@TenKh", dh.TenKH,
                                                                    "@Email", dh.Email,
                                                                    "@SoDienThoai", dh.SoDienThoai,
                                                                    "@Xa", dh.Xa,
                                                                    "@Huyen", dh.Huyen,
                                                                    "@Tinh", dh.Tinh,
                                                                    "@DCChiTiet", dh.DCChitiet,
                                                                    "@HashedCardInformation", dh.HashedCardInformation
                                                                    );
                if (!string.IsNullOrEmpty(msgError))
                {
                    throw new Exception(msgError);
                }
                return(dt.ConvertTo <DonHangModel>().FirstOrDefault());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public bool Update(HoaDonBanModel model)
        {
            string msgError = "";

            try
            {
                var result = _dbHelper.ExecuteScalarSProcedureWithTransaction(out msgError, "sp_hoadonban_update",
                                                                              "@Mahdb", model.Mahdb,
                                                                              "@Makh", model.Makh,
                                                                              "@Ngayban", model.Ngayban,
                                                                              "@Hoten", model.Ngayban,
                                                                              "@SDT", model.Ngayban,
                                                                              "@Diachi", model.Ngayban,
                                                                              "@Tongtien", model.Tongtien,
                                                                              "@Thanhtoan", model.Thanhtoan,
                                                                              "@Ghichu", model.Ghichu,
                                                                              "@listjson_chitiet", model.listjson_chitiet != null ? MessageConvert.SerializeObject(model.listjson_chitiet) : null);
                if ((result != null && !string.IsNullOrEmpty(result.ToString())) || !string.IsNullOrEmpty(msgError))
                {
                    throw new Exception(Convert.ToString(result) + msgError);
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 6
0
        public bool Create(BillModel model)
        {
            string msgError = "";

            try
            {
                var result = _dbHelper.ExecuteScalarSProcedureWithTransaction(out msgError, "sp_Bill_create",
                                                                              "@id", model.id,
                                                                              "@name", model.name,
                                                                              "@total", model.total,
                                                                              "@address", model.address,
                                                                              "@phone", model.phone,
                                                                              "@email", model.email,
                                                                              "@created_at", model.created_at,
                                                                              "@listjson_chitiet", model.listjson_chitiet != null ? MessageConvert.SerializeObject(model.listjson_chitiet) : null);
                if ((result != null && !string.IsNullOrEmpty(result.ToString())) || !string.IsNullOrEmpty(msgError))
                {
                    throw new Exception(Convert.ToString(result) + msgError);
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 7
0
        public HoaDonNhapModel Them(HoaDonNhapModel hdn)
        {
            string msgError = "";

            try
            {
                var dt = _dbHelper.ExecuteSProcedureReturnDataTable(out msgError, "themhdn",
                                                                    "@mancc", hdn.MaNCC,
                                                                    "@mashop", hdn.MaShop,
                                                                    "@chitiet", hdn.chitiet != null ? MessageConvert.SerializeObject(hdn.chitiet) : null);
                if (!string.IsNullOrEmpty(msgError))
                {
                    throw new Exception(msgError);
                }

                return(dt.ConvertTo <HoaDonNhapModel>().FirstOrDefault());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 8
0
        public bool Dat_Hang(string maid, string ten_kh, string noi_giao, string sdt, int thanh_tien, List <ChiTietHoaDonModel> listjson_chitiet)
        {
            string msgError = "";

            try
            {
                var dt = _dbHelper.ExecuteScalarSProcedureWithTransaction(out msgError, "sp_dat_hang_2", "@ma_hoa_don", maid, "@ngay_dat", DateTime.Now, "@ngay_giao", DateTime.Now, "@tinhtrang", 0, "@makh", ten_kh, "@noi_giao", noi_giao, "@sdt", sdt, "@thanh_tien", thanh_tien, "@listjson_chitiet", listjson_chitiet != null ? MessageConvert.SerializeObject(listjson_chitiet) : null);
                if (!string.IsNullOrEmpty(msgError) || (!string.IsNullOrEmpty(dt.ToString()) && dt != null))
                {
                    throw new Exception(msgError);
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 9
0
        public bool Create(HoaDonModel model)
        {
            string msgError = "";

            try
            {
                var result = _dbHelper.ExecuteScalarSProcedureWithTransaction(out msgError, "sp_hoa_don_create",
                                                                              "@order_id ", model.order_id,
                                                                              "@customer_id ", model.customer_id,
                                                                              "@order_status ", model.order_status,
                                                                              "@order_date ", model.order_date,
                                                                              "@required_date ", model.required_date,
                                                                              "@shipped_date ", model.shipped_date,
                                                                              "@store_id ", model.store_id,
                                                                              "@staff_id", model.staff_id,
                                                                              //"@DateOrder", model.DateOrder,
                                                                              "@listjson_chitiet", model.listjson_chitiet != null ? MessageConvert.SerializeObject(model.listjson_chitiet) : null);
                if ((result != null && !string.IsNullOrEmpty(result.ToString())) || !string.IsNullOrEmpty(msgError))
                {
                    throw new Exception(Convert.ToString(result) + msgError);
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }