Example #1
0
        public void AddSubStock(Department department)
        {
            // lower range
            long subStockMin = Int64.Parse(department.DepartmentId.ToString().PadRight(4,'0').PadRight(5,'0'));
            // higher range
            long subStockMax = Int64.Parse(department.DepartmentId.ToString().PadRight(4, '0').PadRight(5,'9'));
            ObjectCriteria objectCriteria = new ObjectCriteria();
            objectCriteria.AddBetweenCriteria("DepartmentId",subStockMin,subStockMax );
            var maxId = DepartmentDAO.SelectSpecificType(objectCriteria, Projections.Max("DepartmentId"));
            var departmentId = maxId == null ?  Int64.Parse(department.DepartmentId.ToString().PadRight(4,'0').PadRight(5,'0')) + 1 : (Int64.Parse(maxId.ToString()) + 1);

            department.DepartmentId = departmentId;
            DepartmentDAO.Add(department);
        }
Example #2
0
        public void InformDepartmentStockInSuccess(Department department, DepartmentStockIn stockIn,long stockOutId)
        {
            ServerUtility.Log(logger, department.DepartmentId + " inform stock in back success. ");
            _callbackSubStockList.ForEach(
                 delegate(IDepartmentStockOutCallback callback)
                 {
                     try
                     {
                         callback.NotifyStockInSuccess(department,stockIn,stockOutId);
                     }
                     catch (Exception)
                     {

                     }
                 });
        }
Example #3
0
        public Department Add(Department data)
        {
            var maxId = DepartmentDAO.SelectSpecificType(null, Projections.Max("DepartmentId"));
            var departmentId = maxId == null ? 1 : (Int64.Parse(maxId.ToString()) + 1);
            data.DepartmentId = departmentId;
            if (data.Active == 1)
            {
                DepartmentDAO.SetInActiveAll();
            }

            DepartmentDAO.Add(data);
            IList employees = data.Employees;
            SaveEmployees(employees,departmentId);

            return data;
        }
Example #4
0
        public void ExitDistributingGroup(Department department)
        {
            ServerUtility.Log(logger, department.DepartmentId + " quitting distributing group. ");
            // Unsubscribe the guest from the beer inventory
            IDepartmentStockOutCallback guest = OperationContext.Current.GetCallbackChannel<IDepartmentStockOutCallback>();

            if (_callbackList.Contains(guest))
            {
                ServerUtility.Log(logger, department.DepartmentId + " quit normal group. ");
                _callbackList.Remove(guest);
            }
            if (_callbackSubStockList.Contains(guest))
            {
                ServerUtility.Log(logger, department.DepartmentId + " quit substock group. ");
                _callbackSubStockList.Remove(guest);
            }
        }
Example #5
0
        public Department Add(Department data)
        {
            ObjectCriteria objectCriteria = new ObjectCriteria();
            objectCriteria.AddLesserCriteria("DepartmentId", (long)10000);
            var maxId = DepartmentDAO.SelectSpecificType(objectCriteria, Projections.Max("DepartmentId"));
            var departmentId = maxId == null ? 1 : (Int64.Parse(maxId.ToString()) + 1);
            data.DepartmentId = departmentId;
            if (data.Active == 1)
            {
                DepartmentDAO.SetInActiveAll();
            }

            DepartmentDAO.Add(data);
            IList employees = data.Employees;
            SaveEmployees(employees,departmentId);

            return data;
        }
Example #6
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     Department department = new Department();
     department.DepartmentId = ((Department) cboDepartments.SelectedItem).DepartmentId;
     department.DepartmentName = txtDepartmentName.Text.Trim();
     department.Address = txtAddress.Text.Trim();
     department.CreateDate = DateTime.Now;
     department.UpdateDate = DateTime.Now;
     department.CreateId = ClientInfo.getInstance().LoggedUser.Name;
     department.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
     department.StartDate = dtpCreateDate.Value;
     SalePointEventArgs ea = new SalePointEventArgs();
     ea.SavingSubStock = department;
     EventUtility.fireEvent(SaveDepartmentSubStockEvent,this,ea);
     if(!ea.HasErrors)
     {
         MessageBox.Show("Tạo kho phụ thành công !");
     }
     else
     {
         MessageBox.Show("Có lỗi khi tạo kho phụ. Liên hệ người quản trị");
     }
 }
