Esempio n. 1
0
    protected void btnLockHour_Click(object sender, EventArgs e)
    {
        bool  inset = false;
        DSTUM dstum = new DSTUM();
        User  user1 = DstumDAL.getUserdetails(Context.User.Identity.Name);

        dstum.userid        = user1.userid;
        dstum.Todaydate     = DateTime.Now.ToString("yyyy/MM/dd");;
        dstum.aid           = Convert.ToInt32(ddlairtifact.SelectedValue.ToString());
        dstum.Todayhour     = Convert.ToInt32(txttodayhour.Text.ToString());
        dstum.yesterdayHour = Convert.ToInt32(txtYesterdayhour.Text.ToString());
        dstum.desc          = txtdesc.Text.ToString();



        try
        {
            inset = DstumDAL.lockHour(dstum);
        }
        catch (Exception ex)
        {
        }
        if (inset == true)
        {
            Response.Write(@"<script language='javascript'>window.alert('Lock Your hour successfully \n ');</script>");

            txtdesc.Text          = "";
            txttodayhour.Text     = "";
            txtYesterdayhour.Text = "";
            DataBindGrid();
        }
        else
        {
            Response.Write(@"<script language='javascript'>alert('some error is occurs \n ');</script>");
        }
    }
Esempio n. 2
0
    public static bool lockHour(DSTUM dstum)
    {
        try
        {
            bool inserted = false;

            if (dstum.aid < 0)
            {
                String query = "insert into [dstum](todaydate,userid,todayhour,yesterdayhour,[desc]) " +
                               " values(@todaydate, @userid,@todayhour,@yesterdayhour,@desc)";


                cmd = new SqlCommand(query, conn);



                cmd.Parameters.AddWithValue("@todaydate", dstum.Todaydate);
                cmd.Parameters.AddWithValue("@userid", dstum.userid);

                cmd.Parameters.AddWithValue("@todayhour", dstum.Todayhour);
                cmd.Parameters.AddWithValue("@yesterdayhour", dstum.yesterdayHour);
                cmd.Parameters.AddWithValue("@desc", dstum.desc);

                conn.Open();
                int dr = cmd.ExecuteNonQuery();
                if (dr > 0)
                {
                    inserted = true;
                }
            }
            else
            {
                String query = "insert into [dstum](todaydate,userid,aid,todayhour,yesterdayhour,[desc]) " +
                               " values(@todaydate, @userid,@aid,@todayhour,@yesterdayhour,@desc)";


                using (cmd = new SqlCommand(query, conn))
                {
                    cmd.Parameters.AddWithValue("@todaydate", dstum.Todaydate);
                    cmd.Parameters.AddWithValue("@userid", dstum.userid);
                    cmd.Parameters.AddWithValue("@aid", dstum.aid);
                    cmd.Parameters.AddWithValue("@todayhour", dstum.Todayhour);
                    cmd.Parameters.AddWithValue("@yesterdayhour", dstum.yesterdayHour);
                    cmd.Parameters.AddWithValue("@desc", dstum.desc);

                    conn.Open();
                    int dr = cmd.ExecuteNonQuery();
                    if (dr > 0)
                    {
                        inserted = true;
                    }
                    conn.Close();
                }



                String updatequery      = "update artifact set lock_hour=@lock_hour where AID=@aid";
                int    lockhour         = getlockHourforArtifact(dstum.aid);
                int    updaatedlockhour = lockhour + dstum.yesterdayHour;
                cmd = new SqlCommand(updatequery, conn);

                cmd.Parameters.AddWithValue("@lock_hour", updaatedlockhour);
                cmd.Parameters.AddWithValue("@aid", dstum.aid);


                conn.Open();
                int dr1 = cmd.ExecuteNonQuery();
                if (dr1 > 0)
                {
                    inserted = true;
                }
                conn.Close();
            }
            return(inserted);
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            conn.Close();
        }
    }