private void SaveLots(TranDetail entityDetail, TranHead entityTranHead)
        {
            //get in_material
            Material entityMaterial = new Material() { material_id = entityDetail.material_id };
            entityMaterial = ServiceProvider.MaterialService.FindByKeys(entityMaterial, false);

            //update into in_phy_lot
            PhyLot entityPhyLot = ServiceProvider.PhyLotService.GetPhyLot(entityDetail.material_id, entityDetail.warehouse_id_dest, entityDetail.lot_no.Value);
            entityPhyLot.bal_qty = (entityPhyLot.bal_qty + entityDetail.quantity.Value);
            entityPhyLot.expire_date = entityTranHead.transaction_date.AddDays(entityMaterial.shelf_life);
            ServiceProvider.PhyLotService.Update(entityPhyLot);

            //update into in_log_lot
            LogLot entityLogLot = ServiceProvider.LogLotService.GetLogLot(entityDetail.material_id, entityDetail.warehouse_id_dest);
            entityLogLot.bal_qty = (entityLogLot.bal_qty + entityDetail.quantity.Value);
            ServiceProvider.LogLotService.Update(entityLogLot);
        }
        private void SaveTransactionDetail(TranHead entityTranHead)
        {
            foreach (DataRow dr in this.dsTranDetail.Tables[0].Rows)
            {
                TranDetail entityDetail = new TranDetail();
                if (dr.RowState == DataRowState.Added)
                {
                    entityDetail.material_id = dr["material_id"].ToLong();
                    entityDetail.warehouse_id_dest = dr["warehouse_id_dest"].ToLong();
                    entityDetail.quantity = dr["Quantity"].ToDecimal();
                    entityDetail.remark = dr["Remark"].ToStringNullable();
                    entityDetail.lot_no = dr["Lot No."].ToDecimal();
                    entityDetail.tran_head_id = entityTranHead.tran_head_id;

                    ServiceProvider.TranDetailService.Insert(entityDetail);
                    SaveLots(entityDetail, entityTranHead);
                }
            }
        }
        private TranDetail GetDetailData()
        {
            TranDetail entity = new TranDetail();            
            entity.material_id = Converts.ParseLong(txtMaterialCode.Text.ToString());
            entity.lot_no = Converts.ParseDecimalNullable(txtLotNo.Text);
            entity.quantity = Converts.ParseDecimalNullable(txtQuantity.Text);
            entity.remark = txtRemarkDetails.Text;

            if (base.FormMode == ObjectState.Add)
            {
                entity.created_by = "SYSTEM";
                entity.created_date = DateTime.Now;
            }
            entity.updated_by = "SYSTEM";
            entity.updated_date = DateTime.Now;
            return entity;
        }
        private void ValidationDetail(TranDetail entity)
        {
            ValidationResults results = new ValidationResults();
            if (baseGridDetail.FormMode == ObjectState.Add)
            {
                if (entity.material_id == 0)
                {
                    ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Material"), this, string.Empty, string.Empty, null);
                    results.AddResult(result);
                }
                else
                {
                    if (entity.warehouse_id_dest != 0)
                    {
                        DataRow[] drs = this.GetDataRowDetail(entity.material_id, entity.warehouse_id_dest);
                        if (drs.Count() >= 1)
                        {
                            ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsDuplicate, "Material"), this, string.Empty, string.Empty, null);
                            results.AddResult(result);
                        }
                    }
                }

                if (entity.warehouse_id_dest == 0)
                {
                    ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Warehouse"), this, string.Empty, string.Empty, null);
                    results.AddResult(result);
                }
            }

            if (string.IsNullOrEmpty(txtLotNo.Text))
            {
                ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Lot No."), this, string.Empty, string.Empty, null);
                results.AddResult(result);
            }
            else if (Converts.ParseDoubleNullable(txtLotNo.Text) == null)
            {
                ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IncorrectFormatOne, "Lot No."), this, string.Empty, string.Empty, null);
                results.AddResult(result);
            }
            else if (entity.lot_no == 0)
            {
                ValidationResult result = new ValidationResult(string.Format(ErrorMessage.CompareValueMore, "Lot No.", "0"), this, string.Empty, string.Empty, null);
                results.AddResult(result);
            }

            if (string.IsNullOrEmpty(txtQuantity.Text))
            {
                ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Quantity"), this, string.Empty, string.Empty, null);
                results.AddResult(result);
            }
            else if (Converts.ParseDoubleNullable(txtQuantity.Text) == null)
            {
                ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IncorrectFormatOne, "Quantity"), this, string.Empty, string.Empty, null);
                results.AddResult(result);
            }
            else if (entity.quantity == 0)
            {
                ValidationResult result = new ValidationResult(string.Format(ErrorMessage.CompareValueMore, "Quantity", "0"), this, string.Empty, string.Empty, null);
                results.AddResult(result);
            }
            else
            {
                if (entity.warehouse_id_dest != 0 && entity.material_id != 0)
                {
                    if (!ServiceProvider.PhyLotService.CheckLimitMaterial(entity.material_id, entity.warehouse_id_dest, entity.quantity.Value))
                    {
                        ValidationResult result = new ValidationResult(string.Format(ErrorMessage.CompareValueLessOrEqual, "Quantity", "Max Stock"), this, string.Empty, string.Empty, null);
                        results.AddResult(result);
                    }
                }
            }

            if (results.Count > 0) { throw new ValidationException(results); }
        }
        private TranDetail GetDetailData()
        {
            TranDetail entity = new TranDetail();
            entity.material_id = ServiceProvider.MaterialService.GetIDByCode(txtMaterialCode.Text).ToLong();
            entity.warehouse_id_dest = Converts.ParseLong(ddlWarehouseDetails.SelectedValue.ToString());
            entity.lot_no = Converts.ParseDecimalNullable(txtLotNo.Text);
            entity.quantity = Converts.ParseDecimalNullable(txtQuantity.Text);
            entity.remark = txtRemarkDetails.Text;

            if (base.FormMode == ObjectState.Add)
            {
                entity.created_by = "SYSTEM";
                entity.created_date = DateTime.Now;
            }
            entity.updated_by = "SYSTEM";
            entity.updated_date = DateTime.Now;
            return entity;
        }