Пример #1
0
        /// <summary>
        /// Thêm một chức vụ
        /// </summary>
        /// <param name="dsPosition"></param>
        /// <returns></returns>
        public int AddPosition(DataSet dsPosition)
        {
            conn                   = WorkingContext.GetConnection();
            sqlCommand             = new SqlCommand("AddPosition", conn);
            sqlCommand.CommandType = CommandType.StoredProcedure;

            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@PositionName", SqlDbType.NVarChar, "PositionName"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Description", SqlDbType.NVarChar, "Description"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@PositionShortName", SqlDbType.NVarChar, "PositionShortName"));

            SqlParameter result = new SqlParameter("@ReturnValue", SqlDbType.Int);

            result.Direction = ParameterDirection.ReturnValue;
            sqlCommand.Parameters.Add(result);

            dataAdapter = new SqlDataAdapter();
            dataAdapter.InsertCommand = sqlCommand;

            try
            {
                conn.Open();
                dataAdapter.Update(dsPosition.Tables[0]);
                return((int)result.Value);
            }

            catch (Exception oException)
            {
                //				throw oException;
                MessageBox.Show(oException.ToString());
                return(0);
            }

            finally
            {
                conn.Close();
            }
        }
Пример #2
0
        /// <summary>
        /// Thêm mới kiểu ngày
        /// </summary>
        /// <param name="dsDayType"></param>
        /// <returns></returns>
        public int AddDayTypeDO(DataSet dsDayType)
        {
            conn                   = WorkingContext.GetConnection();
            sqlCommand             = new SqlCommand("AddDayType", conn);
            sqlCommand.CommandType = CommandType.StoredProcedure;
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@DayName", SqlDbType.NVarChar, "DayName"));
//			sqlCommand.Parameters.Add(WorkingContext.CreateParam("@DayColor",SqlDbType.VarChar,"DayColor"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@DayFactor", SqlDbType.Float, "DayFactor"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@DayShortName", SqlDbType.VarChar, "DayShortName"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@InsuranceCheck", SqlDbType.Bit, "InsuranceCheck"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@InsuranceFactor", SqlDbType.Float, "InsuranceFactor"));
//			sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Quantity",SqlDbType.Int,"Quantity"));

            SqlParameter result = new SqlParameter("@ReturnValue", SqlDbType.Int);

            result.Direction = ParameterDirection.ReturnValue;
            sqlCommand.Parameters.Add(result);

            dadapter = new SqlDataAdapter();
            dadapter.InsertCommand = sqlCommand;
            try
            {
                conn.Open();
                dadapter.Update(dsDayType, "tblDayType");
                return((int)result.Value);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(0);
            }
            finally
            {
                conn.Dispose();
                conn.Close();
            }
        }
Пример #3
0
        private void CreateWorkingContextHierarchy()
        {
            m_BusinessLogicApplicationContext = new WorkingContext(false,
                                                                   WorkingContextEnvironment.Application,
                                                                   AppId,
                                                                   "Project"
                                                                   );

            m_BusinessLogicApplicationContext.ConstructServiceEvent           += m_BusinessLogicApplicationContext_ConstructServiceEvent;
            m_BusinessLogicApplicationContext.ServiceLoadedEvent              += m_BusinessLogicApplicationContext_ServiceLoadedEvent;
            m_BusinessLogicApplicationContext.ServiceAddedEvent               += m_BusinessLogicApplicationContext_ServiceAddedEvent;
            m_BusinessLogicApplicationContext.WorkingContextChildCreatedEvent += M_BusinessLogicApplicationContext_WorkingContextChildCreatedEvent;

            m_BusinessLogicApplicationContext.AutoLoadDlcs();

            WorkingContextProxy      wcp = new WorkingContextProxy(m_BusinessLogicApplicationContext);
            PlatformServiceContainer psc = wcp.PlatformServiceContainer;

            m_ViewApplicationContext = new WorkingContext(true,
                                                          WorkingContextEnvironment.Application,
                                                          AppId,
                                                          "Project"
                                                          );
            m_ViewApplicationContext.SiblingInBusinessLogicContext = m_BusinessLogicApplicationContext;

            m_ViewApplicationContext.ConstructServiceEvent += M_ViewApplicationContext_ConstructServiceEvent;
            m_ViewApplicationContext.ServiceLoadedEvent    += M_ViewApplicationContext_ServiceLoadedEvent;
            m_ViewApplicationContext.ServiceAddedEvent     += M_ViewApplicationContext_ServiceAddedEvent;
            m_ViewApplicationContext.AutoLoadDlcs();

            PersistenceWorkingContext = new WorkingContext(m_ViewApplicationContext,
                                                           WorkingContextEnvironment.Persistence);

            PrimaryProjectUiWorkingContextManagerProxy = m_ViewApplicationContext.GetPrimaryProjectUiWorkingContextManagerProxy();
            PrimaryProjectManagerProxy =
                PrimaryProjectUiWorkingContextManagerProxy.PrimaryProjectManager;
        }
