Friday, 27 April 2012

Method to Print View Object wirtten in AM called by Controller of the Page

package oracle.apps.ak.test.EOPackage;
import oracle.apps.fnd.framework.server.OAApplicationModuleImpl;
import oracle.jbo.Row;
import oracle.apps.fnd.framework.OAViewObject;
//  ---------------------------------------------------------------
//  ---    File generated by Oracle Business Components for Java.
//  ---------------------------------------------------------------

public class EOPackageModuleImpl extends OAApplicationModuleImpl
{


   public  void printViewObject()
   {

   //get a handle to the View Object that we wish to initialize
    OAViewObject vo = (OAViewObject)getEmprequisitionView1();
      // Execute the query, print results to the screen.
      vo.executeQuery();
      while (vo.hasNext()) {
         Row row = vo.next();
         String rowDataStr = "";

         // How many attributes (columns) is the View Object using?
         int numAttrs = vo.getAttributeCount();

         // Column numbers start with 0, not 1.
         for (int columnNo = 0; columnNo < numAttrs; columnNo++) {

           // See also Row.getAttribute(String name).
           Object attrData = row.getAttribute(columnNo);
           rowDataStr += (attrData + "\t");
         }
         System.out.println(rowDataStr);
      }
   }




public void OurInsertMethod(String empid, String empname, String empdesign, String empdepart, String empdiv, String emploc ){

System.out.println("I am insert method in Am"+empid+empname);
 //get a handle to the View Object that we wish to initialize
    OAViewObject vo = (OAViewObject)getEmprequisitionView1();
    if(!vo.isPreparedForExecution()){
    vo.executeQuery();
    }

    //Create a blank Row
    
     Row row = vo.createRow();
    //Attach that blank row to the VO. Data will be fed into this row, when the user types into the fields
   //row.
    
      vo.insertRow(row);
    //Set the status of the blank row to initialized. This tells OA Framework that record is blank and must not be included in DML
    //Operations until    changes are made to its underlying VO [via screen fields]
   row.setNewRowState(Row.STATUS_INITIALIZED);
}
   
 //method defined to commit the tractions.  
public void saveDataToSimpleTable()
{
        getDBTransaction().commit();
}


  /**
   *
   * This is the default constructor (do not remove)
   */
  public EOPackageModuleImpl()
  {
  }

  /**
   *
   * Container's getter for EmprequisitionView1
   */
  public EmprequisitionViewImpl getEmprequisitionView1()
  {
    return (EmprequisitionViewImpl)findViewObject("EmprequisitionView1");
  }

  /**
   *
   * Sample main for debugging Business Components code using the tester.
   */
  public static void main(String[] args)
  {
    launchTester("oracle.apps.ak.test.EOPackage", "EOPackageModuleLocal");
  }
}

Thursday, 26 April 2012

AM Appliction Module Containing InsertMethod Called By Controller

package oracle.apps.ak.test.EOPackage;
import oracle.apps.fnd.framework.server.OAApplicationModuleImpl;
import oracle.jbo.Row;
import oracle.apps.fnd.framework.OAViewObject;
public class EOPackageModuleImpl extends OAApplicationModuleImpl
{
public void OurInsertMethod(String empid, String empname, String empdesign, String empdepart, String empdiv, String emploc ){
System.out.println("I am insert method in Am"+empid+empname);
 //get a handle to the View Object that we wish to initialize
    OAViewObject vo = (OAViewObject)getEmprequisitionView1();
    if(!vo.isPreparedForExecution()){
    vo.executeQuery();
    }
    //Create a blank Row
    Row row = vo.createRow();
    //Attach that blank row to the VO. Data will be fed into this row, when the user types into the fields
   //row.
     vo.insertRow(row);
    //Set the status of the blank row to initialized. This tells OA Framework that record is blank and must not be included in DML
    //Operations until    changes are made to its underlying VO [via screen fields]
   row.setNewRowState(Row.STATUS_INITIALIZED);
}
 public void saveDataToSimpleTable()
{        getDBTransaction().commit();}
  /**
   *
   * This is the default constructor (do not remove)
   */
  public EOPackageModuleImpl()
  {
  }

  /**
   *
   * Container's getter for EmprequisitionView1
   */
  public EmprequisitionViewImpl getEmprequisitionView1()
  {
    return (EmprequisitionViewImpl)findViewObject("EmprequisitionView1");
  }