Example #7
0
 public void Delete(Department data)
 {
     DepartmentDAO.Delete(data);
 }
Example #8
0
        public void Update(Department data)
        {
            if (data.Active == 1)
            {
                DepartmentDAO.SetInActiveAll();
            }

            DepartmentDAO.Update(data);
            if (data.DelFlg != 1)
            {
                SaveEmployees(data.Employees, data.DepartmentId);
            }
        }
Example #9
0
 /// <summary>
 /// Get Current Active Department , return false if HQ department and return true in case any department active
 /// </summary>
 /// <param name="department">Active department need to get</param>
 /// <returns></returns>
 public static bool CurrentActiveDepartment(out Department department)
 {
     department = Get();
     return department.DepartmentId > 0 ? true : false;
 }
        private void ExportDeptStockDefinitionForm_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'masterDB1.stock_def_file' table. You can move, or remove it, as needed.
            //this.stock_def_fileTableAdapter.Fill(this.masterDB1.stock_def_file);
            // TODO: This line of code loads data into the 'masterDB.Department' table. You can move, or remove it, as needed.
            this.departmentTableAdapter.Fill(this.masterDB.Department);
            departmentBindingSource1.Clear();

            Department mainStock = new Department
                                       {
                                           DepartmentId = 0,
                                           DepartmentName = "KHO CHINH"
                                       };
            departmentBindingSource1.Add(mainStock);
            foreach (MasterDB.DepartmentRow row in masterDB.Department)
            {
                Department department = new Department
                                            {
                                                DepartmentId = row.DEPARTMENT_ID,
                                                DepartmentName = row.DEPARTMENT_NAME
                                            };
                departmentBindingSource1.Add(department);
            }
            departmentBindingSource1.ResetBindings(false);
            this.masterDB1.EnforceConstraints = false;
            cboDepartment_SelectedIndexChanged(null, null);
        }
Example #11
0
 public Department LoadDepartment(Department department)
 {
     return DepartmentDAO.LoadDepartment(department);
 }
Example #12
0
        public void JoinDistributingGroup(Department department)
        {
            ServerUtility.Log(logger, department.DepartmentId + " joining the distributing group.");
            // Subscribe the guest to the beer inventory
            IDepartmentStockOutCallback guest = OperationContext.Current.GetCallbackChannel<IDepartmentStockOutCallback>();
            if (department.DepartmentId > 9999)
            {
                if (!_callbackSubStockList.Contains(guest))
                {

                    _callbackSubStockList.Add(guest);
                    guest.NotifyConnected();
                    ServerUtility.Log(logger, department.DepartmentId + " joined the substock group.");
                }
            }
            else
            {
                if (!_callbackList.Contains(guest))
                {
                    _callbackList.Add(guest);
                    ServerUtility.Log(logger, department.DepartmentId + " joined the normal group.");
                    guest.NotifyConnected();
                }
            }
        }
Example #13
0
 private void ShowFormWithActiveDepartment(Form form,Department activeDepartment)
 {
     if (!CurrentDepartment.CurrentActiveDepartment(out activeDepartment))
     {
         MessageBox.Show("Cửa hàng chính chưa được thiết lập! Xin vui lòng thiết lập cửa hàng chính trước.", "Lỗi",
                         MessageBoxButtons.OK);
         form.Close();
     }
     else
     {
         form.Show();
     }
 }
Example #14
0
        /// <summary>
        /// Load exist department and all of employees
        /// </summary>
        /// <param name="department">Department</param>
        /// <returns></returns>
        public Department LoadDepartment(Department department)
        {
            return (Department)
            HibernateTemplate.Execute(
                  delegate(ISession session)
                      {
                            session.Lock(department, LockMode.Read);
                            IList employeesInfo = department.Employees;
                            foreach(EmployeeInfo employeeInfo in employeesInfo)
                            {
                                //Int64 empID = employeeInfo.EmployeeId;
                                Employee employee = employeeInfo.Employee;
                                EmployeePK employeePK = employeeInfo.EmployeePK;
                                //employeeInfo.EmployeeId = employeePK.EmployeeId;
                                employee.EmployeePK = employeePK;
                                employee.EmployeeInfo = employeeInfo;
                                employee.Department = department;

                            }
                        return department;
                      }
                );
        }
