Ejemplo n.º 1
0
        public ReturnProgramPdtCtrl DeleteByKey(ProgramPdtCtrl p)
        {
            ReturnProgramPdtCtrl returnProgramPdtCtrl = new ReturnProgramPdtCtrl();

            try
            {
                // Gọi vào DB để lấy dữ liệu.
                using (SqlConnection sqlConnection = ConnectSQLCommon.CreateAndOpenSqlConnection())
                {
                    using (SqlCommand cmd = new SqlCommand("", sqlConnection))
                    {
                        cmd.CommandText = "sp_tProgramPdtCtrl_DeleteByKey";
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("@ProgramName", SqlDbType.VarChar)).Value = p.ProgramName;
                        cmd.Parameters.Add(new SqlParameter("@Part", SqlDbType.VarChar)).Value        = p.Part;

                        cmd.Parameters.Add(new SqlParameter("@ControlItem", SqlDbType.VarChar)).Value = p.ControlItem;

                        //cmd.Parameters.Add("@RETURN_CODE", SqlDbType.Int).Direction = ParameterDirection.Output;
                        //int RETURN_CODE = Convert.ToInt32(cmd.Parameters["@RETURN_CODE"].Value);
                        cmd.ExecuteNonQuery();
                        returnProgramPdtCtrl.Code    = "00";
                        returnProgramPdtCtrl.Message = "Cập nhật dữ liệu thành công.";
                    }
                }
            }
            catch (Exception ex)
            {
                returnProgramPdtCtrl.Code              = "99";
                returnProgramPdtCtrl.Message           = "Lỗi xử lý dữ liệu: " + ex.ToString();
                returnProgramPdtCtrl.Total             = 0;
                returnProgramPdtCtrl.lstProgramPdtCtrl = null;
            }
            return(returnProgramPdtCtrl);
        }
Ejemplo n.º 2
0
        public ReturnProgramPdtCtrl Insert(ProgramPdtCtrl p)
        {
            ReturnProgramPdtCtrl returnProgramPdtCtrl = new ReturnProgramPdtCtrl();

            try
            {
                using (SqlConnection sqlConnection = ConnectSQLCommon.CreateAndOpenSqlConnection())
                {
                    using (SqlCommand cmd = new SqlCommand("", sqlConnection))
                    {
                        cmd.CommandText = "sp_tProgramPdtCtrl_InsertUpdate";
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("@ProgramName", SqlDbType.VarChar)).Value  = p.ProgramName;
                        cmd.Parameters.Add(new SqlParameter("@Part", SqlDbType.NVarChar)).Value        = String.IsNullOrEmpty(p.Part) ? "" : p.Part;
                        cmd.Parameters.Add(new SqlParameter("@ControlItem", SqlDbType.NVarChar)).Value = p.ControlItem;
                        cmd.Parameters.Add(new SqlParameter("@ColumnName", SqlDbType.NVarChar)).Value  = String.IsNullOrEmpty(p.ColumnName) ? "" : p.ColumnName;
                        cmd.Parameters.Add(new SqlParameter("@LowerLimit", SqlDbType.NVarChar)).Value  = p.LowerLimit;
                        cmd.Parameters.Add(new SqlParameter("@Unit", SqlDbType.NVarChar)).Value        = String.IsNullOrEmpty(p.Unit) ? "" : p.Unit;
                        cmd.Parameters.Add(new SqlParameter("@UpperLimit", SqlDbType.NVarChar)).Value  = p.UpperLimit;
                        cmd.Parameters.Add(new SqlParameter("@OperatorID", SqlDbType.Int)).Value       = p.OperatorID;
                        cmd.Parameters.Add(new SqlParameter("@SpecDisplay", SqlDbType.NVarChar)).Value = String.IsNullOrEmpty(p.SpecDisplay) ? "" : p.SpecDisplay;

                        //int RETURN_CODE = Convert.ToInt32(cmd.Parameters["@RETURN_CODE"].Value);
                        cmd.ExecuteNonQuery();
                        returnProgramPdtCtrl.Code    = "00";
                        returnProgramPdtCtrl.Message = "Cập nhật dữ liệu thành công.";
                    }
                }
            }
            catch (Exception ex)
            {
                returnProgramPdtCtrl.Code              = "99";
                returnProgramPdtCtrl.Message           = "Lỗi xử lý dữ liệu: " + ex.ToString();
                returnProgramPdtCtrl.Total             = 0;
                returnProgramPdtCtrl.lstProgramPdtCtrl = null;
                mylog4net.Error("", ex);
            }
            return(returnProgramPdtCtrl);
        }
