//Get:Transporter for update private void GetTransporterForUpdate() { if (!string.IsNullOrEmpty(Request.QueryString["Id"])) { divoptions.Style.Add("display", "block"); txtcode.Enabled = false; int id = Convert.ToInt32(Request.QueryString["Id"].ToString()); tblTransporter _transporter = repo.Get_TransporterById(id); if (_transporter != null) { txtcode.Text = _transporter.Code.ToString(); txtName.Text = _transporter.Name.ToString(); txtaddress1.Text = _transporter.Address1.ToString(); txtaddress2.Text = _transporter.Address2.ToString(); txtcity.Text = _transporter.City.ToString(); txtstate.Text = _transporter.State.ToString(); txtcountry.Text = _transporter.Country.ToString(); txtgstno.Text = _transporter.GSTNo.ToString(); txtpanno.Text = _transporter.PanNo.ToString(); txtperson.Text = _transporter.ContactPerson.ToString(); txtmobile.Text = _transporter.ContactMobile.ToString(); txtemail.Text = _transporter.ContactEmail.ToString(); } } }
public string Get_TransporterByCode(string code) { tblTransporter transporter = _transrepo.GetTransporter_ByCode(code.ToLower()); string myjsonresult = (new JavaScriptSerializer()).Serialize(transporter); return(myjsonresult); }
public string Check_Transporter(string code) { string s = string.Empty; tblTransporter t = _transrepo.GetTransporter_ByCode(code); if (t != null) { s = new JavaScriptSerializer().Serialize(t); } return(s); }
//Add:New Transporter Record public bool Add_Transporter(tblTransporter tran) { bool status = false; if (tran != null) { db.tblTransporters.InsertOnSubmit(tran); db.SubmitChanges(); status = true; } return(status); }
//Delete:Tranporter by Id public bool Delete_TransporterById(int id) { bool status = false; tblTransporter tran = db.tblTransporters.FirstOrDefault(x => x.Id == id && x.IsDeleted == false); if (tran != null) { tran.IsDeleted = true; db.SubmitChanges(); status = true; } return(status); }
//Get:Previous Transporter record protected void Previous_Record_Click(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString["Id"].ToString()); tblTransporter next = null; try { next = repo.GetTransportersList().Where(x => x.Id < id && x.IsDeleted == false).OrderByDescending(i => i.Id).FirstOrDefault(); } catch { } if (next != null) { Response.Redirect("AddEdit.aspx?id=" + next.Id.ToString()); } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "toastr", "toastr.success('No more records founds.')", true); } }
//Update:Transporter private void UpdateTransporter() { if (Request.QueryString["Id"] != null) { try { int id = Convert.ToInt32(Request.QueryString["Id"].ToString()); tblTransporter _tans = repo.GetTransportersList().Where(x => x.Code == txtcode.Text && x.IsDeleted == false && x.Id != id).FirstOrDefault(); if (_tans != null) { ClientScript.RegisterStartupScript(this.GetType(), "toastr", "toastr.error('Same Transporter code exist! Please try again');", true); } else { tblTransporter _trans = db.tblTransporters.FirstOrDefault(x => x.Id == id && x.IsDeleted == false); _trans.Code = txtcode.Text.ToString(); _trans.Name = txtName.Text.ToString(); _trans.Address1 = txtaddress1.Text.ToString(); _trans.Address2 = txtaddress2.Text.ToString(); _trans.City = txtcity.Text.ToString(); _trans.State = txtstate.Text.ToString(); _trans.Country = txtcountry.Text.ToString(); _trans.GSTNo = txtgstno.Text.ToString(); _trans.PanNo = txtpanno.Text.ToString(); _trans.ContactPerson = txtperson.Text.ToString(); _trans.ContactMobile = txtmobile.Text.ToString(); _trans.ContactEmail = txtemail.Text.ToString(); db.SubmitChanges(); ScriptManager.RegisterStartupScript(this, this.GetType(), "toastr", "toastr.success('Record Updated Successfully')", true); HtmlMeta meta = new HtmlMeta { HttpEquiv = "Refresh", Content = "3;url=AddEdit.aspx?id=" + id }; this.Page.Controls.Add(meta); } } catch { } } }
//Add:New Transporter private void AddTransporter() { if (Request.QueryString["Id"] == null) { tblTransporter _tran = repo.GetTransporter_ByCode(txtcode.Text.Trim()); if (_tran != null) { ScriptManager.RegisterStartupScript(this, this.GetType(), "toastr", "toastr.error('Same Transporter code exist! Please try again');", true); } else { tblTransporter _trans = new tblTransporter(); _trans.Code = txtcode.Text.ToString(); _trans.Name = txtName.Text.ToString(); _trans.Address1 = txtaddress1.Text.ToString(); _trans.Address2 = txtaddress2.Text.ToString(); _trans.City = txtcity.Text.ToString(); _trans.State = txtstate.Text.ToString(); _trans.Country = txtcountry.Text.ToString(); _trans.GSTNo = txtgstno.Text.ToString(); _trans.PanNo = txtpanno.Text.ToString(); _trans.ContactPerson = txtperson.Text.ToString(); _trans.ContactMobile = txtmobile.Text.ToString(); _trans.ContactEmail = txtemail.Text.ToString(); _trans.IsDeleted = false; if (repo.Add_Transporter(_trans)) { ScriptManager.RegisterStartupScript(this, this.GetType(), "toastr", "toastr.success('Save Successfully')", true); HtmlMeta meta = new HtmlMeta { HttpEquiv = "Refresh", Content = "1;url=AddEdit.aspx" }; this.Page.Controls.Add(meta); } } } }
//Get:Transporter By Id public tblTransporter Get_TransporterById(int id) { tblTransporter tran = db.tblTransporters.FirstOrDefault(x => x.Id == id && x.IsDeleted == false); return(tran); }
//Save:Excel data to the server public string SaveDataToServer(DataSet ds) { string result = string.Empty; using (DataClasses1DataContext db = new DataClasses1DataContext()) { string connection = ConfigurationManager.ConnectionStrings["AveryDBConnectionString"].ConnectionString; DataTable dt = ds.Tables[0]; int _failed = 0; int _success = 0; int _update = 0; foreach (DataRow dr in dt.Rows) { try { string _code = dr["Code"].ToString(); string _name = dr["Name"].ToString(); string _address1 = dr["Address1"].ToString(); string _address2 = dr["Address2"].ToString(); string _city = dr["City"].ToString(); string _state = dr["State"].ToString(); string _country = dr["Country"].ToString(); string _gstno = dr["GST No"].ToString(); string _panno = dr["PAN No"].ToString(); string _contactperson = dr["Contact Person"].ToString(); string _contactmobile = dr["Contact Mobile"].ToString(); string _contactemail = dr["Contact Email"].ToString(); var _transporter = db.tblTransporters.Where(x => x.Code == _code && x.IsDeleted == false).FirstOrDefault(); if (_transporter != null) { if (string.IsNullOrEmpty(_name)) { _failed++; } else { _transporter.Name = _name; _transporter.Address1 = _address1; _transporter.Address2 = _address2; _transporter.City = _city; _transporter.State = _state; _transporter.Country = _country; _transporter.GSTNo = _gstno; _transporter.PanNo = _panno; _transporter.ContactPerson = _contactperson; _transporter.ContactMobile = _contactmobile; _transporter.ContactEmail = _contactemail; db.SubmitChanges(); _update++; } } else { if (!string.IsNullOrEmpty(_code) && !string.IsNullOrEmpty(_name)) { tblTransporter _trans = db.tblTransporters.Where(x => x.Code == _code && x.IsDeleted == false).FirstOrDefault(); if (_trans != null) { _failed++; } else { db.tblTransporters.InsertOnSubmit(new tblTransporter { Code = _code, Name = _name, Address1 = _address1, Address2 = _address2, City = _city, State = _state, Country = _country, GSTNo = _gstno, PanNo = _panno, ContactPerson = _contactperson, ContactMobile = _contactmobile, ContactEmail = _contactemail, IsDeleted = false }); db.SubmitChanges(); _success++; } } else { _failed++; } } } catch { _failed++; } } result = "New Added: " + _success + " Updated: " + _update + " Failed: " + _failed + ""; } return(result); }
//Get:Transporter by transporter code public tblTransporter GetTransporter_ByCode(string code) { tblTransporter trans = db.tblTransporters.Where(x => x.Code == code && x.IsDeleted == false).SingleOrDefault(); return(trans); }