Esempio n. 1
0
        private void btnModify_Click(object sender, EventArgs e)
        {
            if (idDL != -1 && arrIdLDL[cbLoaiDL.SelectedIndex] >= 0 && arrIdQuan[cbQuan.SelectedIndex] >= 0 &&
                txtTienNo.Text.Equals("") == false && txtTenDaiLy.Text.Equals("") == false &&
                txtSdt.Text.Equals("") == false && txtDiaChi.Text.Equals("") == false)
            {
                DTO_DaiLy dl = new DTO_DaiLy();
                dl.IdDL     = idDL;
                dl.IdLoaiDL = arrIdLDL[cbLoaiDL.SelectedIndex];
                dl.IdQuan   = arrIdQuan[cbQuan.SelectedIndex];
                dl.TienNo   = (float)Convert.ToDouble(txtTienNo.Text);
                dl.TenDaiLy = txtTenDaiLy.Text;
                dl.Sdt      = txtSdt.Text;
                dl.DiaChi   = txtDiaChi.Text;
                dl.Cmnd     = nhanVien.Cmnd;
                dl.NgayNhan = DateTime.Now;

                int kq = BUS_DaiLy.SuaDaiLy(dl);

                if (kq == 1)
                {
                    dsDaiLy = BUS_DaiLy.DsDaiLy();
                    UpdateGvDaiLy();
                    MessageBox.Show("Cập nhật thành công");
                }
                else if (kq == 3)
                {
                    MessageBox.Show("Loại đại lý đã đủ số lượng");
                }
                else
                {
                    MessageBox.Show("Cập nhật thất bại");
                }
            }
        }
Esempio n. 2
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     if (idDL != -1 && arrIdLDL[cbLoaiDL.SelectedIndex] >= 0 && arrIdQuan[cbQuan.SelectedIndex] >= 0 &&
         txtTienNo.Text.Equals("") == false && txtTenDaiLy.Text.Equals("") == false &&
         txtSdt.Text.Equals("") == false && txtDiaChi.Text.Equals("") == false)
     {
         DTO_DaiLy dl = new DTO_DaiLy();
         dl.IdDL     = 1;
         dl.IdLoaiDL = arrIdLDL[cbLoaiDL.SelectedIndex];
         dl.IdQuan   = arrIdQuan[cbQuan.SelectedIndex];
         dl.TenDaiLy = txtTenDaiLy.Text;
         dl.Sdt      = txtSdt.Text;
         dl.Cmnd     = nhanVien.Cmnd;
         dl.DiaChi   = txtDiaChi.Text;
         dl.NgayNhan = DateTime.Now;
         dl.TienNo   = 0;
         if (BUS_DaiLy.Themdaily(dl) == 0)
         {
         }
         else
         {
             dsDaiLy = BUS_DaiLy.DsDaiLy();
             UpdateGvDaiLy();
         }
     }
 }
Esempio n. 3
0
        /*
         * Sửa đại lý
         * 1:Sửa thành công
         * 2:tiền nợ vượt quy định cho phép
         *
         */
        public static int SuaDaiLy(DTO_DaiLy daiLy)
        {
            int        kq;
            string     ngayNhanSql = daiLy.NgayNhan.ToString("yyyy-MM-dd");
            SqlCommand cmd         = new SqlCommand("PR_UpdateDL", conn);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@TenDaiLy", SqlDbType.NVarChar).Value = daiLy.TenDaiLy;
            cmd.Parameters.Add("@SDT", SqlDbType.VarChar).Value       = daiLy.Sdt;
            cmd.Parameters.Add("@DiaChi", SqlDbType.NVarChar).Value   = daiLy.DiaChi;
            cmd.Parameters.Add("@IdQuan", SqlDbType.Int).Value        = daiLy.IdQuan;
            cmd.Parameters.Add("@NgayTiepNhan", SqlDbType.Date).Value = ngayNhanSql;
            cmd.Parameters.Add("@IdLoaiDL", SqlDbType.Int).Value      = daiLy.IdLoaiDL;
            cmd.Parameters.Add("@CMND", SqlDbType.VarChar).Value      = daiLy.Cmnd;
            cmd.Parameters.Add("@TienNo", SqlDbType.Float).Value      = daiLy.Cmnd;
            cmd.Parameters.Add("@IdDaiLy", SqlDbType.Int).Value       = daiLy.IdDL;
            cmd.Parameters.Add("@out", SqlDbType.Int).Direction       = ParameterDirection.Output;
            try
            {
                conn.Open();
                cmd.ExecuteNonQuery();
                kq = (int)cmd.Parameters["@out"].Value;
                return(kq);
            }
            finally
            {
                conn.Close();
            }
        }