Example #15
0
 /// <summary>
 /// Add Department to database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public Department Add(Department data)
 {
     HibernateTemplate.Save(data);
     //HibernateTemplate.Flush();
     return data;
 }
Example #16
0
        public void MakeRawDepartmentStockOut(Department department, DepartmentStockOut stockOut, DepartmentPrice price)
        {
            DataAccessLayer dalSubStock = new DataAccessLayer(Properties.Settings.Default.SubStockDB);
            DataAccessLayer dalSalePoint = new DataAccessLayer(Properties.Settings.Default.SalePointDB);

            //DataAccessLayer dalSalePoint = new DataAccessLayer("achay");

            /*try
            {*/

            try
            {

                DepartmentStockIn stockIn = new FastDepartmentStockInMapper().Convert(stockOut);
                // get max stock in id
                string deptStr = "";
                string extraZero = "";
                string startNum = "";

                if(department.DepartmentId > 999)
                {
                    deptStr = department.DepartmentId.ToString();
                    extraZero = "000";
                    startNum = "001";
                }
                else
                {
                    deptStr = string.Format("{0:000}", department.DepartmentId);
                    extraZero = "00000";
                    startNum = "00001";
                }

                string dateStr = DateTime.Now.ToString("yyMMdd");
                var selectMaxIdSQL = " select max(stock_in_id) from department_stock_in where stock_in_id > '" + dateStr + deptStr + extraZero + "'";

                ServerUtility.Log(logger, selectMaxIdSQL);
                //var maxId = dalSalePoint.GetSingleValue(selectMaxIdSQL);
                var maxId = dalSalePoint.GetSingleValue(selectMaxIdSQL);
                string stockInId = "";
                if(maxId == null || maxId.ToString() == string.Empty)
                {
                    stockInId = dateStr + deptStr + startNum;
                }
                else
                {
                    stockInId = string.Format("{0:00000000000000}", (Int64.Parse(maxId.ToString()) + 1));
                }

                // search in department_stock_in_history
                string selectHistory = " select stock_in_id from department_stock_in_history "
                                       + " where SOURCE_DEPARTMENT_ID = " + stockOut.DepartmentStockOutPK.DepartmentId
                                       + " and stock_out_id = " + stockOut.DepartmentStockOutPK.StockOutId;
                ServerUtility.Log(logger, selectHistory);
                var existStockInId = dalSalePoint.GetSingleValue(selectHistory);
                if (existStockInId == null || existStockInId.ToString() == string.Empty)
                {
                    string insertHistory = " insert into department_stock_in_history(stock_out_id,source_department_id,stock_in_id,dest_department_id,description,create_id,create_date,update_id,update_date ) values( "
                                           + stockOut.DepartmentStockOutPK.StockOutId + ","
                                           + stockOut.DepartmentStockOutPK.DepartmentId + ",'"
                                           + stockInId + "',"
                                           + stockIn.DepartmentStockInPK.DepartmentId + ",'"
                                           + " Xuat hang xuong cua hang " + "',"
                                           + "'admin'" + ","
                                           + "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',"
                                           + "'admin'" + ","
                                           + "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');";
                    ServerUtility.Log(logger, insertHistory);
                    dalSalePoint.ExecuteQuery(insertHistory);
                }
                else
                {
                    InformMessage(stockOut.DepartmentStockOutPK.StockOutId,SUBTODEPT, true,
                    stockOut.DepartmentStockOutPK.StockOutId + " đã đến " + stockOut.OtherDepartmentId + " trước đó. Không thể truyền lại !");
                    return;
                }

                DoStockIn(dalSalePoint, department, stockIn, true);
                InformMessage(stockOut.DepartmentStockOutPK.StockOutId,SUBTODEPT, false,
                    stockOut.DepartmentStockOutPK.DepartmentId +  " đã truyền "+ stockOut.DepartmentStockOutPK.StockOutId +" xuống " + stockOut.OtherDepartmentId + " thành công !");
            }
            catch (Exception exception)
            {
                ServerUtility.Log(logger,exception.Message);
                ServerUtility.Log(logger, exception.StackTrace);
                InformMessage(stockOut.DepartmentStockOutPK.StockOutId,SUBTODEPT, true,
                    stockOut.DepartmentStockOutPK.DepartmentId + " đã truyền " + stockOut.DepartmentStockOutPK.StockOutId + " xuống " + stockOut.OtherDepartmentId + " thất bại !");
            }
        }