  public static void main(String[] args)
  {
    launchTester("oracle.apps.ak.test.EOPackage", "EOPackageModuleLocal");
  }
}

Controll Class in OAF


package oracle.apps.ak.test.EOPackage.webui;
import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.OAApplicationModule;
import java.io.Serializable;
/**
 * Controller for ...
 */
public class EmpolyeeController extends OAControllerImpl
{
  public static final String RCS_ID="$Header$";
  public static final boolean RCS_ID_RECORDED =
        VersionInfo.recordClassVersion(RCS_ID, "%packagename%");
  /**
   * Layout and page setup logic for a region.
   * @param pageContext the current OA page context
   * @param webBean the web bean corresponding to the region
   */
  public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processRequest(pageContext, webBean);
  OAApplicationModule am = pageContext.getApplicationModule(webBean);
  String userId = pageContext.getParameter("EmployeeID");
  String userName = pageContext.getParameter("EmployeeName");
  String userDesignation = pageContext.getParameter("EmployeeDesignation");
  String userDepartment = pageContext.getParameter("EmployeeDepartment");
  String userDivision = pageContext.getParameter("EmployeeDivision");
  String userLocation = pageContext.getParameter("EmployeeLocation");
  Serializable[] params={userId,userName,userDesignation,userDepartment,userDivision,userLocation};
  am.invokeMethod("OurInsertMethod",params);
  }

  /**
   * Procedure to handle form submissions for form elements in
   * a region.
   * @param pageContext the current OA page context
   * @param webBean the web bean corresponding to the region
   */
  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);

    OAApplicationModule am = pageContext.getApplicationModule(webBean);
    am.invokeMethod("saveDataToSimpleTable") ;

}
}

Thursday, 29 March 2012

Inserting and deleting and update records in MSSQL Server database using .net C#

Check duplicate before Inserting record:
SqlConnection scon = new SqlConnection("Data Source=FAISALN;Initial Catalog=Shipping;Integrated Security=True");
        scon.Open();
        SqlCommand scmd = new SqlCommand("select PO from PO_Table where PO=@PO " , scon);
        scmd.Parameters.Add("PO", SqlDbType.Int).Value = TextBox1.Text;
        scmd.ExecuteScalar();

        if (scmd.ExecuteScalar()== null)
        {
            SqlDataAdapter da = new SqlDataAdapter();
            da.InsertCommand = new SqlCommand("insert into PO_Table values (@PO, @Style_Ref, @Price, @Season, @Order_Qty, @PO_Ship_Date, @PO_Shipping_Month, @PO_Shipping_Mode, @PO_Value, @PO_Destination, @Vendor, @Buyer)", scon);
            da.InsertCommand.Parameters.Add("@PO", SqlDbType.Int).Value = TextBox1.Text;
            da.InsertCommand.Parameters.Add("@Style_Ref", SqlDbType.NVarChar).Value = TextBox2.Text;
            da.InsertCommand.Parameters.Add("@PO_Destination", SqlDbType.NVarChar).Value = DropDownList3.Text;
            da.InsertCommand.Parameters.Add("@Price", SqlDbType.Float).Value = TextBox3.Text;
            da.InsertCommand.Parameters.Add("@Season", SqlDbType.NVarChar).Value = DropDownList2.Text;
            da.InsertCommand.Parameters.Add("@Order_Qty", SqlDbType.Int).Value = TextBox4.Text;
            da.InsertCommand.Parameters.Add("@PO_Ship_Date", SqlDbType.DateTime).Value = TextBox5.Text;
            da.InsertCommand.Parameters.Add("@PO_Shipping_Month", SqlDbType.Char).Value = TextBox6.Text;
            da.InsertCommand.Parameters.Add("@PO_Shipping_Mode", SqlDbType.Char).Value = TextBox7.Text;
            da.InsertCommand.Parameters.Add("@PO_Value", SqlDbType.Int).Value = TextBox8.Text;
            da.InsertCommand.Parameters.Add("@Vendor", SqlDbType.NVarChar).Value = DropDownList5.Text;
            da.InsertCommand.Parameters.Add("@Buyer", SqlDbType.NVarChar).Value = DropDownList4.Text;
            da.InsertCommand.ExecuteNonQuery();
            scon.Close();
            TextBox1.Text = "";
            TextBox2.Text = "";
            TextBox3.Text = "";
            TextBox4.Text = "";
            TextBox5.Text = "";
            TextBox6.Text = "";
            TextBox7.Text = "";
            TextBox8.Text = "";
            string strScript = "<script language='JavaScript'>alert('PO Enter Successfully')</script>";
            Page.RegisterStartupScript("PopUp", strScript);    
           
        }  
        else
        {
            string strScript = "<script language='JavaScript'>alert('PO Already Exist')</script>";
            Page.RegisterStartupScript("PopUp", strScript);         
           
           
        }      
            scon.Close();     


