Copying and Pasting cs Code

In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.

For example, you can follow the pattern in this listing:

         private void btnsave_Click(object sender, EventArgs e)
         {

             foreach(Control obj in pnl_stockmaster.Controls)
             {
                 if(obj is TextBox)
                 {
                     if(obj.Text == "")
                     {
                         MessageBox.Show("Action connot be perform. All fields are required to be fill up.", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                         return;
                     }
                 }
             }



             sql = "INSERT INTO `tblstock_in_out` (`ITEMID`, `QTY`,`TRANSACTIONDATE`, `TOTALPRICE`, `REMARKS`)" +
               " VALUES ('" + txtitemid.Text + "','" + txtqty.Text + "','" + DateTime.Now.ToString("yyyy-MM-dd") + "','" + txtprice.Text +
               "','StockIn')";
            config.Execute_Query(sql);


             sql = "SELECT ITEMID FROM tblitems WHERE ITEMID='" + txtitemid.Text + "'";
             config.singleResult(sql);
             if(config.dt.Rows.Count > 0)
             {
                 sql = "UPDATE tblitems SET qty =qty + '" + txtqty.Text + "' WHERE ITEMID ='" + txtitemid.Text + "'";
                 config.Execute_Query(sql);
             }
             else
             {
                 sql = "insert into tblitems (ITEMID,`NAME`, `DESCRIPTION`, `TYPE`, `PRICE`, `QTY`,UNIT)" +
                    "VALUES ('" + txtitemid.Text + "','" + txtname.Text + "','" + txtdescription.Text + "','" + cbotype.Text
                    + "','" + txtprice.Text + "','" + txtqty.Text + "','" + cbounit.Text + "' )";
                 config.Execute_CUD(sql, "No data saved.", "Data has been saved in the database.");

                 config.update_Autonumber(cbotype.Text);
             }

             btnnew_Click(sender, e);

         }