コード例 #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            ELCompanyType objEL = new ELCompanyType();

            int newID = 0;

            if (lblID.Text.Length > 0)
            {
                objEL.ID = Convert.ToInt32(lblID.Text);
            }
            else
            {
                newID = Common.GetNewID(tableName);
                objEL.ID = newID;
            }

            objEL.Code = txtCode.Text;
            objEL.Name = txtName.Text;
            objEL.Creator = 0;
            objEL.Created = DateTime.Now;
            objEL.IsActive = false;

            if (chkIsActive.Checked) objEL.IsActive = true;

            if (Validations())
            {
                if (DLCompanyType.Add(objEL) > 0)
                {
                    MessageBox.Show("Record Inserted");
                    ClearControls();
                }
                else
                {
                    MessageBox.Show("Record not Inserted");
                }
            }
        }
コード例 #2
0
        public static ELCompanyType FetchByID(int ID = 0, string Code = "")
        {
            SqlCommand cmd;
            string qry = "";
            ELCompanyType ObjEL = new ELCompanyType();
            SqlDataReader dr;
            try
            {
                conn.CreatConnection();

                qry = "SELECT CT.*,C.ID As CompanyID,C.Code As CompanyCode,C.Name As CompanyName FROM CompanyType CT " +
                        " join Company C on CT.CompanyID=C.ID WHERE ";

                if (Code != "")
                    qry = qry + " CT.code =@Code ";
                else if (ID > 0)
                    qry = qry + " CT.ID =@ID";
                else
                    qry = qry + " CT.ID =@ID";

                cmd = new SqlCommand(qry, conn.con);

                SqlParameter param;

                param = new SqlParameter("@ID", SqlDbType.Int);
                param.Direction = ParameterDirection.Input;
                param.Value = ID;
                cmd.Parameters.Add(param);

                param = new SqlParameter("@Code", SqlDbType.VarChar);
                param.Direction = ParameterDirection.Input;
                param.Value = Code;
                cmd.Parameters.Add(param);

                foreach (SqlParameter Parameter in cmd.Parameters)
                {
                    if (Parameter.Value == null)
                    {
                        Parameter.Value = DBNull.Value;
                    }
                }

                dr = cmd.ExecuteReader();

                if (dr.HasRows)
                {
                    dr.Read();
                    ObjEL.ID = Convert.ToInt32(dr["id"]);
                    ObjEL.Code = dr["Code"].ToString();
                    ObjEL.Name = dr["Name"].ToString();
                    ObjEL.CompanyID = Convert.ToInt32(dr["CompanyID"]);
                    ObjEL.CompanyCode = dr["CompanyCode"].ToString();
                    ObjEL.CompanyName = dr["CompanyName"].ToString();
                    ObjEL.IsActive = Convert.ToBoolean(dr["IsActive"]);
                    ObjEL.Creator = Convert.ToInt32(dr["Creator"]);
                    ObjEL.Created = Convert.ToDateTime(dr["Created"]);

                }
                dr.Close();

                return ObjEL;
            }
            catch (Exception ex)
            {
                UtilityLayer.Common.ErrorLog(DateTime.Now.ToString() + ex.Message + " " + ex.StackTrace + " " + "DLCompanyType - FetchByID");
                return null;
            }
            finally
            {
                conn.CloseConnection();
            }
        }
コード例 #3
0
        private void gv_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex > 0)
            {

                string strCode = gv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
                string ID = gv.Rows[e.RowIndex].Cells[0].Value.ToString();
                string CompanyCode = gv.Rows[e.RowIndex].Cells[3].Value.ToString();

                ELCompanyType objEL = new ELCompanyType();
                DLCompanyType objDL = new DLCompanyType();
                objEL = DLCompanyType.FetchByID(Convert.ToInt32(ID));

                if (objEL != null)
                {
                    lblID.Text = objEL.ID.ToString();
                    txtCode.Text = objEL.Code;
                    txtName.Text = objEL.Name;
                    chkIsActive.Checked = Convert.ToBoolean(objEL.IsActive);
                    if (CompanyCode == objEL.ID.ToString())
                        cbTypes.SelectedItem = objEL.CompanyName;
                }
            }
        }
コード例 #4
0
        public static int Add(ELCompanyType objEL)
        {
            int retValue = 0;
            SqlCommand cmd;
            string qry = "";
            object value;
            try
            {
                conn.CreatConnection();

                qry = "";

                qry = "SELECT COUNT(ID) FROM CompanyType WHERE ID =@ID ";

                cmd = new SqlCommand(qry, conn.con);

                SqlParameter param;

                param = new SqlParameter("@ID", SqlDbType.Int);
                param.Direction = ParameterDirection.Input;
                param.Value = objEL.ID;
                cmd.Parameters.Add(param);

                foreach (SqlParameter Parameter in cmd.Parameters)
                {
                    if (Parameter.Value == null)
                    {
                        Parameter.Value = DBNull.Value;
                    }
                }

                value = cmd.ExecuteScalar();

                if (value != null && value.ToString() != "0")
                {
                    qry = "";
                    qry = "UPDATE CompanyType SET Code=@Code, Name =@Name,CompanyID=@CompanyID,IsActive=@IsActive WHERE ID=@ID";

                    cmd = new SqlCommand(qry, conn.con);

                    param = new SqlParameter("@ID", SqlDbType.Int);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objEL.ID;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@Code", SqlDbType.NVarChar);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objEL.Code;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@Name", SqlDbType.NVarChar);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objEL.Name;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@CompanyID", SqlDbType.Int);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objEL.CompanyID;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@isActive", SqlDbType.Bit);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objEL.IsActive;
                    cmd.Parameters.Add(param);

                    foreach (SqlParameter Parameter in cmd.Parameters)
                    {
                        if (Parameter.Value == null)
                        {
                            Parameter.Value = DBNull.Value;
                        }
                    }

                    retValue = cmd.ExecuteNonQuery();
                }
                else
                {
                    qry = "";

                    qry = "INSERT INTO CompanyType (ID, CODE, NAME,CompanyID, CREATOR , CREATED, ISACTIVE) " +
                        " VALUES(@ID, @Code, @Name,@CompanyID, @Creator, @Created, @IsActive) ";

                    cmd = new SqlCommand(qry, conn.con);

                    param = new SqlParameter("@ID", SqlDbType.Int);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objEL.ID;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@Code", SqlDbType.NVarChar);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objEL.Code;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@Name", SqlDbType.NVarChar);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objEL.Name;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@CompanyID", SqlDbType.Int);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objEL.CompanyID;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@Creator", SqlDbType.Int);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objEL.Creator;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@Created", SqlDbType.DateTime);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objEL.Created;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@isActive", SqlDbType.Bit);
                    param.Direction = ParameterDirection.Input;
                    param.Value = objEL.IsActive;
                    cmd.Parameters.Add(param);

                    foreach (SqlParameter Parameter in cmd.Parameters)
                    {
                        if (Parameter.Value == null)
                        {
                            Parameter.Value = DBNull.Value;
                        }
                    }

                    retValue = cmd.ExecuteNonQuery();

                }
            }
            catch (Exception ex)
            {
                UtilityLayer.Common.ErrorLog(DateTime.Now.ToString() + ex.Message + " " + ex.StackTrace + " " + "DLCompanyType - Add");
                return 0;
            }
            finally
            {
                conn.CloseConnection();
            }
            return retValue;
        }