Example #17
0
 public static void WriteLastSyncTime(DateTime syncTime,string exportPath,Department department,SyncType syncType)
 {
     DateTime lastSyncTime = DateTime.Now;
     string mark = "_Status";
     if (syncType == SyncType.SyncUp)
     {
         mark += "SyncUp";
     }
     if (syncType == SyncType.SyncDown)
     {
         mark += "SyncDown";
     }
     string lastSyncFile = exportPath + "\\" + department.DepartmentId + mark +".synctime";
     Stream stream = File.Open(lastSyncFile, FileMode.Create);
     BinaryFormatter formatter = new BinaryFormatter();
     formatter.Serialize(stream, syncTime);
     stream.Close();
 }
Example #18
0
        public void MakeRawDepartmentStockIn(Department department, DepartmentStockIn stockIn)
        {
            DataAccessLayer dalSubStock = new DataAccessLayer(Properties.Settings.Default.SubStockDB);
            DataAccessLayer dalSalePoint = new DataAccessLayer(Properties.Settings.Default.SalePointDB);

            try
            {
                DepartmentStockOut stockOut = new FastDepartmentStockOutMapper().Convert(stockIn);
                stockOut.DepartmentStockOutPK = new DepartmentStockOutPK();
                // cheat for stock in back to substock
                stockOut.DepartmentStockOutPK.DepartmentId = stockIn.DepartmentStockInPK.DepartmentId;
                Department subStockDept = new Department
                {
                    DepartmentId = stockIn.DepartmentStockInPK.DepartmentId
                };

                DoStockOut(dalSalePoint, department, stockOut, false);
                DoStockIn(dalSubStock, subStockDept, stockIn, false);

                InformMessage(subStockDept.DepartmentId, DEPTTOSUB, false,
                    subStockDept.DepartmentId + " lấy hàng từ " +
                    department.DepartmentId + " thành công !");
            }
            catch (Exception exception)
            {
                ServerUtility.Log(logger,exception.Message);
                ServerUtility.Log(logger,exception.StackTrace);
                InformMessage(stockIn.DepartmentStockInPK.DepartmentId,DEPTTOSUB,true,exception.Message);
            }
        }
Example #19
0
        public void MakeMultiDepartmentStockOut(Department department, DepartmentStockOut[] stockOutList, DepartmentPrice price)
        {
            ServerUtility.Log(logger, " Xuat hang di " + department.DepartmentId);
            _callbackList.ForEach(
                delegate(IDepartmentStockOutCallback callback)
                {
                    try
                    {
                        // dispatch stock-out to department
                        callback.NotifyNewMultiDepartmentStockOut(department, stockOutList, price);
                    }
                    catch (Exception)
                    {

                    }
                });
        }
Example #20
0
        public void MakeDepartmentStockIn(Department department, DepartmentStockIn stockOut)
        {
            ServerUtility.Log(logger, " Stock-in dispatching from " + department.DepartmentId);
            _callbackList.ForEach(
               delegate(IDepartmentStockOutCallback callback)
               {
                   try
                   {
                       callback.NotifyNewDepartmentStockIn(department, stockOut);
                   }
                   catch (Exception)
                   {

                   }
               });
        }