Clear fields after insterting records:
 TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
        TextBox5.Text = "";
        TextBox6.Text = "";
        TextBox7.Text = "";
        TextBox8.Text = "";


Data Search and fill the fields:
SqlConnection scon = new SqlConnection("Data Source=FAISALN;Initial Catalog=Shipping;Integrated Security=True");
        scon.Open();
        SqlCommand scmd = new SqlCommand("select PO from PO_Table where PO=@PO ", scon);
        scmd.Parameters.Add("PO", SqlDbType.Int).Value = TextBox1.Text;
        scmd.ExecuteScalar();
       
        if (scmd.ExecuteScalar() == null)
       
        {
            string strScript = "<script language='JavaScript'>alert('PO Not Found, Please Re-enter Your PO No')</script>";
            Page.RegisterStartupScript("PopUp", strScript);
            scon.Close();
       }
           
        else
        {
            SqlConnection scon1 = new SqlConnection("Data Source=FAISALN;Initial Catalog=Shipping;Integrated Security=True");
            SqlCommand scmd1 = new SqlCommand("select * from PO_Table where PO=@PO", scon1);
            scmd1.Parameters.Add("PO", SqlDbType.Int).Value = TextBox1.Text;
            SqlDataAdapter sda = new SqlDataAdapter(scmd1);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            TextBox1.Text = ds.Tables[0].Rows[0][0].ToString();
            TextBox2.Text = ds.Tables[0].Rows[0][1].ToString();
            TextBox3.Text = ds.Tables[0].Rows[0][2].ToString();
            TextBox4.Text = ds.Tables[0].Rows[0][4].ToString();
            TextBox5.Text = ds.Tables[0].Rows[0][5].ToString();
            TextBox6.Text = ds.Tables[0].Rows[0][6].ToString();
            TextBox7.Text = ds.Tables[0].Rows[0][7].ToString();
            TextBox8.Text = ds.Tables[0].Rows[0][8].ToString();
            DropDownList2.Text = ds.Tables[0].Rows[0][3].ToString();
            DropDownList3.Text = ds.Tables[0].Rows[0][9].ToString();
            DropDownList5.Text = ds.Tables[0].Rows[0][10].ToString();
            DropDownList4.Text = ds.Tables[0].Rows[0][11].ToString();
            scon1.Close();
                      
Update Data with aleart:
SqlConnection use = new SqlConnection(" Data Source=FAISALN;Initial Catalog=Shipping;Integrated Security=True ");
        SqlDataAdapter da = new SqlDataAdapter();
        da.UpdateCommand = new SqlCommand("update PO_Table set PO=@PO, Vendor=@Vendor, Buyer=@Buyer, Style_Ref=@Style_Ref, Price=@Price, Season=@Season, Order_Qty=@Order_Qty, PO_Ship_Date=@PO_Ship_Date, PO_Shipping_Month=@PO_Shipping_Month, PO_Shipping_Mode=@PO_Shipping_Mode, PO_Value=@PO_Value, PO_Destination=@PO_Destination where PO=@PO", use);
        da.UpdateCommand.Parameters.Add("@PO", SqlDbType.Int).Value = TextBox1.Text;
        da.UpdateCommand.Parameters.Add("@Style_Ref", SqlDbType.NVarChar).Value = TextBox2.Text;
        da.UpdateCommand.Parameters.Add("@PO_Destination", SqlDbType.NVarChar).Value = DropDownList3.Text;
        da.UpdateCommand.Parameters.Add("@Price", SqlDbType.Money).Value = TextBox3.Text;
        da.UpdateCommand.Parameters.Add("@Season", SqlDbType.NVarChar).Value = DropDownList2.Text;
        da.UpdateCommand.Parameters.Add("@Order_Qty", SqlDbType.Int).Value = TextBox4.Text;
        da.UpdateCommand.Parameters.Add("@PO_Ship_Date", SqlDbType.DateTime).Value = TextBox5.Text;
        da.UpdateCommand.Parameters.Add("@PO_Shipping_Month", SqlDbType.Char).Value = TextBox6.Text;
        da.UpdateCommand.Parameters.Add("@PO_Shipping_Mode", SqlDbType.Char).Value = TextBox7.Text;
        da.UpdateCommand.Parameters.Add("@PO_Value", SqlDbType.Int).Value = TextBox8.Text;
        da.UpdateCommand.Parameters.Add("@Vendor", SqlDbType.NVarChar).Value = DropDownList5.Text;
        da.UpdateCommand.Parameters.Add("@Buyer", SqlDbType.NVarChar).Value = DropDownList4.Text;
        use.Open();
        da.UpdateCommand.ExecuteNonQuery();
        use.Close();
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
        TextBox5.Text = "";
        TextBox6.Text = "";
        TextBox7.Text = "";
        TextBox8.Text = "";
        string strScript = "<script language='JavaScript'>alert('Record Update')</script>";
        Page.RegisterStartupScript("PopUp", strScript);
Delete Record:

 SqlConnection use = new SqlConnection(" Data Source=FAISALN;Initial Catalog=Shipping;Integrated Security=True ");
        SqlDataAdapter da = new SqlDataAdapter();
        da.DeleteCommand = new SqlCommand("delete from PO_Table where PO=@PO", use);
        da.DeleteCommand.Parameters.Add("@PO", SqlDbType.Int).Value = TextBox1.Text;
        da.DeleteCommand.Parameters.Add("@Style_Ref", SqlDbType.NVarChar).Value = TextBox2.Text;
        da.DeleteCommand.Parameters.Add("@PO_Destination", SqlDbType.NVarChar).Value = DropDownList3.Text;
        da.DeleteCommand.Parameters.Add("@Price", SqlDbType.Money).Value = TextBox3.Text;
        da.DeleteCommand.Parameters.Add("@Season", SqlDbType.NVarChar).Value = DropDownList2.Text;
        da.DeleteCommand.Parameters.Add("@Order_Qty", SqlDbType.Int).Value = TextBox4.Text;
        da.DeleteCommand.Parameters.Add("@PO_Ship_Date", SqlDbType.DateTime).Value = TextBox5.Text;
        da.DeleteCommand.Parameters.Add("@PO_Shipping_Month", SqlDbType.Char).Value = TextBox6.Text;
        da.DeleteCommand.Parameters.Add("@PO_Shipping_Mode", SqlDbType.Char).Value = TextBox7.Text;
        da.DeleteCommand.Parameters.Add("@PO_Value", SqlDbType.Int).Value = TextBox8.Text;
        da.DeleteCommand.Parameters.Add("@Vendor", SqlDbType.NVarChar).Value = DropDownList5.Text;
        da.DeleteCommand.Parameters.Add("@Buyer", SqlDbType.NVarChar).Value = DropDownList4.Text;
        use.Open();
        da.DeleteCommand.ExecuteNonQuery();
        use.Close();
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
        TextBox5.Text = "";
        TextBox6.Text = "";
        TextBox7.Text = "";
        TextBox8.Text = "";
Required Feild Validation:
<asp:RequiredFieldValidator runat="server" id="RFV" ControlToValidate="TextBox1" ErrorMessage="PO No Is Required" display="Static">
        </asp:RequiredFieldValidator>
Record Delete Alert

<asp:Button ID="Button5" Text="Delete" runat="server" Width="100px" onclick="Button5_Click" onclientclick="return confirm ('Are You Sure You Want To Delete This PO')" /> 

Wednesday, 28 March 2012

insert and updating delete and select using oledb access database in .net

using System.Data.OleDb;

public partial class _Default : System.Web.UI.Page
{
    OleDbDataAdapter da;
    DataSet ds;
   
    protected void Insert_Click(object sender, EventArgs e)
    {
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\Learning2\\App_Data\\tahir.accdb;Persist Security Info=False;");
        OleDbCommand comm = new OleDbCommand("INSERT INTO test VALUES(@roll_no, @st_name, @st_course)", conn);
        comm.Parameters.AddWithValue("@roll_no", TextBox1.Text);
        comm.Parameters.AddWithValue("@st_name", TextBox2.Text);
        comm.Parameters.AddWithValue("@st_course", TextBox3.Text);
        //ds = new DataSet();
        //da = new OleDbDataAdapter(comm);
        //da.Fill(ds);
        conn.Open();
        comm.ExecuteNonQuery();
        conn.Close();
    }

    protected void Delete_Click(object sender, EventArgs e)
    {
    OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\Learning2\\App_Data\\tahir.accdb;Persist Security Info=False;");
    OleDbCommand comm = new OleDbCommand("delete * from test where roll_no=@rollno ", conn);
    comm.Parameters.AddWithValue("@rollno", TextBox1.Text);
    conn.Open();
    comm.ExecuteNonQuery();
      
    }
    protected void Update_Click(object sender, EventArgs e)
    {
        OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\Learning2\\App_Data\\tahir.accdb;Persist Security Info=False;");
        OleDbCommand comm = new OleDbCommand("update test set st_name='Tahir' where roll_no=@rollno ", conn);
        comm.Parameters.AddWithValue("@rollno", TextBox1.Text);
        conn.Open();
        comm.ExecuteNonQuery();
      }
    protected void Display_Click(object sender, EventArgs e)
    {
        OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\Learning2\\App_Data\\tahir.accdb;Persist Security Info=False;");
        OleDbCommand comm = new OleDbCommand("select * from test where roll_no=@rollno ", conn);
        comm.Parameters.AddWithValue("@rollno",TextBox1.Text);
        da = new OleDbDataAdapter(comm);
        ds = new DataSet();
        da.Fill(ds);
       // GridView1.DataSource = ds;
       // GridView1.DataBind();
       // GridView1.Visible = true;
         TextBox2.Text = ds.Tables[0].Rows[0][1].ToString();
         TextBox3.Text = ds.Tables[0].Rows[0][2].ToString();
         da.Fill(ds);
        
       
    }
}

Wednesday, 21 March 2012

Inserting and connecting the MSAccess2007 with C# .net

OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\Learning2\\App_Data\\tahir.accdb;Persist Security Info=False;");
OleDbCommand comm = new OleDbCommand("INSERT INTO test VALUES(@roll_no, @st_name, @st_course)", conn);
comm.Parameters.AddWithValue("@roll_no", TextBox1.Text);
comm.Parameters.AddWithValue("@st_name", TextBox2.Text);
comm.Parameters.AddWithValue("@st_course", TextBox3.Text);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();

Wednesday, 14 March 2012

The best Example of Binary Operator Overloading in C++


#include<iostream>
using namespace std;

class Rational
{
private:
int num; // numerator
int den; // denominator
public:
void show();
Rational(int=1,int=1);
void setnumden(int,int);
Rational add(Rational object);
Rational operator+(Rational object);
bool operator==(Rational object);
bool operator!=(Rational object);
};

void Rational::show() {
cout << num << "/" << den << "\n";
}

Rational::Rational(int a,int b) {
setnumden(a,b);
}

void Rational::setnumden(int x,int y) {
int temp,a,b;
a = x;
b = y;
if(b > a) {
temp = b;
b = a;
a = temp;
}
while(a != 0 && b != 0) {
if(a % b == 0)
break;
temp = a % b;
a = b;
b = temp;
}
  num = x / b;
den = y / b;
}

Rational Rational::add(Rational object) {
int new_num = num * object.den + den * object.num;
int new_den = den * object.den;
return Rational(new_num, new_den);
}

Rational Rational::operator+(Rational object) {
int new_num = num * object.den + den * object.num;
int new_den = den * object.den;
return Rational(new_num, new_den);
}

bool Rational::operator==(Rational object) {
return (num == object.num && den == object.den);
}

bool Rational::operator!=(Rational object) {
return (num != object.num || den != object.den);
}

int main() {
Rational obj1(1,4), obj2(210,840), result1;
result1 = obj1.add(obj2);
result1.show();

Rational obj3(1,3), obj4(33,99), result2;
result2 = obj3 + obj4;
result2.show();

Rational obj5(10,14), obj6(25,35), obj7(2,3), obj8(1,2);

if(obj5 == obj6) {
cout << "The two fractions are equal." << endl;
}
if(obj7 != obj8) {
cout << "The two fractions are not equal." << endl;
}

return 0;
}