Пример #4
0
        public DataSet GetAttendRecordNew(int DepartmentID, DateTime Month)
        {
            SqlConnection conn = WorkingContext.GetConnection();
            // Build the command
            SqlCommand command = new SqlCommand();

            // Adapter and DataSet
            SqlDataAdapter dataAdapter = new SqlDataAdapter();

            dataAdapter.SelectCommand = command;
            command.Connection        = conn;
            command.CommandType       = CommandType.StoredProcedure;
            // Build the command
            command.CommandText = "GetAttendanceRecord_New";
            command.Parameters.Add(new SqlParameter("@DepartmentID", SqlDbType.Int)).Value = DepartmentID;
            command.Parameters.Add(new SqlParameter("@Month", SqlDbType.DateTime)).Value   = Month;
            // Adapter and DataSet
            DataSet dataSet = new DataSet();

            try
            {
                conn.Open();
                dataAdapter.Fill(dataSet);
            }

            catch (Exception oException)
            {
                MessageBox.Show(oException.ToString());
                return(null);
            }
            finally
            {
                conn.Close();
            }
            return(dataSet);
        }
Пример #5
0
        /// <summary>
        /// Lấy danh sách các nhân viên của một phòng ban
        /// </summary>
        /// <param name="DepartmentID">Mã phòng ban</param>
        /// <returns>Thông tin các nhân viên trong phòng ban</returns>
        public DataSet GetDepEmployees(int DepartmentID)
        {
            SqlConnection conn = WorkingContext.GetConnection();
            // Build the command
            string strSQL = "SELECT * FROM tblEmployee";

            if (DepartmentID != 1)
            {
                strSQL += " WHERE DepartmentID = " + DepartmentID;
            }

            SqlCommand sqlCommand = new SqlCommand(strSQL, conn);

            // Adapter and DataSet
            SqlDataAdapter dataAdapter = new SqlDataAdapter();

            dataAdapter.SelectCommand = sqlCommand;
            DataSet dataSet = new DataSet();

            try
            {
                conn.Open();
                dataAdapter.Fill(dataSet, "tblEmployee");
                return(dataSet);
            }

            catch (Exception oException)
            {
                MessageBox.Show(oException.ToString());
                return(null);
            }
            finally
            {
                conn.Close();
            }
        }
Пример #6
0
        /// <summary>
        /// Tính số ngày nghỉ thực tế được đăng ký
        /// </summary>
        /// <param name="iEmployeeIDPara">ID nhân viên</param>
        /// <param name="dtStartRestPara">Ngày bắt đầu nghỉ</param>
        /// <param name="dtEndRestPara">Ngày kết thúc nghỉ</param>
        /// <param name="fNumDayPara">Thời gian nghỉ (sáng/chiều/cả ngày)</param>
        /// <returns></returns>
        public float GetCurrentRest(int iEmployeeIDPara, DateTime dtStartRestPara, DateTime dtEndRestPara, float fNumDayPara)
        {
            float fCurrentRestPri = -1;

            con             = WorkingContext.GetConnection();
            com             = new SqlCommand("GetCurrentRestOfEmployee", con);
            com.CommandType = CommandType.StoredProcedure;

            com.Parameters.Clear();
            com.Parameters.Add(new SqlParameter("@EmployeeID", SqlDbType.Int)).Value     = iEmployeeIDPara;
            com.Parameters.Add(new SqlParameter("@StartRest", SqlDbType.DateTime)).Value = dtStartRestPara;
            com.Parameters.Add(new SqlParameter("@EndRest", SqlDbType.DateTime)).Value   = dtEndRestPara;
            com.Parameters.Add(new SqlParameter("@NumDay", SqlDbType.Float)).Value       = fNumDayPara;

            try
            {
                con.Open();
                SqlDataReader reader = com.ExecuteReader();
                while (reader.Read())
                {
                    fCurrentRestPri = Convert.ToSingle(reader["TotalRest"]);
                }
                reader.Close();

                return(fCurrentRestPri);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(-1);
            }
            finally
            {
                con.Close();
            }
        }