Ejemplo n.º 3
0
        public ReturnProgramPdtCtrl GetProgramPdtCtrl_ByProgramName(ReturnProgramPdtCtrl searchProgramPdtCtrl)
        {
            List <ProgramPdtCtrl> lstProgramPdtCtrl    = null;
            ProgramPdtCtrl        programPdtCtrl       = null;
            ReturnProgramPdtCtrl  returnProgramPdtCtrl = new ReturnProgramPdtCtrl();

            try
            {
                using (SqlConnection sqlConnection = ConnectSQLCommon.CreateAndOpenSqlConnection())
                {
                    using (SqlCommand cmd = new SqlCommand("", sqlConnection))
                    {
                        cmd.CommandText = "sp_GetProgramPdtCtrl_ByProgramName";
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("@ProgramName", SqlDbType.VarChar)).Value = searchProgramPdtCtrl.aProgramPdtCtrl.ProgramName;
                        //cmd.Parameters.Add(new SqlParameter("@Part", SqlDbType.NVarChar)).Value = searchProgramPdtCtrl.aProgramPdtCtrl.Part;
                        //cmd.Parameters.Add(new SqlParameter("@ControlItem", SqlDbType.NVarChar)).Value = searchProgramPdtCtrl.aProgramPdtCtrl.ControlItem;

                        //cmd.Parameters.Add(new SqlParameter("@pageNumber", SqlDbType.Int)).Value = searchProgramPdtCtrl.PageNumber;
                        //cmd.Parameters.Add(new SqlParameter("@pageSize", SqlDbType.Int)).Value = pageSize;
                        //cmd.Parameters.Add("@totalRow", SqlDbType.Int).Direction = ParameterDirection.Output;

                        using (SqlDataReader sqlDr = ConnectSQLCommon.ExecuteDataReader(cmd))
                        {
                            if (sqlDr.HasRows)
                            {
                                lstProgramPdtCtrl = new List <ProgramPdtCtrl>();
                                while (sqlDr.Read())
                                {
                                    programPdtCtrl              = new ProgramPdtCtrl();
                                    programPdtCtrl.ID           = Convert.ToInt32(sqlDr["ID"].ToString());
                                    programPdtCtrl.ProgramName  = sqlDr["ProgramName"].ToString();
                                    programPdtCtrl.Part         = sqlDr["Part"].ToString();
                                    programPdtCtrl.ControlItem  = sqlDr["ControlItem"].ToString();
                                    programPdtCtrl.SpecDisplay  = sqlDr["SpecDisplay"].ToString();
                                    programPdtCtrl.Unit         = sqlDr["Unit"].ToString();
                                    programPdtCtrl.UpperLimit   = sqlDr["UpperLimit"].ToString();
                                    programPdtCtrl.LowerLimit   = sqlDr["LowerLimit"].ToString();
                                    programPdtCtrl.ColumnName   = sqlDr["ColumnName"].ToString();
                                    programPdtCtrl.OperatorID   = Convert.ToInt32(sqlDr["OperatorID"].ToString());
                                    programPdtCtrl.OperatorName = (new UserDB()).getUserNameByID(Convert.ToInt32(programPdtCtrl.OperatorID));
                                    programPdtCtrl.CreatedDate  = DateTime.Parse(sqlDr["CreatedDate"].ToString());
                                    lstProgramPdtCtrl.Add(programPdtCtrl);
                                }
                                returnProgramPdtCtrl.Code              = "00";
                                returnProgramPdtCtrl.Message           = "Lấy dữ liệu thành công.";
                                returnProgramPdtCtrl.lstProgramPdtCtrl = lstProgramPdtCtrl;
                                returnProgramPdtCtrl.userID            = MyShareInfo.ID;
                                returnProgramPdtCtrl.UserName          = MyShareInfo.UserName;
                                returnProgramPdtCtrl.UserName          = MyShareInfo.UserName;
                            }
                            else
                            {
                                returnProgramPdtCtrl.Code              = "01";
                                returnProgramPdtCtrl.Message           = "Không tồn tại bản ghi nào.";
                                returnProgramPdtCtrl.Total             = 0;
                                returnProgramPdtCtrl.lstProgramPdtCtrl = null;
                                returnProgramPdtCtrl.UserName          = MyShareInfo.UserName;
                                returnProgramPdtCtrl.UserName          = MyShareInfo.UserName;
                            }
                        }
                        //get return Totalpage value.
                        //if (returnProgramPdtCtrl.Code == "00")
                        //    returnProgramPdtCtrl.Total = Convert.ToInt32(cmd.Parameters["@totalRow"].Value);
                    }
                }
            }
            catch (Exception ex)
            {
                returnProgramPdtCtrl.Code              = "99";
                returnProgramPdtCtrl.Message           = "Lỗi xử lý dữ liệu: " + ex.ToString();
                returnProgramPdtCtrl.Total             = 0;
                returnProgramPdtCtrl.lstProgramPdtCtrl = null;
                mylog4net.Error("", ex);
            }
            return(returnProgramPdtCtrl);
        }
