コード例 #1
0
        public bool AddUnitType(clsUnitType info)
        {
            int st = 0;

            try
            {
                using (SqlConnection conn = new SqlConnection(strConn))
                {
                    conn.Open();

                    {
                        using (SqlCommand cmd = new SqlCommand("TMR_USP_AddUnitType"))
                        {
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.Connection  = conn;
                            cmd.Parameters.AddWithValue("@UnitTypeID", info.strUnitTypeID);
                            cmd.Parameters.AddWithValue("@UnitTypeDescription", info.strDesc);
                            cmd.Parameters.AddWithValue("@ID", info.id);

                            st = cmd.ExecuteNonQuery();
                        }
                    }
                    conn.Close();
                }
            }
            catch (Exception ex) { }
            if (st > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
        public List <clsUnitType> GetAllUnitTypeInfo()
        {
            List <clsUnitType> lst = new List <clsUnitType>();

            using (SqlConnection conn = new SqlConnection(strConn))
            {
                conn.Open();

                using (SqlCommand cmd = new SqlCommand("TMR_USP_GetUnitType"))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Connection  = conn;

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        var info = new clsUnitType();

                        info.strUnitTypeID = reader["UnitTypeID"].ToString();
                        info.strDesc       = reader["UnitTypeDescription"].ToString();
                        info.id            = Convert.ToInt32(reader["ID"]);

                        lst.Add(info);
                    }
                    conn.Close();
                }
            }
            return(lst);
        }
コード例 #3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtID.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Unit Category id cannot be empty.");
                txtID.Focus();
                return;
            }
            if (txtDesc.Text.Trim() == "")
            {
                MessageBox.Show("Description cannot be empty.");
                txtDesc.Focus();
                return;
            }

            foreach (DataGridViewRow dgr in dgList.Rows)
            {
                if (dgr.Cells["UnitTypeID"].Value.ToString().Trim().ToUpper() == txtID.Text.Trim().ToUpper() && this.id != Convert.ToInt32(dgr.Cells["ID1"].Value))
                {
                    MessageBox.Show("A unit type with same ID already exists.");
                    return;
                }
            }

            clsUnitType cat = new clsUnitType();

            cat.strUnitTypeID = txtID.Text.Trim();
            cat.strDesc       = txtDesc.Text.Trim();
            cat.id            = this.id;

            bool result = da.AddUnitType(cat);

            if (result == false)
            {
                MessageBox.Show("An error occurred.");
                return;
            }

            LoadProjects();

            Clear();
        }