Пример #7
0
        public int AddGroupPermission(string UserGroupID, int PermissionID)
        {
            conn = WorkingContext.GetConnection();

            sqlCommand             = new SqlCommand("HT_AddGroupPermission", conn);
            sqlCommand.CommandType = CommandType.StoredProcedure;
            sqlCommand.Parameters.Add(new SqlParameter("@UserGroupID", UserGroupID));
            sqlCommand.Parameters.Add(new SqlParameter("@PermissionID", PermissionID));

            try
            {
                conn.Open();
                return(sqlCommand.ExecuteNonQuery());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(0);
            }
            finally
            {
                conn.Close();
            }
        }
Пример #8
0
        /// <summary>
        /// Xoa ca lam them
        /// </summary>
        /// <param name="dataSet"></param>
        /// <returns></returns>
        public int DeleteShiftOver(DataSet dataSet)
        {
            SqlConnection conn = WorkingContext.GetConnection();
            // Build the command
            SqlCommand sqlCommand = new SqlCommand("DeleteShiftOver", conn);

            sqlCommand.CommandType = CommandType.StoredProcedure;

            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@ShiftOverID", SqlDbType.Int, "ShiftOverID"));

            SqlParameter result = new SqlParameter("@ReturnValue", SqlDbType.Int);

            result.Direction = ParameterDirection.ReturnValue;
            sqlCommand.Parameters.Add(result);

            SqlDataAdapter dataAdapter = new SqlDataAdapter();

            dataAdapter.DeleteCommand = sqlCommand;

            try
            {
                conn.Open();
                dataAdapter.Update(dataSet.Tables[0]);
                return((int)result.Value);
            }
            catch (Exception oException)
            {
                MessageBox.Show(oException.ToString());
                return(0);
            }
            finally
            {
                conn.Dispose();
                conn.Close();
            }
        }
Пример #9
0
        public int ChangePass(DataSet dataSet)
        {
            conn = WorkingContext.GetConnection();

            sqlCommand             = new SqlCommand("ChangePass", conn);
            sqlCommand.CommandType = CommandType.StoredProcedure;
            //sqlCommand.Parameters.Add(new SqlParameter("@UserID", SqlDbType.Int, 4, "UserID"));
            sqlCommand.Parameters.Add(new SqlParameter("@UserName", SqlDbType.VarChar, 30, "UserName"));
            sqlCommand.Parameters.Add(new SqlParameter("@Password", SqlDbType.VarChar, 30, "Password"));
            //sqlCommand.Parameters.Add(new SqlParameter("@UserGroupID", SqlDbType.VarChar, 10, "UserGroupID"));
            //sqlCommand.Parameters.Add(new SqlParameter("@CardID", SqlDbType.VarChar, 10, "CardID"));

            SqlParameter result = new SqlParameter("@ReturnValue", SqlDbType.Int);

            result.Direction = ParameterDirection.ReturnValue;
            sqlCommand.Parameters.Add(result);

            dataAdapter = new SqlDataAdapter();
            dataAdapter.UpdateCommand = sqlCommand;

            try
            {
                conn.Open();
                dataAdapter.Update(dataSet.Tables[0]);
                return((int)result.Value);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(0);
            }
            finally
            {
                conn.Close();
            }
        }
