private void cmdAdd_Click(object sender, EventArgs e)
        {
            if (txtWareHouseID.Text.Trim() == "")
            {
                MessageBox.Show("กรุณาป้อนรหัสคลังสินค้าก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtWareHouseID.Focus();
                return;
            }
            if (txtWareHouseName.Text.Trim() == "")
            {
                MessageBox.Show("กรุณาป้อนชื่อคลังสินค้าก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtWareHouseName.Focus();
                return;
            }
            if (txtLocation.Text.Trim() == "")
            {
                MessageBox.Show("กรุณาป้อนสถานที่คลังสินค้าก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtLocation.Focus();
                return;
            }
            if (MessageBox.Show("คุณต้องการเพิ่มคลังสินค้าใหม่ ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                try
                {

                    WareHouse wareHouse = serviceWarahouse.getByCode(txtWareHouseID.Text.Trim());
                    if (wareHouse == null)
                    {
                        WareHouse newWareHouse = new WareHouse();
                        newWareHouse.WHCode = txtWareHouseID.Text.Trim();
                        newWareHouse.WHName = txtWareHouseName.Text.Trim();
                        newWareHouse.WHLocation = txtLocation.Text.Trim();
                        bool saveWareHouse = serviceWarahouse.Save(newWareHouse);
                        if (saveWareHouse)
                        {
                            MessageBox.Show("เพิ่มคลังสินค้า เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            loadData();
                        }
                        else
                        {
                            MessageBox.Show("ไม่สามารถ เพิ่มคลังสินค้าใหม่ได้!!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        }
                    }
                    else
                    {

                        MessageBox.Show("มีคลังสินค้านี้อยู่แล้ว!!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show("ไม่สามารถ เพิ่มคลังสินค้าได้ เนื่องจาก !!! : " + ex.Message, "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }

            }
        }
Exemple #2
0
 public bool Update(WareHouse updateWareHouse)
 {
     int TempId =  dc.UpdateWareHouse(updateWareHouse);
     if (TempId > 0)
     {
         return true;
     }
     return false;
 }
Exemple #3
0
 public bool Save(WareHouse newWareHouse)
 {
     int TempId =  dc.CreateWareHouse(newWareHouse);
     if (TempId > 0)
     {
         return true;
     }
     return false;
 }
        public int CreateWareHouse(WareHouse newWareHouse)
        {
            int result = -1;
            try
            {
                Conn = db.openConnAccess();
                tr = Conn.BeginTransaction();

                sb = new StringBuilder();

                sb.Remove(0, sb.Length);
                sb.Append("INSERT INTO tbWareHouse(WHCode,WHName,WHLocation)");
                sb.Append(" VALUES (@WHCode,@WHName,@WHLocation)");

                string sqlSave;
                sqlSave = sb.ToString();

                com = new OleDbCommand();
                com.Connection = Conn;
                com.CommandText = sqlSave;
                com.Transaction = tr;
                com.Parameters.Clear();
                com.Parameters.Add("@WHCode", OleDbType.VarChar).Value = newWareHouse.WHCode;
                com.Parameters.Add("@WHName", OleDbType.VarChar).Value = newWareHouse.WHName;
                com.Parameters.Add("@WHLocation", OleDbType.VarChar).Value = newWareHouse.WHLocation;
                com.ExecuteNonQuery();
                tr.Commit();

                result = 1;

            }
            catch (Exception ex)
            {
                tr.Rollback();
                Conn.Close();
                return result;
                throw ex;

            }
            finally
            {
                Conn.Close();
            }

            return result;
        }
        public void loadDefault()
        {
            WareHouse servicewareHouse = new WareHouse();
            IList<WareHouse> warehouses = servicewareHouse.getWareHouseAll();

            cbowarhouse.BeginUpdate();
            cbowarhouse.DisplayMember = "WHName";
            cbowarhouse.ValueMember = "WHCode";
            cbowarhouse.DataSource = warehouses;
            cbowarhouse.EndUpdate();

            Category servicCategory = new Category();
            IList<Category> categorys = servicCategory.getCategoryAll();

            cbocategory.BeginUpdate();
            cbocategory.DisplayMember = "CategoryName";
            cbocategory.ValueMember = "CategoryCode";
            cbocategory.DataSource = categorys;
            cbocategory.EndUpdate();
        }
Exemple #6
0
        private void frmSale_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;

            lsvProductList.Columns.Add("รหัสสินค้า", 90, HorizontalAlignment.Left);
            lsvProductList.Columns.Add("ชื่อสินค้า", 220, HorizontalAlignment.Left);
            lsvProductList.Columns.Add("ราคา", 80, HorizontalAlignment.Right);
            lsvProductList.Columns.Add("จำนวน", 80, HorizontalAlignment.Right);
            lsvProductList.Columns.Add("รวมเป็นเงิน", 115, HorizontalAlignment.Right);
            lsvProductList.View = View.Details;
            lsvProductList.GridLines = true;

            IList<Province> provinces = new List<Province>();
            provinces = pv.getAll();

            cboProvince.BeginUpdate();
            cboProvince.DisplayMember = "Name";
            cboProvince.ValueMember = "PRVCode";
            cboProvince.DataSource = provinces;
            cboProvince.EndUpdate();

            WareHouse serviceWareHouse = new WareHouse();
            IList<WareHouse> wareHouses = serviceWareHouse.getWareHouseAll();

            cboWarehouse.BeginUpdate();
            cboWarehouse.DisplayMember = "WHName";
            cboWarehouse.ValueMember = "WHCode";
            cboWarehouse.DataSource = wareHouses;
            cboWarehouse.EndUpdate();

            txtSaleCode.Text = serviceSale.getSaleCode();
        }
Exemple #7
0
        private void frmRent_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;

            lsvProductList.Columns.Add("รหัสสินค้า", 90, HorizontalAlignment.Left);
            lsvProductList.Columns.Add("ชื่อสินค้า", 220, HorizontalAlignment.Left);
            lsvProductList.Columns.Add("จำนวนต่อหน่วย", 120, HorizontalAlignment.Left);
            lsvProductList.Columns.Add("จำนวน", 80, HorizontalAlignment.Right);
            lsvProductList.View = View.Details;
            lsvProductList.GridLines = true;

            txtRN.Text = serviceRent.getRentCode();

            WareHouse serviceWareHouse = new WareHouse();
            IList<WareHouse> wareHouses = serviceWareHouse.getWareHouseAll();

            cboWarehouse.BeginUpdate();
            cboWarehouse.DisplayMember = "WHName";
            cboWarehouse.ValueMember = "WHCode";
            cboWarehouse.DataSource = wareHouses;
            cboWarehouse.EndUpdate();
        }
        public WareHouse getByCode(string _code)
        {
            WareHouse wareHouse = null;

            try
            {
                Conn = db.openConnAccess();

                sb = new StringBuilder();

                sb.Remove(0, sb.Length);
                sb.Append(" SELECT ID,WHCode,WHName,WHLocation FROM tbWareHouse ");
                sb.Append(" WHERE (WHCode='" + _code + "')");
                string sql;
                sql = sb.ToString();

                com = new OleDbCommand();
                com.CommandText = sql;
                com.CommandType = CommandType.Text;
                com.Connection = Conn;
                dr = com.ExecuteReader();
                if (dr.HasRows)
                {

                    DataTable dt = new DataTable();
                    dt.Load(dr);
                    int index = 1;
                    foreach (DataRow drw in dt.Rows)
                    {
                        wareHouse = new WareHouse();
                        wareHouse.ID = Convert.ToInt32(drw["ID"].ToString());
                        wareHouse.Index = Convert.ToString(index);
                        wareHouse.WHCode = drw["WHCode"].ToString();
                        wareHouse.WHName = drw["WHName"].ToString();
                        wareHouse.WHLocation = drw["WHLocation"].ToString();
                    }

                }

                dr.Close();

            }
            catch (Exception ex)
            {
                dr.Close();
                Conn.Close();
                return null;
                throw ex;

            }
            finally
            {
                Conn.Close();
            }

            return wareHouse;
        }
        public int UpdateWareHouse(WareHouse updateWareHouse)
        {
            int result = -1;
            try
            {
                Conn = db.openConnAccess();
                tr = Conn.BeginTransaction();

                sb = new StringBuilder();

                sb.Remove(0, sb.Length);
                sb.Append(" UPDATE tbWareHouse ");
                sb.Append(" SET WHName='" + updateWareHouse.WHName + "',WHLocation='" + updateWareHouse.WHLocation + "'");
                sb.Append(" WHERE (WHCode='" + updateWareHouse.WHCode+ "')");
                string sqlUpdate;
                sqlUpdate = sb.ToString();

                com = new OleDbCommand();
                com.Connection = Conn;
                com.CommandText = sqlUpdate;
                com.Transaction = tr;
                com.Parameters.Clear();
                com.ExecuteNonQuery();
                tr.Commit();

                result = 1;

            }
            catch (Exception ex)
            {
                tr.Rollback();
                Conn.Close();
                return result;
                throw ex;

            }
            finally
            {
                Conn.Close();
            }

            return result;
        }
        public IList<WareHouse> getUnitAll()
        {
            IList<WareHouse> wareHouses = new List<WareHouse>();
            WareHouse wareHouse = null;

            try
            {
                Conn = db.openConnAccess();
                sb = new StringBuilder();

                sb.Remove(0, sb.Length);
                sb.Append(" SELECT ID,WHCode,WHName,WHLocation FROM tbWareHouse order by ID desc");
                // sb.Append(" WHERE (PCode=@PCode)");
                string sql;
                sql = sb.ToString();

                com = new OleDbCommand();
                com.CommandText = sql;
                com.CommandType = CommandType.Text;
                com.Connection = Conn;
                dr = com.ExecuteReader();
                if (dr.HasRows)
                {
                    DataTable dt = new DataTable();
                    dt.Load(dr);
                    int index = 1;
                    foreach (DataRow drw in dt.Rows)
                    {
                        wareHouse = new WareHouse();
                        wareHouse.ID = Convert.ToInt32(drw["ID"].ToString());
                        wareHouse.Index = Convert.ToString(index);
                        wareHouse.WHCode = drw["WHCode"].ToString();
                        wareHouse.WHName= drw["WHName"].ToString();
                        wareHouse.WHLocation = drw["WHLocation"].ToString();
                        wareHouses.Add(wareHouse);
                        index++;

                    }

                }

                dr.Close();

            }
            catch (Exception ex)
            {
                dr.Close();
                Conn.Close();
                return null;
                throw ex;

            }
            finally
            {
                Conn.Close();
            }

            return wareHouses;
        }
Exemple #11
0
        private void frmReturn_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;

            WareHouse serviceWareHouse = new WareHouse();
            IList<WareHouse> wareHouses = serviceWareHouse.getWareHouseAll();

            cboWarehouse.BeginUpdate();
            cboWarehouse.DisplayMember = "WHName";
            cboWarehouse.ValueMember = "WHCode";
            cboWarehouse.DataSource = wareHouses;
            cboWarehouse.EndUpdate();
        }