Example #21
0
        public static string EnsureSyncPath(string path, Department department)
        {
            string ensurePath = path + "\\" + department.DepartmentId;
            bool result = false;

                try
                {
                    if(!Directory.Exists(ensurePath))
                    {
                        Directory.CreateDirectory(ensurePath);
                    }
                    result = true;
                }
                catch (Exception)
                {

                }

            if(result)
            {
                return ensurePath;
            }
            else
            {
                return path;
            }
        }
 public void NotifyUpdateStockOutFlag(Department department, DepartmentStockIn stockIn, long stockOutId)
 {
 }
Example #23
0
 public static DateTime GetLastSyncTime(string exportPath,Department department,SyncType syncType)
 {
     DateTime lastSyncTime = DateTime.MinValue;
     string[] syncTimeFiles = Directory.GetFiles(exportPath, "*.synctime");
     string mark = "_Status";
     if(syncType == SyncType.SyncUp)
     {
         mark += "SyncUp";
     }
     if (syncType == SyncType.SyncDown)
     {
         mark += "SyncDown";
     }
     foreach (string file in syncTimeFiles)
     {
         if(file.IndexOf(department.DepartmentId + mark) >=0 )
         {
             Stream stream = File.OpenRead(file);
             BinaryFormatter formatter = new BinaryFormatter();
             lastSyncTime  = (DateTime)formatter.Deserialize(stream);
             stream.Close();
         }
     }
     return lastSyncTime;
 }
Example #24
0
        public override void FormToModel()
        {
            Department department = SalePointController.DepartmentModel;
            if(department == null)
            {
                department = new Department();
            }

            department.DepartmentId = ObjectConverter.Convert<Int64>(txtDepartmentId.Text);
            department.DepartmentName = txtDepartmentName.Text;
            department.Address = txtAddress.Text;
            department.StartDate = dtpCreateDate.Value;
            department.Employees = bdsEmployeeSource.List as IList;
            department.Active = ObjectConverter.Convert<Int32>(txtActiveDepartment.Text);

            SalePointController.DepartmentModel = department;
        }
Example #25
0
        public void UpdateStockInBackFlag(Department department, DepartmentStockIn stockIn,long stockOutId)
        {
            ServerUtility.Log(logger, " Cap nhat co xuat hang o " + department.DepartmentId);
            _callbackList.ForEach(
                delegate(IDepartmentStockOutCallback callback)
                {
                    try
                    {
                        // update stock out flag in department
                        callback.NotifyUpdateStockOutFlag(department, stockIn,stockOutId);
                    }
                    catch (Exception)
                    {

                    }
                });
        }
