Beispiel #1
0
        public static bool UpdateBransch(Bransch bransch)
        {
            int           result = 0;
            SqlConnection conn   = DBUtil.CreateConnection();

            if (conn == null)
            {
                return(false);
            }
            try
            {
                SqlCommand cmd = new SqlCommand("usp_Update_A_Bransch", conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Bransch_Id", SqlDbType.Int).Value       = bransch.BranschId;
                cmd.Parameters.AddWithValue("@Bransch_Name", SqlDbType.VarChar).Value = bransch.Name;
                result = cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                DBUtil.CloseConnection(conn);
            }
            if (result == 0)
            {
                return(false);
            }
            return(true);
        }
Beispiel #2
0
        public static DataTable ReadAllCompaniesForABransch(Bransch b)
        {
            DataTable     bransches = new DataTable();
            SqlConnection conn      = DBUtil.CreateConnection();

            if (conn == null)
            {
                return(bransches);
            }
            try
            {
                SqlCommand cmd = new SqlCommand("usp_Info_About_Companies_With_A_Given_Bransch", conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                SqlParameter   idParam = new SqlParameter("@BranschId", b.BranschId);
                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                cmd.Parameters.Add(idParam);
                adapter.Fill(bransches);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                DBUtil.CloseConnection(conn);
            }
            return(bransches);
        }
Beispiel #3
0
        private void CreateBranchButton_Click(object sender, EventArgs e)
        {
            try
            {
                String tempId = txtBranchId.Text;
                tempId = tempId.Trim();
                if (String.IsNullOrEmpty(tempId))
                {
                    lblresponse.Text = "Id box is empty";
                    return;
                }

                Bransch bransch = new Bransch();
                bransch.BranschId = Int32.Parse(tempId);

                bransch.Name = txtBranchName.Text;
                bransch.Name = bransch.Name.Trim();
                if (bransch.BranschId < 0)
                {
                    lblresponse.Text = "Id is less than 0";
                    return;
                }
                if (String.IsNullOrEmpty(bransch.Name))
                {
                    lblresponse.Text = "You need to write a name";
                    return;
                }

                bool success = BranschController.CreateBransch(bransch);
                FillListWithAllBranches();

                if (success)
                {
                    lblresponse.Text = "Bransch Created";
                }
                else
                {
                    lblresponse.Text = "Failed to create Bransch";
                }
            }
            catch (Exception ex)
            {
                lblresponse.Text = ErrorHandlern.HandleExceptions(ex);
            }
            FillListWithAllEmployees();
        }
Beispiel #4
0
        public static Bransch FindById(int branschId)

        {
            Bransch       bransch = null;
            SqlConnection conn    = DBUtil.CreateConnection();

            if (conn == null)
            {
                return(null);
            }
            try
            {
                SqlCommand cmd = new SqlCommand("usp_Find_A_Bransch_By_BranschID", conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                SqlParameter idParam = new SqlParameter("@BranschId", branschId);
                cmd.Parameters.Add(idParam);

                SqlDataReader reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    bransch           = new Bransch();
                    bransch.BranschId = reader.GetInt32(reader.GetOrdinal("BranschId"));
                    bransch.Name      = reader["Name"].ToString();
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                DBUtil.CloseConnection(conn);
            }
            return(bransch);
        }
Beispiel #5
0
 public static bool UpdateBransch(Bransch bransch)
 {
     return(BranschAccess.UpdateBransch(bransch));
 }
Beispiel #6
0
 public static bool CreateBransch(Bransch bransch)
 {
     return(BranschAccess.CreateBransch(bransch));
 }
Beispiel #7
0
 public static DataTable ReadAllCompaniesForABransch(Bransch b)
 {
     return(BranschAccess.ReadAllCompaniesForABransch(b));
 }
Beispiel #8
0
 public bool Equals(Bransch bransch)
 {
     return(Type == bransch.Type);
 }