Beispiel #1
0
        private bool checkWareHouse(Stock stock)
        {
            var         details   = _currentStockOut.StockOutDetails.FirstOrDefault(x => x.StockId.Equals(stock.StoId));
            APWareHouse wareHouse = _unitofwork.APWareHouseRepository.GetById(stock.APWarehouseId);

            if (details != null)
            {
                if (wareHouse != null)
                {
                    if (wareHouse.Contain < (details.Quan + 1))
                    {
                        MessageBox.Show("Doesn't have enough this kind of Stock in Warehouse to take out!");
                        return(false);
                    }
                }
                else
                {
                    MessageBox.Show("Warehouse doen't contain this Stock. Please check again!");
                    return(false);
                }
            }
            else
            {
                if (wareHouse.Contain == 0)
                {
                    MessageBox.Show("Doesn't have enough this kind of Stock in Warehouse to take out!");
                    return(false);
                }
            }

            return(true);
        }
Beispiel #2
0
        /*********************************
        * Form Manipulate
        *********************************/

        private void UpdateAPWareHouseContain()
        {
            foreach (var details in _currentStockOut.StockOutDetails)
            {
                var stock = _stockList.FirstOrDefault(x => x.StoId.Equals(details.StockId));
                if (stock != null)
                {
                    APWareHouse wareHouse = _unitofwork.APWareHouseRepository.GetById(stock.APWarehouseId);
                    if (wareHouse != null)
                    {
                        wareHouse.Contain -= details.Quan * UnitOutTrans.ToUnitContain(stock.UnitOut);
                        _unitofwork.APWareHouseRepository.Update(wareHouse);
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// auto generate id for all entities in Asowell Database
        /// all id type is 10 character and the sign is depend on the type of entity
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        private TEntity AutoGeneteId_DBAsowell(TEntity entity)
        {
            string sign = "";

            if (entity is Employee)
            {
                sign = "EMP";
                // lấy số thứ tự mới nhất
                string numberWantToset = (this.Get().Count() + 1).ToString();

                int    blank  = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length);
                string result = sign;
                for (int i = 0; i < blank; i++)
                {
                    result += "0";
                }
                result += numberWantToset;

                Employee emp = entity as Employee;
                emp.EmpId = result;
            }
            else if (entity is AdminRe)
            {
                sign = "AD";
                // lấy số thứ tự mới nhất
                string numberWantToset = (this.Get().Count() + 1).ToString();

                int    blank  = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length);
                string result = sign;
                for (int i = 0; i < blank; i++)
                {
                    result += "0";
                }
                result += numberWantToset;


                AdminRe admin = entity as AdminRe;
                admin.AdId = result;
            }
            else if (entity is Customer)
            {
                sign = "CUS";
                // lấy số thứ tự mới nhất
                string numberWantToset = (this.Get().Count() + 1).ToString();

                int    blank  = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length);
                string result = sign;
                for (int i = 0; i < blank; i++)
                {
                    result += "0";
                }
                result += numberWantToset;

                Customer cus = entity as Customer;
                cus.CusId = result;
            }
            else if (entity is WareHouse)
            {
                sign = "WAH";
                // lấy số thứ tự mới nhất
                string numberWantToset = (this.Get().Count() + 1).ToString();

                int    blank  = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length);
                string result = sign;
                for (int i = 0; i < blank; i++)
                {
                    result += "0";
                }
                result += numberWantToset;

                WareHouse wh = entity as WareHouse;
                wh.WarehouseId = result;
            }
            else if (entity is Ingredient)
            {
                sign = "IGD";
                // lấy số thứ tự mới nhất
                string numberWantToset = (this.Get().Count() + 1).ToString();

                int    blank  = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length);
                string result = sign;
                for (int i = 0; i < blank; i++)
                {
                    result += "0";
                }
                result += numberWantToset;

                Ingredient ign = entity as Ingredient;
                ign.IgdId = result;
            }
            else if (entity is Product)
            {
                sign = "P";
                // lấy số thứ tự mới nhất
                string numberWantToset = (this.Get().Count() + 1).ToString();

                int    blank  = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length);
                string result = sign;
                for (int i = 0; i < blank; i++)
                {
                    result += "0";
                }
                result += numberWantToset;

                Product p = entity as Product;
                p.ProductId = result;
            }
            else if (entity is ProductDetail)
            {
                sign = "PD";
                // lấy số thứ tự mới nhất
                string numberWantToset = (this.Get().Count() + 1).ToString();

                int    blank  = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length);
                string result = sign;
                for (int i = 0; i < blank; i++)
                {
                    result += "0";
                }
                result += numberWantToset;

                ProductDetail pd = entity as ProductDetail;
                pd.PdetailId = result;
            }
            else if (entity is OrderNote)
            {
                sign = "ORD";
                // lấy số thứ tự mới nhất
                string numberWantToset = (this.Get().Count() + 1).ToString();

                int    blank  = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length);
                string result = sign;
                for (int i = 0; i < blank; i++)
                {
                    result += "0";
                }
                result += numberWantToset;

                OrderNote ord = entity as OrderNote;
                ord.OrdernoteId = result;
            }
            else if (entity is ReceiptNote)
            {
                sign = "RN";
                // lấy số thứ tự mới nhất
                string numberWantToset = (this.Get().Count() + 1).ToString();

                int    blank  = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length);
                string result = sign;
                for (int i = 0; i < blank; i++)
                {
                    result += "0";
                }
                result += numberWantToset;

                ReceiptNote rcn = entity as ReceiptNote;
                rcn.RnId = result;
            }
            else if (entity is SalaryNote)
            {
                sign = "SAN";
                // lấy số thứ tự mới nhất
                string numberWantToset = (this.Get().Count() + 1).ToString();

                int    blank  = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length);
                string result = sign;
                for (int i = 0; i < blank; i++)
                {
                    result += "0";
                }
                result += numberWantToset;

                SalaryNote sln = entity as SalaryNote;
                sln.SnId = result;
            }
            else if (entity is WorkingHistory)
            {
                sign = "WOH";
                // lấy số thứ tự mới nhất
                string numberWantToset = (this.Get().Count() + 1).ToString();

                int    blank  = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length);
                string result = sign;
                for (int i = 0; i < blank; i++)
                {
                    result += "0";
                }
                result += numberWantToset;

                WorkingHistory wh = entity as WorkingHistory;
                wh.WhId = result;
            }


            else if (entity is StockOut)
            {
                sign = "STO";
                // lấy số thứ tự mới nhất
                string numberWantToset = (this.Get().Count() + 1).ToString();

                int    blank  = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length);
                string result = sign;
                for (int i = 0; i < blank; i++)
                {
                    result += "0";
                }
                result += numberWantToset;

                StockOut stkout = entity as StockOut;
                stkout.StockOutId = result;
            }
            else if (entity is StockIn)
            {
                sign = "STI";
                // lấy số thứ tự mới nhất
                string numberWantToset = (this.Get().Count() + 1).ToString();

                int    blank  = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length);
                string result = sign;
                for (int i = 0; i < blank; i++)
                {
                    result += "0";
                }
                result += numberWantToset;

                StockIn stkIn = entity as StockIn;
                stkIn.Si_id = result;
            }
            else if (entity is APWareHouse)
            {
                sign = "APW";
                // lấy số thứ tự mới nhất
                string numberWantToset = (this.Get().Count() + 1).ToString();

                int    blank  = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length);
                string result = sign;
                for (int i = 0; i < blank; i++)
                {
                    result += "0";
                }
                result += numberWantToset;

                APWareHouse wh = entity as APWareHouse;
                wh.APWarehouseId = result;
            }
            else if (entity is Stock)
            {
                sign = "STK";
                // lấy số thứ tự mới nhất
                string numberWantToset = (this.Get().Count() + 1).ToString();

                int    blank  = ID_SIZE_DBASOWELL - (sign.Length + numberWantToset.Length);
                string result = sign;
                for (int i = 0; i < blank; i++)
                {
                    result += "0";
                }
                result += numberWantToset;

                Stock stock = entity as Stock;
                stock.StoId = result;
            }



            return(entity);
        }