Esempio n. 4
0
        private void btnThemDaiLy_Click(object sender, EventArgs e)
        {
            if (btnThemDaiLy.Text == "Thêm Đại Lý")
            {
                btnThemDaiLy.Text = "Lưu";
                btnSua.Enabled    = false;
                btnXoa.Text       = "Hủy";
                btnXoa.Enabled    = true;
                SetDefault(true);
                txtTenDaiLy.Focus();
            }
            else
            {
                DialogResult result = MessageBox.Show("Bạn chắc chắn muốn thêm đại lý", "THÊM ĐẠI LÝ", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (result == DialogResult.OK)
                {
                    if (KiemTra())
                    {
                        DTO_DaiLy dl = new DTO_DaiLy();
                        dl.TenDaiLy     = this.txtTenDaiLy.Text;
                        dl.MaLoaiDL     = long.Parse(this.cbLoaiDaiLy.SelectedValue.ToString());
                        dl.MaQuan       = long.Parse(this.cbQuan.SelectedValue.ToString());
                        dl.DiaChi       = this.txtDiaChi.Text;
                        dl.Sdt          = this.txtSoDienThoai.Text;
                        dl.NgayTiepNhan = this.date.Value;
                        dl.TongNo       = uint.Parse(this.txtTongNo.Text);

                        if (daily.ThemDaiLy(dl))
                        {
                            btnThemDaiLy.Text = "Thêm Đại Lý";
                            btnXoa.Text       = "Xóa";

                            dataDaiLy.DataSource = daily.LayDanhSachDaiLy();
                            CurrencyManager myCurrencyManager = (CurrencyManager)this.BindingContext[dataDaiLy.DataSource];
                            myCurrencyManager.Refresh();

                            SetDefault(false);
                            ResetValue();

                            if (string.IsNullOrEmpty(txtMaDaiLy.Text))
                            {
                                btnXoa.Enabled = false;
                            }

                            MessageBox.Show("Thêm đại lý thành công", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                        else
                        {
                            MessageBox.Show("Vui lòng kiểm tra lại quy định và dữ liệu", "Thêm đại lý thất bại", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        public List <DTO_DaiLy> LayDanhSachDaiLy()
        {
            List <DTO_DaiLy> ldl = new List <DTO_DaiLy>();

            string query = string.Empty;

            query = "SELECT * FROM tblDaiLy";

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;

                    try
                    {
                        con.Open();
                        SqlDataReader reader = cmd.ExecuteReader();

                        if (reader.HasRows == true)
                        {
                            while (reader.Read())
                            {
                                DTO_DaiLy dl = new DTO_DaiLy();
                                dl.Id           = long.Parse(reader["id"].ToString());
                                dl.TenDaiLy     = reader.GetString(1);
                                dl.MaLoaiDL     = long.Parse(reader["maLoaiDL"].ToString());
                                dl.Sdt          = reader.GetString(3);
                                dl.DiaChi       = reader.GetString(4);
                                dl.MaQuan       = long.Parse(reader["maQuan"].ToString());
                                dl.NgayTiepNhan = reader.GetDateTime(6);
                                dl.TongNo       = (uint)reader.GetDecimal(7);
                                ldl.Add(dl);
                            }
                        }
                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        return(null);
                    }
                }
            }

            return(ldl);
        }
Esempio n. 6
0
        public bool SuaDaiLy(DTO_DaiLy dl)
        {
            string query = string.Empty;

            query = "UPDATE [tblDaiLy] " +
                    "SET [tenDL] = @tendl , [maLoaiDL] = @maldl, [sdt] = @sdt, [diaChi] = @diachi, [maQuan] = @maquan, [tongNo] = @tongno " +
                    "WHERE [id] = @id";
            //query = "SuaDaiLy";

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    //cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.CommandText = query;

                    cmd.Parameters.AddWithValue("@tendl", dl.TenDaiLy);
                    cmd.Parameters.AddWithValue("@maldl", dl.MaLoaiDL);
                    cmd.Parameters.AddWithValue("@sdt", dl.Sdt);
                    cmd.Parameters.AddWithValue("@diachi", dl.DiaChi);
                    cmd.Parameters.AddWithValue("@maquan", dl.MaQuan);
                    cmd.Parameters.AddWithValue("@tongno", Decimal.Parse(dl.TongNo.ToString()));
                    cmd.Parameters.AddWithValue("@id", dl.Id);

                    try
                    {
                        con.Open();
                        if (cmd.ExecuteNonQuery() > 0)
                        {
                            con.Close();
                            con.Dispose();
                            return(true);
                        }
                        else
                        {
                            con.Close();
                            return(false);
                        }
                    }
                    catch
                    {
                        con.Close();
                        return(false);
                    }
                }
            }
        }
Esempio n. 7
0
        public bool ThemDaiLy(DTO_DaiLy dl)
        {
            string query = string.Empty;

            query += "INSERT INTO [tblDaiLy] ([tenDL], [maLoaiDL], [sdt], [diaChi], [maQuan], [ngayTiepNhan], [tongNo]) ";
            query += "VALUES (@tendl, @maloaidl, @sdt, @diachi, @maquan, @ngaytiepnhan, @tongno)";

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;

                    cmd.Parameters.AddWithValue("@tendl", dl.TenDaiLy);
                    cmd.Parameters.AddWithValue("@maloaidl", dl.MaLoaiDL);
                    cmd.Parameters.AddWithValue("@sdt", dl.Sdt);
                    cmd.Parameters.AddWithValue("@diachi", dl.DiaChi);
                    cmd.Parameters.AddWithValue("@maquan", dl.MaQuan);
                    cmd.Parameters.AddWithValue("@ngaytiepnhan", dl.NgayTiepNhan);
                    cmd.Parameters.AddWithValue("@tongno", Decimal.Parse(dl.TongNo.ToString()));

                    try
                    {
                        con.Open();
                        if (cmd.ExecuteNonQuery() > 0)
                        {
                            con.Close();
                            con.Dispose();
                            return(true);
                        }
                        else
                        {
                            con.Close();
                            return(false);
                        }
                    }
                    catch
                    {
                        con.Close();
                        return(false);
                    }
                }
            }
        }
Esempio n. 8
0
        public static ArrayList search(string name)
        {
            ArrayList al    = new ArrayList();
            string    query = "select * from DaiLy where TenDaiLy like N'%" + name + "%'";
            DataTable tb    = ResultQuery.GetTableResult(conn, query);

            foreach (DataRow r in tb.Rows)
            {
                int       id       = (int)r["IdDaiLy"];
                string    tenDL    = r["TenDaiLy"].ToString();
                string    sdt      = r["SDT"].ToString();
                string    diaChi   = r["DiaChi"].ToString();
                int       idquan   = (int)r["IdQuan"];
                DateTime  ngayNhan = Convert.ToDateTime(r["NgayTiepNhan"]);
                int       idLoaiDL = (int)r["IdLoaiDL"];
                string    cmnd     = r["CMND"].ToString();
                float     tienNo   = (float)Convert.ToDouble(r["TienNo"]);
                DTO_DaiLy dl       = new DTO_DaiLy(id, idLoaiDL, tenDL, sdt, diaChi, idquan, ngayNhan, cmnd, tienNo);
                al.Add(dl);
            }
            return(al);
        }
Esempio n. 9
0
        public List <DTO_DaiLy> TimKiemDaiLy(string tukhoa)
        {
            List <DTO_DaiLy> ds = new List <DTO_DaiLy>();

            string query = string.Empty;

            query += "SELECT * FROM [tblDaiLy]";
            query += "WHERE [tenDL] like '%' + @tukhoa + '%' " +
                     "OR [sdt] like '%' + @tukhoa + '%' " +
                     "OR [diaChi] like '%' + @tukhoa + '%' ";
            long tk;

            if (long.TryParse(tukhoa, out tk))
            {
                query += "OR [id] like '%' + @tukhoa + '%' " +
                         "OR[maLoaiDL] like '%' + @tukhoa + '%' " +
                         "OR [maQuan] like '%' + @tukhoa + '%' ";
            }

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;

                    cmd.Parameters.AddWithValue("@tukhoa", tukhoa);
                    cmd.Parameters.AddWithValue("@tk", tk);

                    try
                    {
                        con.Open();
                        SqlDataReader reader = cmd.ExecuteReader();

                        if (reader.HasRows == true)
                        {
                            while (reader.Read())
                            {
                                DTO_DaiLy dl = new DTO_DaiLy();
                                dl.Id           = long.Parse(reader["id"].ToString());
                                dl.TenDaiLy     = reader.GetString(1);
                                dl.MaLoaiDL     = long.Parse(reader["maLoaiDL"].ToString());
                                dl.Sdt          = reader.GetString(3);
                                dl.DiaChi       = reader.GetString(4);
                                dl.MaQuan       = long.Parse(reader["maQuan"].ToString());
                                dl.NgayTiepNhan = reader.GetDateTime(6);
                                dl.TongNo       = (uint)reader.GetDecimal(7);
                                ds.Add(dl);
                            }
                        }
                        con.Close();
                        con.Dispose();
                    }
                    catch
                    {
                        con.Close();
                        return(null);
                    }
                }
            }

            return(ds);
        }
Esempio n. 10
0
 public bool SuaDaiLy(DTO_DaiLy dl)
 {
     return(daily.SuaDaiLy(dl));
 }
Esempio n. 11
0
 public bool ThemDaiLy(DTO_DaiLy dl)
 {
     return(daily.ThemDaiLy(dl));
 }
Esempio n. 12
0
        public static int SuaDaiLy(DTO_DaiLy dl)
        {
            int a = DAL_DaiLy.SuaDaiLy(dl);

            return(a);
        }
Esempio n. 13
0
        public static int Themdaily(DTO_DaiLy dl)
        {
            int a = DAL_DaiLy.ThemDaiLy(dl);

            return(a);
        }