Sunday, March 6, 2011

DAL code c#

using System;
using System.Data;
using System.Data.SqlClient;

namespace CRM.Lib.DAL
{
    internal class HelpdeskActionDAL : BaseDAL
    {

        public DataTable GetAll()
        {
            base.com.CommandText = "spHelpdeskAction";
            base.com.Parameters.AddWithValue("@id", 0);
            return base.GetDataTable();

        }

        public DataRow GetById(int id)
        {
            base.com.CommandText = "spHelpdeskAction";
            base.com.Parameters.AddWithValue("@id", id);
            return base.GetFirstRow();
        }

        public int Save(int id, int helpdeskid, string actionspecifics, string actionby, string resultspecifics, DateTime actiondate, string endorsedto, DateTime endorseddate, DateTime daterecorded, string createdby, DateTime createddate, string modifiedby, DateTime modifieddate, out string message)
        {
            message = "";
            base.com.CommandText = "spHelpdeskActionUpdate";
            base.com.Parameters.AddWithValue("@id", id);
            base.com.Parameters.AddWithValue("@helpdeskid", helpdeskid);
            base.com.Parameters.AddWithValue("@actionspecifics", actionspecifics);
            base.com.Parameters.AddWithValue("@actionby", actionby);
            base.com.Parameters.AddWithValue("@resultspecifics", resultspecifics);
            base.com.Parameters.AddWithValue("@actiondate", actiondate);
            base.com.Parameters.AddWithValue("@endorsedto", endorsedto);
            base.com.Parameters.AddWithValue("@endorseddate", endorseddate);
            base.com.Parameters.AddWithValue("@daterecorded", daterecorded);
            base.com.Parameters.AddWithValue("@createdby", createdby);
            base.com.Parameters.AddWithValue("@createddate", createddate);
            base.com.Parameters.AddWithValue("@modifiedby", modifiedby);
            base.com.Parameters.AddWithValue("@modifieddate", modifieddate);


            int ra = 0;
            try
            {
                ra = Convert.ToInt32(base.com.ExecuteScalar());
            }
            catch (SqlException sqlex)
            {
                switch (sqlex.Number)
                {
                    case 2601:
                        message = "HelpdeskAction Name already exists!";
                        break;
                    default:
                        message = "Update failed!";
                        break;
                }
            }
            return ra;
        }

        public bool Delete(int id)
        {
            base.com.CommandText = "spHelpdeskActionDelete";
            base.com.Parameters.AddWithValue("@id", id);

            int ra;
            try
            {
                ra = Convert.ToInt32(base.com.ExecuteScalar());
            }
            catch
            {
                throw new Exception("Delete helpdeskaction failed!");
            }
            return (ra > 0);
        }

    }
}


No comments:

Post a Comment