Beispiel #4
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //check name
                string name = txtName.Text.Trim();
                if (name.Length == 0)
                {
                    MessageBox.Show("Name is not valid!");
                    txtName.Focus();
                    return;
                }

                //check info
                string info = txtInfo.Text.Trim();
                //check barter code
                string barterCode = txtBarterCode.Text;
                //check barter name
                string barterName = txtBarterName.Text;

                int    group   = (int)cboStockGroup.SelectedItem;
                string unitIn  = cboUnitIn.SelectedItem.ToString();
                string unitOut = cboUnitOut.SelectedItem.ToString();

                //check supplier
                string supplier = txtSupplier.Text;

                //check price
                decimal price = decimal.Parse(txtPrice.Text.Trim());



                APWareHouse newWareHouse = new APWareHouse
                {
                    APWarehouseId   = "",
                    Name            = "",
                    Contain         = 0,
                    StandardContain = 100
                };

                _unitofwork.APWareHouseRepository.Insert(newWareHouse);
                _unitofwork.Save();



                _currentNewStock.APWarehouseId = newWareHouse.APWarehouseId;
                _currentNewStock.Name          = name;
                _currentNewStock.Info          = info;
                _currentNewStock.Group         = group;
                _currentNewStock.BarterCode    = barterCode;
                _currentNewStock.BarterName    = barterName;
                _currentNewStock.UnitIn        = unitIn;
                _currentNewStock.UnitOut       = unitOut;
                _currentNewStock.Supplier      = supplier;
                _currentNewStock.StandardPrice = price;

                _unitofwork.StockRepository.Insert(_currentNewStock);
                _unitofwork.Save();


                MessageBox.Show("Add new stock " + _currentNewStock.Name + "(" + _currentNewStock.StoId + ") successful!");
                clearAllData();

                // refesh data
                ((APWareHouseWindow)Window.GetWindow(this)).Refresh_Tick(null, new EventArgs());
            }
            catch (Exception ex)
            {
                MessageBox.Show("Something went wrong. Can not add new stock. Please check your input again!");
            }
        }