Example #26
0
        private bool DoStockIn(DataAccessLayer dal, Department department, DepartmentStockIn stockIn, bool NeedUpdateMasterData)
        {
            string deptStr = "";
            string extraZero = "";
            string startNum = "";
            if (department.DepartmentId > 999)
            {
                deptStr = department.DepartmentId.ToString();
                extraZero = "000";
                startNum = "001";
            }
            else
            {
                deptStr = string.Format("{0:000}", department.DepartmentId);
                extraZero = "00000";
                startNum = "00001";
            }

            string dateStr = DateTime.Now.ToString("yyMMdd");
            var selectMaxIdSQL = " select max(stock_in_id) from department_stock_in where stock_in_id > '" + dateStr + deptStr + extraZero + "'";

            ServerUtility.Log(logger, selectMaxIdSQL);
            var maxId = dal.GetSingleValue(selectMaxIdSQL);
            string stockInId = "";
            if(maxId == null || maxId.ToString() == string.Empty)
            {
                stockInId = dateStr + deptStr + startNum;
            }
            else
            {
                stockInId = string.Format("{0:00000000000000}", (Int64.Parse(maxId.ToString()) + 1));
            }

            string insertStockIn = " insert into department_stock_in(department_id,stock_in_id,stock_in_date,create_date,create_id,update_date,update_id,del_flg,exclusive_key) " +
                                   " values(" +
                                   department.DepartmentId + "," +
                                   "'" + stockInId + "'," +
                                   "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," +
                                   "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," +
                                   "'admin'," +
                                   "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," +
                                   "'admin'," +
                                   "0," +
                                   "1)";
            // insert department-stock-in
            ServerUtility.Log(logger, insertStockIn);
            dal.ExecuteQuery(insertStockIn);
            // insert department-stock-in-details
            foreach (DepartmentStockInDetail inDetail in stockIn.DepartmentStockInDetails)
            {
                if(NeedUpdateMasterData)
                {
                    ProcessStockInDetail(inDetail, dal);
                }

                // insert department-stock-in-detail
                string insertStockInDetail =
                    "insert into department_stock_in_detail(department_id,stock_in_id,product_id,product_master_id,quantity, price, del_flg,create_id,create_date,update_id,update_date) " +
                    " values(" +
                    department.DepartmentId + ",'" +
                    stockInId + "','" +
                    inDetail.Product.ProductId + "','" +
                    inDetail.Product.ProductMaster.ProductMasterId + "'," +
                    inDetail.Quantity + "," +
                    inDetail.Price + "," +
                    "0," +
                    "'admin'," +
                    "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," +
                    "'admin'," +
                    "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')";

                ServerUtility.Log(logger, insertStockInDetail);
                dal.ExecuteQuery(insertStockInDetail);
                // insert department-stock
                //string insertStock = "insert into stock(stock_id,product_id,product_master_id,quantity,create_date,good_quantity,create_id,del_flg) values(18854,'001419317H01','0000000014193',1,'2009-07-27 00:00:00',1,'admin',0)";
                // stock
                string reqDeptStock = "Select product_id from department_stock where product_id ='" +
                                      inDetail.Product.ProductId + "'";
                ServerUtility.Log(logger, reqDeptStock);
                var id = dal.GetSingleValue(reqDeptStock);
                if (id == null || id.ToString() == string.Empty)
                {
                    string insertStock = "insert into department_stock(department_id, product_id, product_master_id, quantity, good_quantity, create_id,create_date,update_id,update_date) values ("
                                         + department.DepartmentId + ", '"
                                         + inDetail.Product.ProductId + "', '"
                                         + inDetail.Product.ProductMaster.ProductMasterId + "', "
                                         + inDetail.Quantity + ", "
                                         + inDetail.Quantity + ", "
                                         + "'admin'," + "'"
                                         + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',"
                                         + "'admin'," + "'"
                                         + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')";

                    ServerUtility.Log(logger, insertStock);
                    dal.ExecuteQuery(insertStock);
                }
                else
                {
                    string updateStock = " update department_stock "
                                         + " set quantity = quantity + " + inDetail.Quantity + " , "
                                         + " good_quantity = good_quantity + " + inDetail.Quantity + " "
                                         + " where product_id = '" + inDetail.Product.ProductId + "' "
                                         + " and department_id = " + department.DepartmentId;
                    ServerUtility.Log(logger, updateStock);
                    dal.ExecuteQuery(updateStock);
                }

            }
            return true;
        }
Example #27
0
 /// <summary>
 /// Update Department to database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public void Update(Department data)
 {
     HibernateTemplate.Execute(
         delegate (ISession session)
             {
                 session.Replicate(data,ReplicationMode.Overwrite);
                 return data;
             }
         );
     //HibernateTemplate.Update(data);
     //HibernateTemplate.Flush();
 }
