l.增
try { crmDataContext myc = new crmDataContext(); con.Beizhu = remark; if (pathName != "") { //保存图片 System.IO.FileStream fs = new System.IO.FileStream(pathName, System.IO.FileMode.Open, System.IO.FileAccess.Read); byte[] bufferByte = new byte[fs.Length]; fs.Read(bufferByte, 0, (int)fs.Length); fs.Close(); fs = null; con.MyPic = bufferByte; }
myc.Contact.InsertOnSubmit(con); myc.SubmitChanges(); MessageBox.Show("保存成功"); this.Close(); //重新绑定GridvIEW tls.bdLinker(); }
catch()
{
}
2.改
crmDataContext myc2 = new crmDataContext();
var vContect = from p in myc2.Contact where p.cid == Convert.ToInt32(_id) select new { p };
Contact con2 = myc2.Contact.Where(p => p.cid.ToString() == _id).First(); con2.Name = name; con2.FirstChar = getSpells(name); con2.QQ = qq; con2.Web = website; con2.Shengshi = shengshi; con2.Shixian = shixian; con2.Jiedao = street; con2.Beizhu = remark; if (pathName != "") { //保存图片 System.IO.FileStream fs = new System.IO.FileStream(pathName, System.IO.FileMode.Open, System.IO.FileAccess.Read); byte[] bufferByte = new byte[fs.Length]; fs.Read(bufferByte, 0, (int)fs.Length); fs.Close(); fs = null; con2.MyPic = bufferByte; }
myc2.SubmitChanges(); MessageBox.Show("修改成功!");
3.删
if (_callID != "") { try { crmDataContext mcc = new crmDataContext(); var vContect = from p in mcc.call where p.id == Convert.ToInt32(_callID) select new { p };
call cl = mcc.call.FirstOrDefault(a => a.id.ToString() == _callID); mcc.call.DeleteOnSubmit(cl); mcc.SubmitChanges(); MessageBox.Show("删除成功!"); bddgvTHJL(); } catch { MessageBox.Show("删除失败!"); } }
4.查
crmDataContext cdcL = new crmDataContext(); var aa = from p in cdcL.lines where p.Line==Convert.ToInt32(_line) select p; this.lblTD.Text= aa.FirstOrDefault().Line.Value.ToString(); tbTDName.Text = aa.FirstOrDefault().Phone;