Пример #10
0
        /// <summary>
        /// Lấy thông tin trạng thái nhân viên
        /// </summary>
        /// <param name="DepartmentID">Mã phòng ban</param>
        /// <param name="Date">Ngày kiểm tra</param>
        /// <returns></returns>
        public DataSet GetEmployeeStatus(int DepartmentID, DateTime Date, int Order, int PageIndex, int PageSize)
        {
            SqlConnection conn = WorkingContext.GetConnection();
            // Build the command
            SqlCommand sqlCommand = new SqlCommand("GetEmployeeStatus", conn);

            sqlCommand.CommandType = CommandType.StoredProcedure;
            sqlCommand.Parameters.Add(new SqlParameter("@DepartmentID", DepartmentID));
            sqlCommand.Parameters.Add(new SqlParameter("@Date", Date));
            sqlCommand.Parameters.Add(new SqlParameter("@Order", Order));
            sqlCommand.Parameters.Add(new SqlParameter("@PageIndex", PageIndex));
            sqlCommand.Parameters.Add(new SqlParameter("@PageSize", PageSize));

            SqlDataAdapter dataAdapter = new SqlDataAdapter();

            dataAdapter.SelectCommand = sqlCommand;

            DataSet dataSet = new DataSet();

            try
            {
                conn.Open();
                dataAdapter.Fill(dataSet, "GetEmployeeStatus");
                return(dataSet);
            }
            catch (Exception oException)
            {
                MessageBox.Show("SqlException: Timeout expired.", "Message");
                return(null);
            }
            finally
            {
                conn.Dispose();
                conn.Close();
            }
        }
Пример #11
0
        /// <summary>
        /// Cập nhật thông về lịch công tác của một nhân viên
        /// </summary>
        /// <param name="dsLeaveSchedule"></param>
        /// <returns></returns>
        public int UpdateLeaveSchedule(DataSet dsLeaveSchedule)
        {
            conn                   = WorkingContext.GetConnection();
            sqlCommand             = new SqlCommand("UpdateLeaveSchedule", conn);
            sqlCommand.CommandType = CommandType.StoredProcedure;

            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@LeaveID", SqlDbType.Int, "LeaveID"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@EmployeeID", SqlDbType.Int, "EmployeeID"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@LeaveLocation", SqlDbType.NVarChar, "LeaveLocation"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@WorkInfo", SqlDbType.NVarChar, "WorkInfo"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@StartLeave", SqlDbType.DateTime, "StartLeave"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@EndLeave", SqlDbType.DateTime, "EndLeave"));
            SqlParameter result = new SqlParameter("ReturnValue", SqlDbType.Int);

            result.Direction = ParameterDirection.ReturnValue;
            sqlCommand.Parameters.Add(result);
            dadapter = new SqlDataAdapter();
            dadapter.UpdateCommand = sqlCommand;

            try
            {
                conn.Open();
                dadapter.Update(dsLeaveSchedule.Tables[0]);
                return((int)result.Value);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(0);
            }
            finally
            {
                conn.Dispose();
                conn.Close();
            }
        }
Пример #12
0
 public WorkingContextProxy(IWorkingContext wc)
 {
     WC = wc as WorkingContext;
 }