Example #28
0
        private bool DoStockOut(DataAccessLayer dal, Department department,DepartmentStockOut stockOut,bool negativeStock)
        {
            // check stock before insert
            foreach (DepartmentStockOutDetail outDetail in stockOut.DepartmentStockOutDetails)
            {
                // stock
                var id = dal.GetSingleValue("Select product_id from department_stock where product_id ='" + outDetail.Product.ProductId+"'");
                if (id == null || id.ToString() == string.Empty)
                {
                    // ERROR
                    throw new BusinessException("Khong co ma hang " + outDetail.Product.ProductId + "trong kho cua hang !");
                }
                else
                {
                    if (!negativeStock)
                    {
                        var varQty =
                            dal.GetSingleValue("Select good_quantity from department_stock where product_id ='" +
                                               outDetail.Product.ProductId + "'");
                        long goodQty = 0;
                        Int64.TryParse(varQty.ToString(), out goodQty);
                        long remainGoodQty = goodQty - outDetail.Quantity;
                        if (remainGoodQty < 0)
                        {
                            throw new BusinessException(outDetail.Product.ProductId +
                                                        " không còn đủ số lượng trong kho.");
                        }
                    }
                }

            }
            // get max stock in id

            var selectMaxIdSQL = " select max(stock_out_id) from department_stock_out";
            var maxId = dal.GetSingleValue(selectMaxIdSQL);
            var stockOutId = (maxId == null || maxId.ToString() == string.Empty ) ? 1 : Int64.Parse(maxId.ToString()) + 1;

            var selectMaxDetIdSQL = " select max(stock_out_detail_id) from department_stock_out_detail";
            var maxDetId = dal.GetSingleValue(selectMaxDetIdSQL);
            var stockOutDetId = (maxDetId == null || maxDetId.ToString() == string.Empty) ? 1 : Int64.Parse(maxDetId.ToString()) + 1;

            string insertStockOut = " insert into department_stock_out(department_id," +
                                   "stock_out_id," +
                                   "stock_out_date," +
                                   "description," +
                                   "defect_status_id," +
                                   "confirm_flg," +
                                   "other_department_id," +
                                   "create_date," +
                                   "create_id," +
                                   "update_date," +
                                   "update_id," +
                                   "del_flg," +
                                   "exclusive_key) " +
                                   " values(" + // values
                                   department.DepartmentId + "," +
                                   "'" + stockOutId + "'," +
                                   "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," +
                                   "' Xuat hang ve kho phu ' " + "," +
                                   7 + "," +
                                   0 + "," +
                                   stockOut.DepartmentStockOutPK.DepartmentId + "," +
                                   "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," +
                                   "'admin'," +
                                   "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," +
                                   "'admin'," +
                                   "0," +
                                   "1)";
            // insert department-stock-in
            ServerUtility.Log(logger,insertStockOut);
            dal.ExecuteQuery(insertStockOut);
            // insert department-stock-in-details
            foreach (DepartmentStockOutDetail outDetail in stockOut.DepartmentStockOutDetails)
            {
                //ProcessStockInDetail(inDetail, dalSalePoint);

                // insert department-stock-in-detail
                string insertStockOutDetail =
                    "insert into department_stock_out_detail(stock_out_detail_id," +
                    "department_id," +
                    "stock_out_id," +
                    "product_id," +
                    "product_master_id," +
                    "quantity," +
                    " good_quantity," +
                    " del_flg," +
                    "create_id," +
                    "create_date," +
                    "update_id," +
                    "update_date) " +
                    " values(" + // values
                    stockOutDetId + "," +
                    department.DepartmentId + "," +
                    stockOutId + ",'" +
                    outDetail.Product.ProductId + "','" +
                    outDetail.Product.ProductMaster.ProductMasterId + "'," +
                    outDetail.Quantity + "," +
                    outDetail.Quantity + "," +
                    "0," +
                    "'admin'," +
                    "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," +
                    "'admin'," +
                    "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')";
                ServerUtility.Log(logger,insertStockOutDetail);
                dal.ExecuteQuery(insertStockOutDetail);
                stockOutDetId += 1;
                // insert department-stock
                //string insertStock = "insert into stock(stock_id,product_id,product_master_id,quantity,create_date,good_quantity,create_id,del_flg) values(18854,'001419317H01','0000000014193',1,'2009-07-27 00:00:00',1,'admin',0)";
                // stock
                dal.ExecuteQuery(" update department_stock "
                              + " set quantity = quantity - " + outDetail.Quantity + " , "
                              + " good_quantity = good_quantity - " + outDetail.Quantity + " "
                              + " where product_id = '" + outDetail.Product.ProductId + "' "
                              + " and department_id = " + department.DepartmentId);

            }

            return true;
        }
Example #29
0
 /// <summary>
 /// Delete Department from database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public void Delete(Department data)
 {
     HibernateTemplate.Delete(data);
 }
 public void NotifyStockInSuccess(Department department, DepartmentStockIn stockIn, long stockOutId)
 {
 }