예제 #1
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                lblerror.Text   = string.Empty;
                lblSuccess.Text = string.Empty;

                if (txtTimeEntryDate.Text.ToString() == string.Empty)
                {
                    lblerror.Visible = true;
                    lblerror.Text    = "Kindly Enter the Date";
                    return;
                }

                //if (txtFileReference.Text.ToString() == string.Empty)
                //{
                //    lblerror.Visible = true;
                //    lblerror.Text = "Kindly Enter the File Reference";
                //    return;
                //}
                if (ddlTask.Text.ToString() == strSelect.ToString())
                {
                    lblerror.Visible = true;
                    lblerror.Text    = "Kindly select the Task";
                    return;
                }

                if (txtDescription.Text.ToString() == string.Empty)
                {
                    lblerror.Visible = true;
                    lblerror.Text    = "Kindly Enter the Task Description";
                    return;
                }
                if (rbtnKeyInAmt.Checked)
                {
                    if (txtDuration.Text.ToString() == string.Empty)
                    {
                        lblerror.Visible = true;
                        lblerror.Text    = "Kindly Enter the Duration";
                        return;
                    }
                }
                if (rbtnKeyInAmt.Checked)
                {
                    if (txtBillableUnit.Text.ToString() == string.Empty)
                    {
                        lblerror.Visible = true;
                        lblerror.Text    = "Kindly Enter the Billable Unit";
                        return;
                    }
                }
                if (rbtnFixedAmt.Checked)
                {
                    if (txtFixedAmount.Text.ToString() == string.Empty)
                    {
                        lblerror.Visible = true;
                        lblerror.Text    = "Kindly Enter the Fixed Amount";
                        return;
                    }
                }

                DataTable dt = new DataTable();
                dt.TableName = "tbl_TimeEntry";
                dt           = CreateTableColumns(dt);
                string sResult = string.Empty;
                if (Request.Cookies[Constants.Update] == null)
                {
                    sResult = oTimeEntry.CreateTimeEntry(dt);
                }
                else
                {
                    if (Request.Cookies[Constants.Update].Value == string.Empty || Request.Cookies[Constants.Update].Value == "")
                    {
                        sResult = oTimeEntry.CreateTimeEntry(dt);
                    }
                    else
                    {
                        sResult = oTimeEntry.UpdateTimeEntry(dt);
                    }
                }
                if (sResult == Constants.Insert)
                {
                    lblerror.Visible = false;
                    lblerror.Text    = string.Empty;

                    ClearFields();
                    string  sUserCode    = Convert.ToString(Request.Cookies[Constants.UserCode].Value);
                    string  sCompanyCode = Convert.ToString(Request.Cookies[Constants.CompanyCode].Value);
                    DataSet ds           = oTimeEntry.GetRecords(sUserCode, sCompanyCode);
                    if (ds != null && ds.Tables[0].Rows.Count > 0)
                    {
                        ViewState["Records"]         = ds.Tables[0];
                        ViewState["FilteredRecords"] = ds.Tables[0];
                        grvTimeEntry.DataSource      = ds.Tables[0];
                        grvTimeEntry.DataBind();
                    }
                    lblSuccess.Visible = true;
                    lblSuccess.Text    = "Time Entry Created successfully";
                    lblSuccess.Focus();
                }
                else if (sResult == Constants.Update)
                {
                    //Response.Cookies[Constants.Update].Expires = DateTime.Now;
                    lblerror.Visible = false;
                    lblerror.Text    = string.Empty;

                    ClearFields();
                    string  sUserCode    = Convert.ToString(Request.Cookies[Constants.UserCode].Value);
                    string  sCompanyCode = Convert.ToString(Request.Cookies[Constants.CompanyCode].Value);
                    DataSet ds           = oTimeEntry.GetRecords(sUserCode, sCompanyCode);
                    if (ds != null && ds.Tables[0].Rows.Count > 0)
                    {
                        ViewState["Records"]         = ds.Tables[0];
                        ViewState["FilteredRecords"] = ds.Tables[0];
                        grvTimeEntry.DataSource      = ds.Tables[0];
                        grvTimeEntry.DataBind();
                    }
                    lblSuccess.Visible = true;
                    lblSuccess.Text    = "Time Entry updated successfully";
                    lblSuccess.Focus();
                }
                else
                {
                    lblerror.Visible = true;
                    lblerror.Text    = sResult;
                }
            }
            catch (Exception ex)
            {
                lblerror.Visible = true;
                lblerror.Text    = ex.Message.ToString();
                grvSearch.DataBind();
                oLog.WriteToLogFile_Debug("Completed with Error", ex.Message.ToString());
                oLog.WriteToLogFile("Completed with Error", ex.Message.ToString());
                // Get stack trace for the exception with source file information
                var st = new StackTrace(ex, true);
                // Get the top stack frame
                var frame = st.GetFrame(0);
                // Get the line number from the stack frame
                var line = frame.GetFileLineNumber();
                oLog.WriteToLogFile("Error Line Number", line.ToString());
            }
        }