Dear Sir,
Please help me sir to complete my task.
if compaint lodge date in greater then 3 hours then cell font color red.
if compaint lodge date in less then 3 hours then cell font color red.
namespace OCMS
{
public partial class nw_it_adm : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=10.1.246.4;Initial Catalog=OCMS;User ID=dba_ntpc_meja_intranet;Password=alpha$890;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
refreshdata();
}
}
protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
SqlConnection con = new SqlConnection(@"Data Source=10.1.246.4;Initial Catalog=OCMS;User ID=dba_ntpc_meja_intranet;Password=alpha$890;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
DropDownList DropDownList1 = (e.Row.FindControl("DropDownList1") as DropDownList);
SqlCommand cmd = new SqlCommand("select * from complaint_status", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "STATUS_NAME";
DropDownList1.DataValueField = "STATUS_NAME";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("-Select Status-", "0"));
DropDownList DropDownList2 = (e.Row.FindControl("DropDownList2") as DropDownList);
cmd = new SqlCommand("select * from Assign_to", con);
sda = new SqlDataAdapter(cmd);
dt = new DataTable();
sda.Fill(dt);
DropDownList2.DataSource = dt;
DropDownList2.DataTextField = "STATUS_NAME";
DropDownList2.DataValueField = "STATUS_NAME";
DropDownList2.DataBind();
DropDownList2.Items.Insert(0, new ListItem("-Select Name-", "0"));
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView dr = (DataRowView)e.Row.DataItem;
HtmlImage img = e.Row.FindControl("Image1") as HtmlImage;
if (!Convert.IsDBNull(dr["Image"]))
{
(e.Row.FindControl("Image1") as HtmlImage).Src = dr["Image"].ToString();
}
else
{
img.Visible = false;
}
if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowIndex != GridView1.EditIndex)
{
//(e.Row.Cells[3].Controls[2] as LinkButton).Attributes["onclick"] = "return confirm('Do you want to delete this row?');";
DateTime time = Convert.ToDateTime((e.Row.FindControl("lblDate") as Label).Text);
// if (time.ToString("tt").ToUpper() == "PM")
if (time.Subtract(DateTime.Now).TotalHours < 3)
{
(e.Row.FindControl("lblDate") as Label).ForeColor = Color.Blue;
}
// if (time.ToString("tt").ToUpper() == "AM")
if (time.Subtract(DateTime.Now).TotalHours > 3)
{
(e.Row.FindControl("lblDate") as Label).ForeColor = Color.Red;
}
}
}
}
public void refreshdata()
{
con.Open();
//SqlCommand cmd = new SqlCommand("select * from comp_box where closing_date IS NULL ORDER BY COMP_ID DESC ", con);
SqlCommand cmd = new SqlCommand("select * from comp_box,emp where closing_date IS NULL and comp_box.emp_id=emp.emp_id order by COMP_ID desc", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
con.Close();
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void Update(object sender, EventArgs e)
{
GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
DropDownList dropDownList1 = row.FindControl("DropDownList1") as DropDownList;
DropDownList dropDownList2 = row.FindControl("DropDownList2") as DropDownList;
if (dropDownList1.SelectedIndex > 0)
{
dropDownList1.Enabled = false;
}
if (dropDownList2.SelectedIndex > 0)
{
dropDownList2.Enabled = false;
}
int COMP_ID = Convert.ToInt32(GridView1.DataKeys[Convert.ToInt32((sender as Button).CommandArgument)].Values[0]);
string STATUS_ID = dropDownList1.SelectedItem.Text;
string ATTEND_BY = dropDownList2.SelectedItem.Text;
// string remark = (row.FindControl("TextBox5") as TextBox).Text;
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("UPDATE comp_box SET STATUS_ID = @STATUS_ID, ATTEND_BY = @ATTEND_BY WHERE COMP_ID = @COMP_ID"))
{
cmd.Parameters.AddWithValue("@STATUS_ID", STATUS_ID);
cmd.Parameters.AddWithValue("@ATTEND_BY", ATTEND_BY);
cmd.Parameters.AddWithValue("@COMP_ID", COMP_ID);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
protected void Closed(object sender, EventArgs e)
{
GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
int COMP_ID = Convert.ToInt32(GridView1.DataKeys[Convert.ToInt32((sender as Button).CommandArgument)].Values[0]);
string STATUS_ID = "02";
string remark = (row.FindControl("TextBox5") as TextBox).Text;
string CLOSING_DATE = DateTime.Now.ToString();
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("UPDATE comp_box SET STATUS_ID = @STATUS_ID, REMARKS = @REMARKS,CLOSING_DATE = @CLOSING_DATE WHERE COMP_ID = @COMP_ID"))
{
cmd.Parameters.AddWithValue("@COMP_ID", COMP_ID);
cmd.Parameters.AddWithValue("@STATUS_ID", STATUS_ID);
cmd.Parameters.AddWithValue("@REMARKS", remark);
cmd.Parameters.AddWithValue("@CLOSING_DATE", CLOSING_DATE);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
string PHONE_MOB = row.Cells[4].Text;
string SMSurl = string.Format("http://185.255.8.59/sms/1/text/query?username=NTpc&password=NTpc@321&from=MUNPLA&to={0}&text=Your OCMS Complaint No:{1} has been resolved successfully - Meja Urja Nigam PVT. LTD. &indiaDltContentTemplateId=1207164466650628862&indiaDltPrincipalEntityId=1201159222154902387", PHONE_MOB, COMP_ID);
//string SMSurl = "http://185.255.8.59/sms/1/text/query?username=NTpc&password=NTpc@321&from=MUNPLA&to= + PHONE_MOB + &text=Your OCMS Complaint No:" + COMP_ID + " has been resolved successfully - Meja Urja Nigam PVT. LTD. &indiaDltContentTemplateId=1207164466650628862&indiaDltPrincipalEntityId=1201159222154902387";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(SMSurl);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
GridView1.EditIndex = -1;
row.Visible = false;
}
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}