예제 #1
0
    public string InsertVendor(ClsShippingVendor data)
    {
        string errMsg = "";
        PuroTouchSQLDataContext puroTouchContext = new PuroTouchSQLDataContext();

        try
        {
            tblShippingVendor oNewRow = new tblShippingVendor()
            {
                idShippingVendor = (Int32)data.idShippingVendor,
                VendorName       = data.VendorName,
                CreatedBy        = data.CreatedBy,
                CreatedOn        = (DateTime?)data.CreatedOn,
                //UpdatedBy = data.UpdatedBy,
                //UpdatedOn = (DateTime?)data.UpdatedOn,
                ActiveFlag = data.ActiveFlag
            };



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


        oVend.VendorName = (userControl.FindControl("txtVendorName") as RadTextBox).Text;
        oVend.ActiveFlag = (userControl.FindControl("ActiveFlag") as RadButton).Checked;

        oVend.UpdatedBy = (string)(Session["userName"]);
        oVend.UpdatedOn = Convert.ToDateTime(DateTime.Now);
        return(oVend);
    }
 protected void rgGrid_UpdateCommand(object sender, GridCommandEventArgs e)
 {
     try
     {
         UserControl       userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
         Label             errorMsg    = (Label)userControl.FindControl("lblErrorMessage");
         ClsShippingVendor oVend       = populateObj(userControl);
         oVend.idShippingVendor = Convert.ToInt16((userControl.FindControl("lblShippingVendorID") as Label).Text);
         string updateMsg = "";
         if (IsValid)
         {
             if (oVend != null)
             {
                 updateMsg = sv.UpdateVendor(oVend);
                 if (updateMsg == "")
                 {
                     pnlsuccess.Visible = true;
                     lblSuccess.Text    = "Successfully updated Vendor " + "'" + oVend.VendorName + "'";
                 }
                 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");
         ClsShippingVendor oVend       = populateObj(userControl);
         string            insertMsg   = "";
         if (IsValid)
         {
             if (oVend != null)
             {
                 insertMsg = sv.InsertVendor(oVend);
                 if (insertMsg == "")
                 {
                     pnlsuccess.Visible = true;
                     lblSuccess.Text    = "Successfully Added New Vendor " + oVend.VendorName;
                 }
                 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 UpdateVendor(ClsShippingVendor data)
    {
        string errMsg = "";
        PuroTouchSQLDataContext puroTouchContext = new PuroTouchSQLDataContext();

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

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

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