Пример #13
0
        /// <summary>
        /// Cap nhat thong tin cong ty
        /// </summary>
        /// <param name="name"></param>
        /// <param name="address"></param>
        /// <param name="city"></param>
        /// <param name="country"></param>
        /// <param name="tel"></param>
        /// <param name="fax"></param>
        /// <param name="email"></param>
        /// <param name="website"></param>
        /// <param name="taxcode"></param>
        /// <param name="banhkName"></param>
        /// <param name="bankAccount"></param>
        /// <param name="foundedDay"></param>
        /// <param name="note"></param>
        /// <param name="healthInsuranceID"></param>
        /// <param name="CompanyCode"></param>
        /// <returns></returns>
        public int UpdateDefaultCompanyInfo(string name, string address, string city, string country, string tel, string fax, string email, string district,
                                            string website, string taxcode, string banhkName, string bankAccount, DateTime foundedDay, string note, string healthInsuranceID, string @CompanyCode)
        //int companyType, bool inactive, bool defaultCompany,
        {
            SqlConnection conn = WorkingContext.GetConnection();

            SqlCommand sqlCommand = new SqlCommand("UpdateDefaultCompanyInfo", conn);

            sqlCommand.CommandType = CommandType.StoredProcedure;

            SqlParameter param1 = new SqlParameter("@Name", name);

            sqlCommand.Parameters.Add(param1);

            param1 = new SqlParameter("@Address", address);
            sqlCommand.Parameters.Add(param1);
            param1 = new SqlParameter("@City", city);
            sqlCommand.Parameters.Add(param1);
            param1 = new SqlParameter("@District", district);
            sqlCommand.Parameters.Add(param1);
            param1 = new SqlParameter("@Country", country);
            sqlCommand.Parameters.Add(param1);
            param1 = new SqlParameter("@Tel", tel);
            sqlCommand.Parameters.Add(param1);
            param1 = new SqlParameter("@Fax", fax);
            sqlCommand.Parameters.Add(param1);
            param1 = new SqlParameter("@Email", email);
            sqlCommand.Parameters.Add(param1);
            param1 = new SqlParameter("@Website", website);
            sqlCommand.Parameters.Add(param1);
            param1 = new SqlParameter("@TaxCode", taxcode);
            sqlCommand.Parameters.Add(param1);
            param1 = new SqlParameter("@BankName", banhkName);
            sqlCommand.Parameters.Add(param1);
            param1 = new SqlParameter("@BankAccount", bankAccount);
            sqlCommand.Parameters.Add(param1);
            param1 = new SqlParameter("@FoundedDay", foundedDay);
            sqlCommand.Parameters.Add(param1);
            param1 = new SqlParameter("@Note", note);
            //sqlCommand.Parameters.Add(param1);
            //param1 = new SqlParameter("@CompanyType", companyType);
            //sqlCommand.Parameters.Add(param1);
            //param1 = new SqlParameter("@Inactive", inactive);
            //sqlCommand.Parameters.Add(param1);
            //param1 = new SqlParameter("@DefaultCompany", defaultCompany);
            sqlCommand.Parameters.Add(param1);
            param1 = new SqlParameter("@HealthInsuranceID", healthInsuranceID);
            sqlCommand.Parameters.Add(param1);
            param1 = new SqlParameter("@CompanyCode", CompanyCode);
            sqlCommand.Parameters.Add(param1);

            SqlParameter result = new SqlParameter("@ReturnValue", SqlDbType.Int);

            result.Direction = ParameterDirection.ReturnValue;
            sqlCommand.Parameters.Add(result);
            try
            {
                conn.Open();
                sqlCommand.ExecuteNonQuery();
                return((int)result.Value);
            }

            catch (Exception oException)
            {
                MessageBox.Show(oException.ToString(), "Lỗi cập nhật cơ sở dữ liệu", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(0);
            }
            finally
            {
                conn.Close();
            }
        }
Пример #14
0
        public void Save()
        {
            if (UseDB)
            {
                using var dbContext = new WorkingContext();

                IList <WorkingDay>?days = List
                                          .Model
                                          .Where(d => !(d.Model is null))
                                          .Select(d => d.Model !)
                                          .ToArray();

                if (!(days is null))
                {
                    List <DateTime> inMemoryDays = days
                                                   .Select(d => d.Date)
                                                   .ToList();

                    List <DateTime> dbDays = dbContext
                                             .WorkingDays
                                             .Select(d => d.Date)
                                             .Where(d => inMemoryDays.Contains(d))
                                             .ToList();

                    var groups = days.GroupBy(d => dbDays.Contains(d.Date));

                    Log.Debug("Saving {@InMemoryDays}", inMemoryDays);

                    foreach (var group in groups)
                    {
                        if (group.Key) // already stored in DB
                        {
                            foreach (WorkingDay day in group)
                            {
                                WorkingDayDBModel d = dbContext
                                                      .WorkingDays
                                                      .Include(d => d.Tasks)
                                                      .First(d => day.Date == d.Date);
                                d.Tasks = day
                                          .Tasks
                                          .Select(t => new WorkingTaskDBModel(t))
                                          .ToList();
                            }
                        }
                        else // new
                        {
                            dbContext.AddRange(group.Select(d => new WorkingDayDBModel(d)));
                        }
                    }

                    try
                    {
                        dbContext.SaveChanges();
                    }
                    catch (DbUpdateException e)
                    {
                        Log.Error("{Error}", e);
                    }
                }
            }
        }
Пример #15
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (selectedRowIndex < 0)
            {
                string str  = WorkingContext.LangManager.GetString("frmRegOverTime_Edit_messa");
                string str1 = WorkingContext.LangManager.GetString("frmListRegRest_Delete_Title");
                //MessageBox.Show("Bạn chưa chọn nhân viên nào!", "Xóa đăng ký nghỉ của nhân viên", MessageBoxButtons.OK,  MessageBoxIcon.Error);
                MessageBox.Show(str, str1, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            DialogResult dr = MessageBox.Show("Bạn có thực sự muốn xóa? ", "Xóa đăng ký nghỉ của nhân viên", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dr == DialogResult.Yes)
            {
                SqlConnection  conn     = WorkingContext.GetConnection();
                SqlTransaction trans    = null;
                int            ret      = 0;
                bool           bUpdate  = false;
                bool           bUpdate1 = false;
                int            iDayId   = -1;

                try
                {
                    conn.Open();
                    trans  = conn.BeginTransaction();
                    iDayId = Convert.ToInt32(dsRegRestEmployee.Tables[0].Rows[selectedRowIndex]["DayID"]);
                    int      iEmployeeID = Convert.ToInt32(dsRegRestEmployee.Tables[0].Rows[selectedRowIndex]["EmployeeID"]);
                    DateTime dtStartRest = Convert.ToDateTime(dsRegRestEmployee.Tables[0].Rows[selectedRowIndex]["StartRest"]);
                    DateTime dtEndRest   = Convert.ToDateTime(dsRegRestEmployee.Tables[0].Rows[selectedRowIndex]["EndRest"]);
                    dsRegRestEmployee.Tables[0].Rows[selectedRowIndex].Delete();
                    //Xóa thông tin đăng ký nghỉ của nhân viên
                    ret = regRestEmployee.DeleteRegRestEmployee(dsRegRestEmployee, trans);
                    //Cập nhật lại số ngày nghỉ phép của nhân viên nếu là xóa đăng ký nghỉ phép
                    if (ret == 1 && (iDayId == 200 || iDayId == 219))
                    {
                        if (dtStartRest.Month == dtEndRest.Month)
                        {
                            bUpdate = regRestEmployee.UpdateRestSheetEmployee(iEmployeeID, dtStartRest, dtEndRest, dtStartRest, iDayId, trans);
                        }
                        else
                        {
                            bUpdate = regRestEmployee.UpdateRestSheetEmployee(iEmployeeID, dtStartRest, dtEndRest, dtStartRest, iDayId, trans);
                            bUpdate = regRestEmployee.UpdateRestSheetEmployee(iEmployeeID, dtStartRest, dtEndRest, dtEndRest, iDayId, trans);
                        }
                    }
                    dsRegRestEmployee.AcceptChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    if (trans != null)
                    {
                        trans.Rollback();
                    }
                    trans.Dispose();
                    return;
                }

                bool bResultPri = false;
                if (iDayId != 200 && iDayId != 219)
                {
                    if (ret == 1)
                    {
                        bResultPri = true;
                    }
                }
                else
                {
                    if (ret == 1 && bUpdate)
                    {
                        bResultPri = true;
                    }
                }
                if (bResultPri)
                {
                    trans.Commit();
                    trans.Dispose();
                }
                else
                {
                    trans.Rollback();
                    trans.Dispose();
                }

                PopulateRestEmployee();
            }
            selectedRowIndex = -1;
            tableModel1.Selections.Clear();
        }
Пример #16
0
        /// <summary>
        /// Cập nhật bảng ăn trưa tháng
        /// </summary>
        /// <param name="dataSet"></param>
        /// <returns></returns>
        public int UpdateLunchSheet(DataSet dataSet)
        {
            SqlConnection conn = WorkingContext.GetConnection();
            // Build the command
            SqlCommand sqlCommand = new SqlCommand("UpdateLunchSheet", conn);

            sqlCommand.CommandType = CommandType.StoredProcedure;

            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Month", SqlDbType.Int, "Month"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Year", SqlDbType.Int, "Year"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@EmployeeID", SqlDbType.Int, "EmployeeID"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day1", SqlDbType.VarChar, "Day1"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day2", SqlDbType.VarChar, "Day2"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day3", SqlDbType.VarChar, "Day3"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day4", SqlDbType.VarChar, "Day4"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day5", SqlDbType.VarChar, "Day5"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day6", SqlDbType.VarChar, "Day6"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day7", SqlDbType.VarChar, "Day7"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day8", SqlDbType.VarChar, "Day8"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day9", SqlDbType.VarChar, "Day9"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day10", SqlDbType.VarChar, "Day10"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day11", SqlDbType.VarChar, "Day11"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day12", SqlDbType.VarChar, "Day12"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day13", SqlDbType.VarChar, "Day13"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day14", SqlDbType.VarChar, "Day14"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day15", SqlDbType.VarChar, "Day15"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day16", SqlDbType.VarChar, "Day16"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day17", SqlDbType.VarChar, "Day17"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day18", SqlDbType.VarChar, "Day18"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day19", SqlDbType.VarChar, "Day19"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day20", SqlDbType.VarChar, "Day20"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day21", SqlDbType.VarChar, "Day21"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day22", SqlDbType.VarChar, "Day22"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day23", SqlDbType.VarChar, "Day23"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day24", SqlDbType.VarChar, "Day24"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day25", SqlDbType.VarChar, "Day25"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day26", SqlDbType.VarChar, "Day26"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day27", SqlDbType.VarChar, "Day27"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day28", SqlDbType.VarChar, "Day28"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day29", SqlDbType.VarChar, "Day29"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day30", SqlDbType.VarChar, "Day30"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@Day31", SqlDbType.VarChar, "Day31"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@TotalPaidLunch", SqlDbType.Float, "TotalPaidLunch"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@TotalNormalLunch", SqlDbType.Float, "TotalNormalLunch"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@TotalOverTimeLunch", SqlDbType.Float, "TotalOverTimeLunch"));
            sqlCommand.Parameters.Add(WorkingContext.CreateParam("@TotalAllowance", SqlDbType.Float, "TotalAllowance"));

            SqlDataAdapter dataAdapter = new SqlDataAdapter();

            dataAdapter.UpdateCommand = sqlCommand;

            try
            {
                conn.Open();
                return(dataAdapter.Update(dataSet.Tables[0]));
            }
            catch (Exception oException)
            {
                MessageBox.Show(oException.ToString());
                return(0);
            }
            finally
            {
                conn.Dispose();
                conn.Close();
            }
        }
Пример #17
0
        public int DeleteHospital(int HospitalID)
        {
            SqlConnection conn = WorkingContext.GetConnection();

            SqlCommand sqlCommand = new SqlCommand("DeleteHospital", conn);

            sqlCommand.CommandType = CommandType.StoredProcedure;

            SqlParameter param1 = new SqlParameter("@HospitalID", HospitalID);

            sqlCommand.Parameters.Add(param1);

            SqlParameter result = new SqlParameter("@ReturnValue", SqlDbType.Int);

            result.Direction = ParameterDirection.ReturnValue;
            sqlCommand.Parameters.Add(result);
            try
            {
                conn.Open();
                sqlCommand.ExecuteNonQuery();
                return((int)result.Value);
            }

            catch (Exception oException)
            {
                MessageBox.Show(oException.ToString(), "Lỗi cập nhật cơ sở dữ liệu", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(0);
            }
            finally
            {
                conn.Close();
            }

            //SqlConnection conn = WorkingContext.GetConnection();

            //SqlCommand sqlCommand = new SqlCommand("DeleteHospital", conn);
            //sqlCommand.CommandType = CommandType.StoredProcedure;
            //SqlParameter param1 = new SqlParameter("@HospitalID", hospitalID);
            //sqlCommand.Parameters.Add(param1);

            //int result = 0;
            //SqlParameter param2 = new SqlParameter("@Result", result);
            //param2.Direction = ParameterDirection.Output;
            //sqlCommand.Parameters.Add(param2);

            //try
            //{
            //    conn.Open();
            //    return sqlCommand.ExecuteNonQuery();
            //}

            //catch (Exception oException)
            //{
            //    MessageBox.Show(oException.ToString());
            //    return 0;
            //}
            //finally
            //{
            //    conn.Dispose();
            //    conn.Close();
            //}
        }