Monday, 20 May 2013

How can I automate my code?

How can I automate my code?

I already have a manual way on updating data from another server to my own server using these codes:
    protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            int rowIndex = Convert.ToInt32(e.CommandArgument);
            GridViewRow row = (sender as GridView).Rows[rowIndex];
            string strID = GridView1.DataKeys[row.RowIndex].Values[0].ToString();

            lblWO.Text = GridView1.Rows[row.RowIndex].Cells[1].Text.ToString();
            lblPN.Text = GridView1.Rows[row.RowIndex].Cells[9].Text.ToString();


            k();

            if (lblFLF.Text == "NO DATA FOUND")
            {
                btnSave.Visible = false;
                lblFLF.ForeColor = Color.Red;
                lblFLM.ForeColor = Color.Red;
                lblFWKG.ForeColor = Color.Red;
                lblFWLB.ForeColor = Color.Red;
                lblPieceNumber.ForeColor = Color.Red;
                lblFinalWO.ForeColor = Color.Red;
            }
            else
            {
                btnSave.Visible = true;
                lblStatus.Text = "";
                lblFLF.ForeColor = Color.Black;
                lblFLM.ForeColor = Color.Black;
                lblFWKG.ForeColor = Color.Black;
                lblFWLB.ForeColor = Color.Black;
                lblPieceNumber.ForeColor = Color.Black;
                lblFinalWO.ForeColor = Color.Black;
            }

        }
        catch (Exception) { }

    }

    protected void k()
    {

        SC = new SqlConnection(ConfigurationManager.ConnectionStrings["BABBLER"].ConnectionString);
        SC.Open();
        CMD = new SqlCommand("Select TOP(1) * from F564101D WHERE ZAWODES = '" + lblWO.Text + "' and ZAPIPLVER = '" + lblPN.Text + "'", SC);

        DR = CMD.ExecuteReader();

        if (DR.HasRows)
        {
            while (DR.Read())
            {
                lblFWLB.Text = (Convert.ToDouble(DR["ZAAWGT"]) / 1000).ToString();
                lblFWKG.Text =  System.Math.Round((Convert.ToDouble(lblFWLB.Text) * 0.453592), 0, MidpointRounding.AwayFromZero).ToString();
                lblFLM.Text = (Convert.ToDouble(DR["ZADILI"]) / 10000).ToString();
                lblFLF.Text = System.Math.Round((Convert.ToDouble(lblFLM.Text) * 0.00328084),1, MidpointRounding.AwayFromZero).ToString();
                lblPieceNumber.Text = Convert.ToDouble(DR["ZABSNN"]).ToString();
                lblFinalWO.Text = DR["ZAWTYPEDES"].ToString();

            }

        }
        else
        {
            lblFLF.Text = "NO DATA FOUND";
            lblFLM.Text = "NO DATA FOUND";
            lblFWKG.Text = "NO DATA FOUND";
            lblFWLB.Text = "NO DATA FOUND";
            lblFinalWO.Text = "NO DATA FOUND";
            lblPieceNumber.Text = "NO DATA FOUND";
        }
    }



    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
        if (lblFWKG.Text == "NO DATA FOUND")
        {
            lblStatus.Text = "Pipe is not yet saved in weighing";
        }
        else
        {
            string CS = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            using (SqlConnection con = new SqlConn

No comments:

Post a Comment