private void Create()
        {
            newEntity = new WithdrawalEntity();

            newEntity.Amount = Convert.ToDecimal(this.txtAmount.Text.Trim());
            newEntity.Date = Convert.ToDateTime(this.txtDate.Text.Trim());
            newEntity.Userid = GlobalObjects.User.ID;
            newEntity.Notes = this.txtNotes.Text.Trim();
            newEntity.Status = 1;

            newService.Save(ActionType.Create, newEntity,1);

            Response.Redirect("ManageExpenses.aspx");
        }
        private WithdrawalEntity SetData(DataRow oRow)
        {
            try
            {
                WithdrawalEntity ent = new WithdrawalEntity();
                ent.ID = Convert.ToInt32(oRow["id"]);
                ent.Amount = Convert.ToDecimal(oRow["amount"]);
                ent.Userid = Convert.ToInt32(oRow["user_id"]);
                ent.Date = Convert.ToDateTime(oRow["date"]);
                ent.Notes = oRow["notes"].ToString();
                ent.Status = Convert.ToInt32(oRow["status"]);

                return ent;

            }
            catch (Exception ex) { throw ex; }
        }
        public void Save(ActionType type, WithdrawalEntity ent, int remType = 0)
        {
            try
            {

                using (Database db = new Database(GlobalObjects.CONNECTION_STRING))
                {
                    db.Open();
                    int ret = 0;
                    int typ = (int)type;
                    string sql = "SaveWithdrawals";
                    string[] asParams;
                    DbType[] atParamTypes;
                    object[] aoValues;

                    asParams = new string[] {   "@actiontype",
                                                "@id",
                                                "@userid",
                                                "@amount",
                                                "@date",
                                                "@notes",
                                                "@remType",
                                                "@status",
                                                "@createdby",
                                                "@createddate",
                                                "@updatedby",
                                                "@updateddate"};

                    atParamTypes = new DbType[] {
                                                    DbType.Int16,
                                                    DbType.Int32,
                                                    DbType.Int32,
                                                    DbType.Decimal,
                                                    DbType.Date,
                                                    DbType.String,
                                                    DbType.Int16,
                                                    DbType.Int32,
                                                    DbType.String,
                                                    DbType.DateTime,
                                                    DbType.String,
                                                    DbType.DateTime };

                    aoValues = new object[] {
                                                typ,
                                                ent.ID,
                                                ent.Userid,
                                                ent.Amount,
                                                ent.Date,
                                                ent.Notes,
                                                remType,
                                                ent.Status,
                                                appUsr.UserName,
                                                DateTime.Now,
                                                appUsr.UserName,
                                                DateTime.Now
                                            };

                    db.ExecuteCommandNonQuery(sql, asParams, atParamTypes, aoValues, out ret, CommandTypeEnum.StoredProcedure);

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public WithdrawalEntity GetOne(int userId)
        {
            try
            {

                using (Database db = new Database(GlobalObjects.CONNECTION_STRING))
                {
                    db.Open();
                    string sql;
                    int ret = 0;
                    DataTable oTable = new DataTable();
                    sql = "GetWithdrawal";
                    db.ExecuteCommandReader(sql,
                        new string[] { "@id" },
                        new DbType[] { DbType.Int32 },
                        new object[] { userId },
                        out ret, ref oTable, CommandTypeEnum.StoredProcedure);

                    WithdrawalEntity user = new WithdrawalEntity();
                    if (oTable.Rows.Count > 0)
                    {
                        DataRow oRow = oTable.Rows[0];
                        user = SetData(oRow);

                    }

                    return user;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void PopulateFields(int id)
        {
            newEntity = new WithdrawalEntity();
            newEntity = newService.GetOne(id);

            this.txtDate.Text = newEntity.Date.ToString("yyyy-MM-dd");
            this.txtNotes.Text = newEntity.Notes;
            this.txtAmount.Text = newEntity.Amount.ToString();

            //ddlInvestor.Enabled = false;
            //txtDate.Enabled = false;
            //this.txtAmount.Enabled = false;
        }
        private void Update()
        {
            newEntity = new WithdrawalEntity();

            newEntity.ID = id;
            newEntity.Notes = this.txtNotes.Text.Trim();
            newEntity.Date = Convert.ToDateTime(txtDate.Text);
            newService.Save(ActionType.Update, newEntity);

            Response.Redirect("ManageExpenses.aspx");
        }
        private void Create()
        {
            newEntity = new WithdrawalEntity();

            newEntity.Amount = Convert.ToDecimal(this.txtAmount.Text.Trim());
            newEntity.Date = Convert.ToDateTime(this.txtDate.Text.Trim());
            newEntity.Userid = Convert.ToInt32(ddlInvestor.SelectedValue);
            newEntity.Notes = this.txtNotes.Text.Trim();
            newEntity.Status = 1;

            newService.Save(ActionType.Create, newEntity,0);

            Response.Redirect("ManageWithdrawals.aspx");
        }