示例#1
0
    public string InsertVendorType(ClsVendorType data)
    {
        string errMsg = "";
        PuroTouchSQLDataContext puroTouchContext = new PuroTouchSQLDataContext();

        try
        {
            tblVendorType oNewRow = new tblVendorType()
            {
                idVendorType = (Int32)data.idVendorType,
                VendorType   = data.VendorType,
                CreatedBy    = data.CreatedBy,
                CreatedOn    = (DateTime?)data.CreatedOn,
                //UpdatedBy = data.UpdatedBy,
                //UpdatedOn = (DateTime?)data.UpdatedOn,
                ActiveFlag = data.ActiveFlag
            };



            puroTouchContext.GetTable <tblVendorType>().InsertOnSubmit(oNewRow);
            // Submit the changes to the database.
            puroTouchContext.SubmitChanges();
            //newID = oNewRow.idTaskType;
        }
        catch (Exception ex)
        {
            errMsg = ex.Message.ToString();
        }
        return(errMsg);
    }
    private ClsVendorType populateObj(UserControl userControl)
    {
        ClsVendorType oRow = new ClsVendorType();


        oRow.VendorType = (userControl.FindControl("txtVendorType") as RadTextBox).Text;

        oRow.ActiveFlag = (userControl.FindControl("ActiveFlag") as RadButton).Checked;


        oRow.UpdatedBy = (string)(Session["userName"]);
        oRow.UpdatedOn = Convert.ToDateTime(DateTime.Now);
        return(oRow);
    }
 protected void rgGrid_UpdateCommand(object sender, GridCommandEventArgs e)
 {
     try
     {
         UserControl   userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
         Label         errorMsg    = (Label)userControl.FindControl("lblErrorMessage");
         ClsVendorType oRow        = populateObj(userControl);
         oRow.idVendorType = Convert.ToInt16((userControl.FindControl("lblVendorTypeID") as Label).Text);
         string updateMsg = "";
         if (IsValid)
         {
             if (oRow != null)
             {
                 updateMsg = cls.UpdateVendorType(oRow);
                 if (updateMsg == "")
                 {
                     pnlsuccess.Visible = true;
                     lblSuccess.Text    = "Successfully updated information for " + "'" + oRow.VendorType + "'";
                 }
                 else
                 {
                     errorMsg.Visible = true;
                     errorMsg.Text    = updateMsg;
                     e.Canceled       = true;
                 }
             }
         }
         else
         {
             // display error
             errorMsg.Visible = true;
             errorMsg.Text    = "Please enter Required fields";
             e.Canceled       = true;
         }
     }
     catch (Exception ex)
     {
         pnlDanger.Visible = true;
         lblDanger.Text    = ex.Message.ToString();
         e.Canceled        = true;
     }
 }
 protected void rgGrid_InsertCommand(object sender, GridCommandEventArgs e)
 {
     try
     {
         UserControl   userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
         Label         errorMsg    = (Label)userControl.FindControl("lblErrorMessage");
         ClsVendorType oRow        = populateObj(userControl);
         string        insertMsg   = "";
         if (IsValid)
         {
             if (oRow != null)
             {
                 insertMsg = cls.InsertVendorType(oRow);
                 if (insertMsg == "")
                 {
                     pnlsuccess.Visible = true;
                     lblSuccess.Text    = "Successfully Added New Record " + oRow.VendorType;
                 }
                 else
                 {
                     errorMsg.Visible = true;
                     errorMsg.Text    = insertMsg;
                     e.Canceled       = true;
                 }
             }
         }
         else
         {
             // display error
             errorMsg.Visible = true;
             errorMsg.Text    = "Please enter Required fields";
             e.Canceled       = true;
         }
     }
     catch (Exception ex)
     {
         pnlDanger.Visible = true;
         lblDanger.Text    = ex.Message.ToString();
         e.Canceled        = true;
     }
 }
示例#5
0
    public string UpdateVendorType(ClsVendorType data)
    {
        string errMsg = "";
        PuroTouchSQLDataContext puroTouchContext = new PuroTouchSQLDataContext();

        try
        {
            if (data.idVendorType > 0)
            {
                // Query the database for the row to be updated.
                var query =
                    from qdata in puroTouchContext.GetTable <tblVendorType>()
                    where qdata.idVendorType == data.idVendorType
                    select qdata;

                // Execute the query, and change the column values
                // you want to change.
                foreach (tblVendorType updRow in query)
                {
                    updRow.VendorType   = data.VendorType;
                    updRow.ActiveFlag   = data.ActiveFlag;
                    updRow.idVendorType = data.idVendorType;
                    updRow.UpdatedBy    = data.UpdatedBy;
                    updRow.UpdatedOn    = data.UpdatedOn;
                }

                // Submit the changes to the database.
                puroTouchContext.SubmitChanges();
            }
            else
            {
                errMsg = "There is No VendorType with ID = " + "'" + data.idVendorType + "'";
            }
        }
        catch (Exception ex)
        {
            errMsg = ex.Message.ToString();
        }
        return(errMsg);
    }