protected void AMS_Date_of_Purchase_TextChanged(object sender, EventArgs e) { try { if (Page.IsPostBack == true) { System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"^\d{4}$|^\d{4}-((0?\d)|(1[012]))-(((0?|[12])\d)|3[01])$"); if (regex.IsMatch(AMS_Date_of_Purchase.Text)) { if (AMS_PH_yearofManufacturer.Text != string.Empty) { DateTime currentdate = Convert.ToDateTime(DateTime.Now.ToString("dd/MM/yyyy")); DateTime manufacturedate = DateTime.Parse(AMS_PH_yearofManufacturer.Text, new CultureInfo("gu-IN", false)); DateTime purchasedate = DateTime.Parse(AMS_Date_of_Purchase.Text, new CultureInfo("gu-IN", false)); if (purchasedate > currentdate) { ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Date of purchase should not be greater than today');", true); AMS_Date_of_Purchase.Text = null; AMS_Date_of_Purchase.Focus(); } else if (purchasedate < manufacturedate) { ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Date of purchase should not be Lesser than Year of Manufacturer.');", true); AMS_Date_of_Purchase.Text = null; AMS_Date_of_Purchase.Focus(); } else { AMS_PH_Warranty.Focus(); DOPLabel.Visible = false; } } else { ClientScript.RegisterStartupScript(GetType(), "alert", "alert('First you should fill Year of manufacture');", true); //AMS_Date_of_Purchase.Text = String.Empty.ToString(); AMS_Date_of_Purchase.Text = null; AMS_PH_yearofManufacturer.Focus(); DOPLabel.Visible = false; } DOPLabel.Visible = false; } else { AMS_Date_of_Purchase.Text = ""; DOPLabel.Visible = true; } //Search_TextBox.Visible = false; //Search_LinkButton.Visible = false; } //Search_TextBox.Visible = false; //Search_LinkButton.Visible = false; } catch (Exception ex) { //string message = string.Format("Message: {0}\\n\\n", ex.Message); //message += string.Format("StackTrace: {0}\\n\\n", ex.StackTrace.Replace(Environment.NewLine, string.Empty)); //message += string.Format("Source: {0}\\n\\n", ex.Source.Replace(Environment.NewLine, string.Empty)); //message += string.Format("TargetSite: {0}", ex.TargetSite.ToString().Replace(Environment.NewLine, string.Empty)); //// ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"" + message + "\");", true); //Session["eswar"] = message; //Session["pagename"] = "HardwareAssets.aspx"; //Response.Redirect("Errorpage.aspx"); throw ex; } }
protected void Insert_Click(object sender, EventArgs e) { try { SqlConnection con = new SqlConnection(constr); SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "master_hw_proc"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@AMS_AssetType", SqlDbType.NVarChar).Value = "Hardware Assets"; cmd.Parameters.Add("@AMS_Asset_Location", SqlDbType.NVarChar).Value = AMS_Asset_Locationn.SelectedValue.Trim(); cmd.Parameters.Add("@AMS_AssetName", SqlDbType.NVarChar).Value = AMS_Asset_Name.Text.Trim(); cmd.Parameters.Add("@AMS_Asset_Size", SqlDbType.NVarChar).Value = "NA"; cmd.Parameters.Add("@AMS_Asset_Cost", SqlDbType.Money).Value = Math.Round(float.Parse(AMS_Asset_Cost.Text.Trim()), 2, MidpointRounding.AwayFromZero); cmd.Parameters.Add("@AMS_Company_Location", SqlDbType.NVarChar).Value = AMS_Asset_Locationn.SelectedValue.Trim(); cmd.Parameters.Add("@AMS_Date_of_Purchase", SqlDbType.NVarChar).Value = AMS_Date_of_Purchase.Text.Trim(); cmd.Parameters.Add("@AMSHW_PH_Warranty", SqlDbType.NVarChar).Value = AMS_PH_Warranty.Text.Trim() + selectyears.SelectedValue; cmd.Parameters.Add("@AMSHW_PH_Characterstics", SqlDbType.NVarChar).Value = AMS_Characteristics.Text.Trim(); //cmd.Parameters.Add("@AMSHW_PH_Allotted_Employee", SqlDbType.NVarChar).Value = AMSHW_PH_Allotted_Emp.Text.Trim(); cmd.Parameters.Add("@AMSHW_PH_Allotted_Employee", SqlDbType.NVarChar).Value = "NA"; cmd.Parameters.Add("@AMSHW_PH_Replacement_Date", SqlDbType.NVarChar).Value = "NA"; cmd.Parameters.Add("@AMSHW_PH_Replacement_Reason", SqlDbType.NVarChar).Value = "NA"; cmd.Parameters.Add("@AMSHW_PH_Depreciation_Cost", SqlDbType.Money).Value = 0; cmd.Parameters.Add("@AMSHW_PH_make", SqlDbType.NVarChar).Value = AMS_PH_Make.Text.Trim(); cmd.Parameters.Add("@AMSHW_PH_Model", SqlDbType.NVarChar).Value = AMS_PH_Model.Text.Trim(); cmd.Parameters.Add("@AMSHW_PH_Year_Of_Mfd", SqlDbType.NVarChar).Value = AMS_PH_yearofManufacturer.Text.Trim(); if (AMS_Asset_Locationn.SelectedValue == "Vijayawada") { cmd.Parameters.Add("@SN_NAME", SqlDbType.NVarChar).Value = "SNVIJ"; } else if (AMS_Asset_Locationn.SelectedValue == "Hyderabad") { cmd.Parameters.Add("@SN_NAME", SqlDbType.NVarChar).Value = "SNHYD"; } else if (AMS_Asset_Locationn.SelectedValue == "Bengaluru") { cmd.Parameters.Add("@SN_NAME", SqlDbType.NVarChar).Value = "SNBEN"; } else if (AMS_Asset_Locationn.SelectedValue == "Mumbai") { cmd.Parameters.Add("@SN_NAME", SqlDbType.NVarChar).Value = "SNMUM"; } else { cmd.Parameters.Add("@SN_NAME", SqlDbType.NVarChar).Value = "NA"; } if (Warrenty_Status.SelectedIndex == 0) { WarrentyStatusRequiredFieldValidator.IsValid = false; } else if (Warrenty_Status.SelectedIndex == 1 || Warrenty_Status.SelectedIndex == 2) { cmd.Parameters.Add("@HW_Warrenty_Status", SqlDbType.NVarChar).Value = Warrenty_Status.Text.Trim(); } if (Remarks.Text == String.Empty.ToString()) { cmd.Parameters.Add("@Remarks", SqlDbType.NVarChar).Value = "NA"; cmd.Parameters.Add("@AMS_Remarks", SqlDbType.NVarChar).Value = "NA"; } else if (Remarks.Text != String.Empty.ToString()) { cmd.Parameters.Add("@Remarks", SqlDbType.NVarChar).Value = Remarks.Text.Trim(); cmd.Parameters.Add("@AMS_Remarks", SqlDbType.NVarChar).Value = Remarks.Text.Trim(); } if (selectyears.SelectedIndex == 1) { Int32 x = Convert.ToInt32(this.AMS_PH_Warranty.Text); DateTime EntryDate = Convert.ToDateTime(AMS_Date_of_Purchase.Text); string s = EntryDate.AddYears(x).ToShortDateString(); cmd.Parameters.Add("@AMSHW_WarrantyExpireDate", SqlDbType.DateTime).Value = s; cmd.Parameters.Add("@AMSHW_Email", SqlDbType.NVarChar).Value = Session["SessionUserMailID"]; } else if (selectyears.SelectedIndex == 2) { Int32 x = Convert.ToInt32(this.AMS_PH_Warranty.Text); DateTime EntryDate = Convert.ToDateTime(AMS_Date_of_Purchase.Text); string s = EntryDate.AddMonths(x).ToShortDateString(); cmd.Parameters.Add("@AMSHW_WarrantyExpireDate", SqlDbType.DateTime).Value = s; cmd.Parameters.Add("@AMSHW_Email", SqlDbType.NVarChar).Value = Session["SessionUserMailID"]; } //SqlConnection con1 = new SqlConnection(constr); //SqlCommand cmd1 = new SqlCommand(); //DataTable dt1 = new DataTable(); //SqlDataAdapter sd1 = new SqlDataAdapter("select s.AMSHW_PH_Serial_Number, a.AMS_AssetName from Asset_Master a join Hardware_Physical_Assets s on s.AMSHW_PH_AssetID = a.AMS_AssetID where s.AMSHW_PH_Serial_Number='" + AMS_PH_SerialNumber.Text + "'", con1); //sd1.Fill(dt1); DateTime manufacturedate = DateTime.Parse(AMS_PH_yearofManufacturer.Text, new CultureInfo("gu-IN", false)); DateTime purchasedate = DateTime.Parse(AMS_Date_of_Purchase.Text, new CultureInfo("gu-IN", false)); //if (dt1.Rows.Count >= 1) //{ // ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Asset already exists');", true); // AMS_PH_SerialNumber.Text = string.Empty; // AMS_PH_yearofManufacturer.Focus(); //} if (purchasedate < manufacturedate) { ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Year of Manufacturer should be Less than Date of purchase');", true); AMS_PH_yearofManufacturer.Text = null; AMS_PH_yearofManufacturer.Focus(); } else { cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); con.Dispose(); Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('Hardware Asset Inserted Successfully.');window.location.href='../Admin/Hardware-Assets.aspx';</script>"); } } catch (Exception ex) { //string message = string.Format("Message: {0}\\n\\n", ex.Message); //message += string.Format("StackTrace: {0}\\n\\n", ex.StackTrace.Replace(Environment.NewLine, string.Empty)); //message += string.Format("Source: {0}\\n\\n", ex.Source.Replace(Environment.NewLine, string.Empty)); //message += string.Format("TargetSite: {0}", ex.TargetSite.ToString().Replace(Environment.NewLine, string.Empty)); ////ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"" + message + "\");", true); //Session["eswar"] = message; //Session["pagename"] = "Add-Hardware-Assets.aspx"; //Response.Redirect("Errorpage.aspx"); throw ex; } }