Ejemplo n.º 4
0
        public ReturnProgramPdtCtrl GetbyID(int ID)
        {
            List <ProgramPdtCtrl> lstProgramPdtCtrl    = null;
            ProgramPdtCtrl        programPdtCtrl       = null;
            ReturnProgramPdtCtrl  returnProgramPdtCtrl = new ReturnProgramPdtCtrl();

            try
            {
                using (SqlConnection sqlConnection = ConnectSQLCommon.CreateAndOpenSqlConnection())
                {
                    using (SqlCommand cmd = new SqlCommand("", sqlConnection))
                    {
                        //cmd.Connection = _sqlConnection;
                        cmd.CommandText = "sp_tProgramPdtCtrl_SelectByID";
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)).Value = ID;
                        using (SqlDataReader sqlDr = ConnectSQLCommon.ExecuteDataReader(cmd, sqlConnection))
                        {
                            if (sqlDr.HasRows)
                            {
                                lstProgramPdtCtrl = new List <ProgramPdtCtrl>();
                                while (sqlDr.Read())
                                {
                                    programPdtCtrl             = new ProgramPdtCtrl();
                                    programPdtCtrl.ID          = Convert.ToInt32(sqlDr["ID"].ToString());
                                    programPdtCtrl.ProgramName = sqlDr["ProgramName"].ToString();
                                    programPdtCtrl.Part        = sqlDr["Part"].ToString();
                                    programPdtCtrl.ControlItem = sqlDr["ControlItem"].ToString();
                                    programPdtCtrl.ColumnName  = sqlDr["ColumnName"].ToString();
                                    programPdtCtrl.Unit        = sqlDr["Unit"].ToString();
                                    programPdtCtrl.SpecDisplay = sqlDr["SpecDisplay"].ToString();
                                    programPdtCtrl.LowerLimit  = sqlDr["LowerLimit"].ToString();
                                    programPdtCtrl.UpperLimit  = sqlDr["UpperLimit"].ToString();
                                    programPdtCtrl.OperatorID  = Convert.ToInt32(sqlDr["OperatorID"].ToString());

                                    programPdtCtrl.OperatorName = (new UserDB()).getUserNameByID(Convert.ToInt32(programPdtCtrl.OperatorID));

                                    programPdtCtrl.CreatedDate = DateTime.Parse(sqlDr["CreatedDate"].ToString());
                                    lstProgramPdtCtrl.Add(programPdtCtrl);
                                }
                                returnProgramPdtCtrl.Code              = "00";
                                returnProgramPdtCtrl.Message           = "Lấy dữ liệu thành công.";
                                returnProgramPdtCtrl.lstProgramPdtCtrl = lstProgramPdtCtrl;
                                returnProgramPdtCtrl.Total             = lstProgramPdtCtrl.Count;
                                //}
                            }
                            else
                            {
                                returnProgramPdtCtrl.Code              = "01";
                                returnProgramPdtCtrl.Message           = "Không tồn tại bản ghi nào.";
                                returnProgramPdtCtrl.Total             = 0;
                                returnProgramPdtCtrl.lstProgramPdtCtrl = null;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                returnProgramPdtCtrl.Code              = "99";
                returnProgramPdtCtrl.Message           = "Lỗi xử lý dữ liệu: " + ex.ToString();
                returnProgramPdtCtrl.Total             = 0;
                returnProgramPdtCtrl.lstProgramPdtCtrl = null;
                mylog4net.Error(" public ReturnProgramPdtCtrl GetbyID(int ID) ", ex);
            }
            return(returnProgramPdtCtrl);
        }