public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; int User_ID = Convert.ToInt32(context.Request["User_ID"]); String contact = context.Request["Contact"]; Contact cont = JsonConvert.DeserializeObject <Contact>(contact); MySqlHelper helper1 = new MySqlHelper(); MySqlDataReader reader1 = helper1.getMySqlReader("select count(*) from contact where User_ID=" + User_ID + ";"); reader1.Read(); int id = User_ID * 10000 + reader1.GetInt32(0); String sql = "insert into contact (ID,User_ID,Name) Values (" + id + "," + User_ID + ",\"" + cont.Name + "\");"; reader1.Close(); reader1.Dispose(); helper1.mysqlcom.Dispose(); helper1.mysqlcon.Close(); helper1.mysqlcon.Dispose(); MySqlHelper helper = new MySqlHelper(); if (helper.getMySqlCom(sql) > 0) { sql = "insert into contact_info (EmailOrNumber,Number,Type,Contact_ID) values "; if (cont.ContactInfos != null) { for (int j = 0; j < cont.ContactInfos.Count; j++) { if (sql.Length < 75) { sql += "(" + cont.ContactInfos[j].EmailOrNumber + ",\"" + cont.ContactInfos[j].Number + "\",\"" + cont.ContactInfos[j].Type + "\"," + id + ")"; } else { sql += ",(" + cont.ContactInfos[j].EmailOrNumber + ",\"" + cont.ContactInfos[j].Number + "\",\"" + cont.ContactInfos[j].Type + "\"," + id + ")"; } if (j == cont.ContactInfos.Count - 1) { if (helper.getMySqlCom(sql) > 0) { context.Response.Write("OK"); } else { context.Response.Write("Error"); } } } } else { context.Response.Write("OK"); } } else { context.Response.Write("Error"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; int Contact_ID = Convert.ToInt32(context.Request["Contact_ID"]); String contact = context.Request["Contact"]; String birthday = context.Request["Birthday"]; Contact cont = JsonConvert.DeserializeObject <Contact>(contact); MySqlHelper helper = new MySqlHelper(); helper.getMySqlCom("DELETE FROM Contact_Info where Contact_ID=" + Contact_ID); if (helper.getMySqlCom("UPDATE Contact SET Name='" + cont.Name + "',Birthday='" + birthday + "' where ID=" + Contact_ID) > 0) { String sql = "insert into contact_info (EmailOrNumber,Number,Type,Contact_ID) values "; if (cont.ContactInfos != null) { for (int j = 0; j < cont.ContactInfos.Count; j++) { if (sql.Length < 75) { sql += "(" + cont.ContactInfos[j].EmailOrNumber + ",\"" + cont.ContactInfos[j].Number + "\",\"" + cont.ContactInfos[j].Type + "\"," + Contact_ID + ")"; } else { sql += ",(" + cont.ContactInfos[j].EmailOrNumber + ",\"" + cont.ContactInfos[j].Number + "\",\"" + cont.ContactInfos[j].Type + "\"," + Contact_ID + ")"; } if (j == cont.ContactInfos.Count - 1) { if (helper.getMySqlCom(sql) > 0) { context.Response.Write("OK"); } else { context.Response.Write("Error"); } } } } else { context.Response.Write("OK"); } } else { context.Response.Write("Error"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //获取请求参数 int contact_info_ID = Convert.ToInt16(context.Request["contact_info_ID"]), contact_email = Convert.ToInt16(context.Request["contact_email"]); string contact_number = context.Request["contact_number"].ToString(), contact_type = context.Request["contact_type"].ToString(); StringBuilder stb = new StringBuilder(); stb.Append("update contact_info set Number= '"); stb.Append(contact_number); stb.Append("',"); stb.Append("EmailorNumber="); stb.Append(contact_email); stb.Append(","); stb.Append("Type='"); stb.Append(contact_type); stb.Append("' where ID="); stb.Append(contact_info_ID); MySqlHelper helper = new MySqlHelper(); if (helper.getMySqlCom(stb.ToString(), null) > 0) { //返回响应信息 context.Response.Write("OK"); } else { context.Response.Write("Error"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; int Contact_ID = Convert.ToInt32(context.Request["Contact_ID"]); MySqlHelper helper = new MySqlHelper(); helper.getMySqlCom("DELETE FROM Contact_Info where Contact_ID=" + Contact_ID); if (helper.getMySqlCom("DELETE FROM Contact where ID=" + Contact_ID) > 0) { context.Response.Write("OK"); } else { context.Response.Write("Error"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; String UserName = context.Request["UserName"]; String Old = context.Request["Password"]; String Ne = context.Request["NewPassword"]; MySqlHelper helper = new MySqlHelper(); if (helper.getMySqlCom("UPDATE User Set Password='******' where UserName='******' And Password='******'") > 0) { context.Response.Write("OK"); } else { context.Response.Write("Error"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; String UserName = context.Request["UserName"]; String remark = context.Request["Remark"]; String Sex = context.Request["Sex"]; String Location = context.Request["Location"]; MySqlHelper helper = new MySqlHelper(); if (helper.getMySqlCom("UPDATE User Set Remark='" + remark + "',Location='" + Location + "',Sex='" + Sex + "' where UserName='******'") > 0) { context.Response.Write("OK"); } else { context.Response.Write("Error"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; String ID = context.Request["Contact_ID"]; String Birthday = context.Request["Birthday"]; String sql = "update Contact set Birthday='" + Birthday + "' where ID='" + ID + "'"; MySqlHelper helper = new MySqlHelper(); int count = helper.getMySqlCom(sql); if (count > 0) { context.Response.Write("OK"); } else { context.Response.Write("ERROR"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //获取请求参数 String UserName = context.Request["UserName"], Password = context.Request["Password"], Sex = context.Request["Sex"], Location = context.Request["Location"], Remark = context.Request["Remark"]; //构建数据库操作语句 String sql = "insert into user (UserName,Password,Sex,Location,Remark,Signcount) Values (@u,@p,@s,@l,@r,@c);"; //构建参数数组 MySqlParameter[] pms = { new MySqlParameter("@u", UserName), new MySqlParameter("@p", Password), new MySqlParameter("@s", Sex), new MySqlParameter("@l", Location), new MySqlParameter("@r", Remark), new MySqlParameter("@c", 0) }; //创建帮助类(自己写的) MySqlHelper helper = new MySqlHelper(); //调用帮助类中的方法 //getMySqlReader()对数据库进行查询,返回MySqlDataReader //getMySqlCom()对数据库进行增删改操作,返回影响行数 //进行相关判断 if (helper.getMySqlCom(sql, pms) > 0) { //返回响应信息 context.Response.Write("OK"); } else { context.Response.Write("Error"); } //进行测试 }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; String UserName = context.Request["UserName"]; String sql = "select Sign,SignCount from user where UserName='******'"; MySqlHelper helper = new MySqlHelper(); MySqlDataReader reader = helper.getMySqlReader(sql); reader.Read(); String today = DateTime.Today.Year + "-" + (DateTime.Today.Month > 9 ? "" + DateTime.Today.Month : "0" + DateTime.Today.Month) + "-" + DateTime.Today.Day; String ss = reader.IsDBNull(0) ? "" : reader.GetString(0); String Sign = ((ss.Equals("")?"": (reader.GetString(0) + ",")) + today); int SignCount = reader.IsDBNull(1)?1:reader.GetInt32(1) + 1; helper.mysqlcom.Dispose(); helper.mysqlcon.Close(); helper.mysqlcon.Dispose(); if (SignCount != 1) { if (ss.Split(',')[SignCount - 2].Equals(today)) { reader.Dispose(); context.Response.Write("Sign:" + ss + ";SignCount:" + (SignCount - 1)); return; } } reader.Dispose(); if (helper.getMySqlCom("Update User set Sign='" + Sign + "',SignCount=" + SignCount + " where UserName='******'") > 0) { context.Response.Write("Sign:" + Sign + ";SignCount:" + SignCount); } else { context.Response.Write("ERROR"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; String UserName = context.Request["UserName"]; String contact = context.Request["Contact"]; String record = context.Request["Record"]; RootObject rb = JsonConvert.DeserializeObject <RootObject>("{\"Contact\":" + contact + ",\"Record\":" + record + "}"); String sql = "select ID from user where UserName=@u;"; MySqlParameter[] pms = { new MySqlParameter("@u", UserName) }; MySqlHelper helper = new MySqlHelper(); MySqlDataReader reader = helper.getMySqlReader(sql, pms); if (reader.HasRows) { reader.Read(); int id = reader.GetInt32(0); sql = "select * from contact where User_ID=@id;"; MySqlHelper helper1 = new MySqlHelper(); MySqlDataReader reader1 = helper1.getMySqlReader(sql, new MySqlParameter("@id", id)); MySqlHelper helper2 = new MySqlHelper(); if (reader1.HasRows) { while (reader1.Read()) { int a1 = helper2.getMySqlCom("delete from contact_info where Contact_ID=@id", new MySqlParameter("@id", reader1.GetInt32(0) + "")); } } helper2 = new MySqlHelper(); int a = helper2.getMySqlCom("delete from contact where User_ID=@id", new MySqlParameter("@id", id + "")); string ss = "insert into record (Number,Duration,Date,User_ID,Type) values "; if (rb.Record != null) { for (int i = 0; i < rb.Record.Count; i++) { if (i == 0) { ss += "(\"" + rb.Record[i].Number + "\",\"" + rb.Record[i].Duration + "\",\"" + rb.Record[i].Date + "\"," + id + ",\"" + rb.Record[i].Type + "\")"; } else { ss += ",(\"" + rb.Record[i].Number + "\",\"" + rb.Record[i].Duration + "\",\"" + rb.Record[i].Date + "\"," + id + ",\"" + rb.Record[i].Type + "\")"; } } if (rb.Record.Count != 0) { helper2.getMySqlCom(ss); } } ss = "insert into contact (ID,User_ID,Name) values "; sql = "insert into contact_info (EmailOrNumber,Number,Type,Contact_ID) values "; if (rb.Contact != null) { for (int i = 0; i < rb.Contact.Count; i++) { if (i == 0) { ss += "(" + (int)(id * 10000 + i) + "," + id + ",\"" + rb.Contact[i].Name + "\")"; } else { ss += ",(" + (int)(id * 10000 + i) + "," + id + ",\"" + rb.Contact[i].Name + "\")"; } if (rb.Contact[i].ContactInfos != null) { for (int j = 0; j < rb.Contact[i].ContactInfos.Count; j++) { if (sql.Length == 71) { sql += "(" + rb.Contact[i].ContactInfos[j].EmailOrNumber + ",\"" + rb.Contact[i].ContactInfos[j].Number + "\",\"" + rb.Contact[i].ContactInfos[j].Type + "\"," + (int)(id * 10000 + i) + ")"; } else { sql += ",(" + rb.Contact[i].ContactInfos[j].EmailOrNumber + ",\"" + rb.Contact[i].ContactInfos[j].Number + "\",\"" + rb.Contact[i].ContactInfos[j].Type + "\"," + (int)(id * 10000 + i) + ")"; } } } } if (rb.Contact.Count != 0 && helper2.getMySqlCom(ss) < 0) { context.Response.Write("Error"); return; } if (rb.Contact.Count != 0) { if (sql.Length > 71 && helper2.getMySqlCom(sql) < 0) { context.Response.Write("Error"); return; } } } context.Response.Write("OK"); reader.Close(); helper.mysqlcom.Dispose(); helper.mysqlcon.Close(); helper.mysqlcon.Dispose(); reader1.Close(); helper1.mysqlcom.Dispose(); helper1.mysqlcon.Close(); helper1.mysqlcon.Dispose(); } else { context.Response.Write("Error"); } if (!reader.IsClosed) { reader.Close(); helper.mysqlcom.Dispose(); helper.mysqlcon.Close(); helper.mysqlcon.Dispose(); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; String UserName = context.Request["UserName"]; String contact = context.Request["Contact"]; String record = context.Request["Record"]; String res = ""; RootObject rb_local = JsonConvert.DeserializeObject <RootObject>("{\"Contact\":" + contact + ",\"Record\":" + record + "}"); rb_local = Check(rb_local); String sql = "select * from user where UserName=@u ORDER BY ID;"; MySqlParameter[] pms = { new MySqlParameter("@u", UserName) }; MySqlHelper helper = new MySqlHelper(); MySqlDataReader reader = helper.getMySqlReader(sql, pms); RootObject rb_cloud = new RootObject(); rb_cloud.Contact = new List <Contact>(); rb_cloud.Record = new List <Record>(); if (reader.HasRows) { reader.Read(); int id = reader.GetInt32(0); String u = reader.GetString(1), p = reader.GetString(2), s = reader.GetString(3), l = reader.GetString(4), r = reader.GetString(5); reader.Dispose(); helper.mysqlcom.Dispose(); helper.mysqlcon.Close(); helper.mysqlcon.Dispose(); res = "{\"ID\":" + id + ",\"UserName\":\"" + u + "\",\"Password\":\"" + p + "\",\"Sex\":\"" + s + "\",\"Location\":\"" + l + "\",\"Remark\":\"" + r + "\",\"Contact\":["; sql = "select * from contact where User_ID=@id ORDER BY ID;"; MySqlHelper helper1 = new MySqlHelper(); MySqlDataReader reader1 = helper1.getMySqlReader(sql, new MySqlParameter("@id", id)); while (reader1.Read()) { Contact con = new Contact(); con.ContactInfos = new List <ContactInfos>(); con.ID = reader1.GetInt32(0) + ""; con.Name = reader1.GetString(2); con.Birthday = Convert.IsDBNull(reader1[3])?"":reader1.GetString(3); MySqlHelper helper12 = new MySqlHelper(); MySqlDataReader reader12 = helper12.getMySqlReader("select * from contact_info where Contact_ID=" + reader1.GetInt32(0) + " ORDER BY ID"); List <ContactInfos> contactInfos = new List <ContactInfos>(); while (reader12.Read()) { ContactInfos ci = new ContactInfos(); ci.EmailOrNumber = reader12.GetInt32(0) + ""; ci.ID = reader12.GetInt32(1) + ""; ci.Number = reader12.GetString(2); ci.Type = reader12.GetString(3); contactInfos.Add(ci); } con.ContactInfos = contactInfos; rb_cloud.Contact.Add(con); reader12.Dispose(); helper12.mysqlcom.Dispose(); helper12.mysqlcon.Close(); helper12.mysqlcon.Dispose(); } reader1.Dispose(); helper1.mysqlcom.Dispose(); helper1.mysqlcon.Close(); helper1.mysqlcon.Dispose(); rb_cloud = Check(rb_cloud); sql = "select * from record where User_ID=@id ORDER BY ID;"; MySqlHelper helper2 = new MySqlHelper(); MySqlDataReader reader2 = helper2.getMySqlReader(sql, new MySqlParameter("@id", id)); while (reader2.Read()) { Record rec = new Record(); rec.ID = reader2.GetInt32(0) + ""; rec.Number = reader2.GetString(1); rec.Duration = reader2.GetString(2); rec.Date = reader2.GetString(3); rec.Type = reader2.GetString(5); rb_cloud.Record.Add(rec); } reader2.Dispose(); helper2.mysqlcom.Dispose(); helper2.mysqlcon.Close(); helper2.mysqlcon.Dispose(); Contact a, b; ContactInfos c, d; if (rb_cloud.Contact.Count > 0) { for (int i = 0; i < rb_cloud.Contact.Count; i++) { bool flag = false; for (int j = 0; j < rb_local.Contact.Count; j++) { a = rb_local.Contact[j]; b = rb_cloud.Contact[i]; if (a.ContactInfos == null) { a.ContactInfos = new List <ContactInfos>(); } if (a.Name.Equals(b.Name) && a.ContactInfos.Count == b.ContactInfos.Count) { if (a.ContactInfos.Count == 0) { rb_local.Contact.RemoveAt(j); flag = true; j--; } else { for (int k = 0; k < a.ContactInfos.Count; k++) { c = a.ContactInfos[k]; d = b.ContactInfos[k]; if (!c.EmailOrNumber.Equals(d.EmailOrNumber) || !c.Number.Equals(d.Number ) || !c.Type.Equals(d.Type)) { k = a.ContactInfos.Count; } else if (k == a.ContactInfos.Count - 1) { rb_local.Contact.RemoveAt(j); flag = true; j--; } } } } } if (flag == true) { if (rb_cloud.Contact.Count > i) { for (int k = i + 1; k < rb_cloud.Contact.Count; k++) { a = rb_cloud.Contact[k]; b = rb_cloud.Contact[i]; if (a.ContactInfos == null) { a.ContactInfos = new List <ContactInfos>(); } if (a.Name.Equals(b.Name) && a.ContactInfos.Count == b.ContactInfos.Count) { if (a.ContactInfos.Count == 0) { rb_cloud.Contact.RemoveAt(k); flag = true; k--; } for (int m = 0; m < a.ContactInfos.Count; m++) { for (int n = 0; m < b.ContactInfos.Count; n++) { c = a.ContactInfos[m]; d = b.ContactInfos[n]; if (c.EmailOrNumber.Equals(d.EmailOrNumber) && c.Number.Equals(d.Number ) && c.Type.Equals(d.Type) && m == a.ContactInfos.Count - 1) { rb_cloud.Contact.RemoveAt(k); flag = true; k--; } else if (c.EmailOrNumber.Equals(d.EmailOrNumber) && c.Number.Equals(d.Number) && c.Type.Equals(d.Type)) { } else { k = a.ContactInfos.Count; } } } } } } rb_cloud.Contact.RemoveAt(i); i--; } } } Record r1, r2; if (rb_cloud.Record.Count > 0) { for (int i = 0; i < rb_cloud.Record.Count; i++) { bool flag = false; for (int j = 0; j < rb_local.Record.Count; j++) { r1 = rb_local.Record[j]; r2 = rb_cloud.Record[i]; if (r1.Type.Equals(r2.Type) && r1.Number.Equals(r2.Number) && r1.ID.Equals(r2.ID) && r1.Duration.Equals(r2.Duration) && r1.Date.Equals(r2.Date)) { rb_local.Record.RemoveAt(j); j--; flag = true; } } if (flag) { rb_cloud.Record.RemoveAt(i); i--; } } } MySqlHelper helper3 = new MySqlHelper(); string ss = "insert into contact (ID,User_ID,Name) values "; sql = "insert into contact_info (EmailOrNumber,Number,Type,Contact_ID) values "; if (rb_local.Contact != null) { for (int i = 0; i < rb_local.Contact.Count; i++) { if (i == 0) { ss += "(" + (int)(id * 10000 + i) + "," + id + ",\"" + rb_local.Contact[i].Name + "\")"; } else { ss += ",(" + (int)(id * 10000 + i) + "," + id + ",\"" + rb_local.Contact[i].Name + "\")"; } if (rb_local.Contact[i].ContactInfos != null) { for (int j = 0; j < rb_local.Contact[i].ContactInfos.Count; j++) { if (sql.Length < 75) { sql += "(" + rb_local.Contact[i].ContactInfos[j].EmailOrNumber + ",\"" + rb_local.Contact[i].ContactInfos[j].Number + "\",\"" + rb_local.Contact[i].ContactInfos[j].Type + "\"," + (int)(id * 10000 + i) + ")"; } else { sql += ",(" + rb_local.Contact[i].ContactInfos[j].EmailOrNumber + ",\"" + rb_local.Contact[i].ContactInfos[j].Number + "\",\"" + rb_local.Contact[i].ContactInfos[j].Type + "\"," + (int)(id * 10000 + i) + ")"; } } } } if (rb_local.Contact.Count != 0) { helper3.getMySqlCom(ss); } if (rb_local.Contact.Count != 0) { helper3.getMySqlCom(sql); } } ss = "insert into record (Number,Duration,Date,User_ID,Type) values "; if (rb_local.Record != null) { for (int i = 0; i < rb_local.Record.Count; i++) { if (i == 0) { ss += "(\"" + rb_local.Record[i].Number + "\",\"" + rb_local.Record[i].Duration + "\",\"" + rb_local.Record[i].Date + "\"," + id + ",\"" + rb_local.Record[i].Type + "\")"; } else { ss += ",(\"" + rb_local.Record[i].Number + "\",\"" + rb_local.Record[i].Duration + "\",\"" + rb_local.Record[i].Date + "\"," + id + ",\"" + rb_local.Record[i].Type + "\")"; } } if (rb_local.Record.Count != 0) { helper3.getMySqlCom(ss); } } rb_local.Record.AddRange(rb_cloud.Record); rb_local.Contact.AddRange(rb_cloud.Contact); if (rb_local.Contact != null) { for (int i = 0; i < rb_local.Contact.Count; i++) { if (i == 0) { res += "{\"ID\":" + (int)(id * 10000 + i) + ",\"Name\":\"" + rb_local.Contact[i].Name + "\",\"Birthday\":\"" + rb_local.Contact[i].Birthday + "\",\"ContactInfos\":["; } else { res += ",{\"ID\":" + (int)(id * 10000 + i) + ",\"Name\":\"" + rb_local.Contact[i].Name + "\",\"Birthday\":\"" + rb_local.Contact[i].Birthday + "\",\"ContactInfos\":["; } if (rb_local.Contact[i].ContactInfos != null) { for (int j = 0; j < rb_local.Contact[i].ContactInfos.Count; j++) { if (j == 0) { res += "{\"ID\":" + 0 + ",\"EmailOrNumber\":" + rb_local.Contact[i].ContactInfos[j].EmailOrNumber + ",\"Number\":\"" + rb_local.Contact[i].ContactInfos[j].Number + "\",\"Type\":\"" + rb_local.Contact[i].ContactInfos[j].Type + "\"}"; } else { res += ",{\"ID\":" + 0 + ",\"EmailOrNumber\":" + rb_local.Contact[i].ContactInfos[j].EmailOrNumber + ",\"Number\":\"" + rb_local.Contact[i].ContactInfos[j].Number + "\",\"Type\":\"" + rb_local.Contact[i].ContactInfos[j].Type + "\"}"; } } } res += "]}"; } } res += "],\"Record\":["; if (rb_local.Record != null) { for (int i = 0; i < rb_local.Record.Count; i++) { if (i == 0) { res += "{\"ID\":0,\"Number\":\"" + rb_local.Record[i].Number + "\",\"Duration\":\"" + rb_local.Record[i].Duration + "\",\"Date\":\"" + rb_local.Record[i].Date + "\",\"Type\":\"" + rb_local.Record[i].Type + "\"}"; } else { res += ",{\"ID\":0,\"Number\":\"" + rb_local.Record[i].Number + "\",\"Duration\":\"" + rb_local.Record[i].Duration + "\",\"Date\":\"" + rb_local.Record[i].Date + "\",\"Type\":\"" + rb_local.Record[i].Type + "\"}"; } } } res += "]}"; context.Response.Write(res); reader.Close(); helper.mysqlcom.Dispose(); helper.mysqlcon.Close(); helper.mysqlcon.Dispose(); reader1.Close(); helper1.mysqlcom.Dispose(); helper1.mysqlcon.Close(); helper1.mysqlcon.Dispose(); } else { context.Response.Write("Error"); } if (!reader.IsClosed) { reader.Close(); helper.mysqlcom.Dispose(); helper.mysqlcon.Close(); helper.mysqlcon.Dispose(); } }