Exemplo n.º 1
0
        public string Update(string dataString)
        {
            string id = "", sql = "", valueString = "", leaderId = "-1";
            string result = "-1";

            SQLServerHelper runner = new SQLServerHelper();

            try
            {
                dataString = dataString.Replace("UpdateDepartment>", "UpdateItem>");

                XmlDocument doc = new XmlDocument();
                XmlNode     vNode;
                doc.LoadXml(dataString);
                //更新消息信息
                vNode = doc.SelectSingleNode("UpdateItem/FSupervisorID");
                string val = "";
                if (vNode != null)
                {
                    val = vNode.InnerText.Trim();
                    if (val.Length > 0 || val != "-1")
                    {
                        valueString = valueString + "FSupervisorID='" + val + "',";
                        leaderId    = val;
                    }
                }

                id = iClass.Update(dataString);
                if (id == "-1")//插入t_items表错误
                {
                    result = "-1";
                }
                if (doc.SelectSingleNode("UpdateItem/ID").InnerText.Trim() == "" || doc.SelectSingleNode("UpdateItem/ID").InnerText.Trim() == "-1")//新增
                {
                    sql = "Insert into t_Departments(FID) Values('" + id + "')";
                    if (runner.ExecuteSqlNone(sql) < 0)//插入新日程失败
                    {
                        throw new Exception("新建失败");
                    }
                }
                vNode = doc.SelectSingleNode("UpdateItem/FIntroduce");
                if (vNode != null)
                {
                    val = vNode.InnerText;
                    if (val.Trim().Length > 0)
                    {
                        valueString = valueString + "FIntroduce='" + val + "',";
                    }
                }

                vNode = doc.SelectSingleNode("UpdateItem/FIsPartTime");
                if (vNode != null)
                {
                    val = vNode.InnerText;
                    if (val.Trim().Length > 0)
                    {
                        valueString = valueString + "FIsPartTime='" + val + "',";
                    }
                }

                vNode = doc.SelectSingleNode("UpdateItem/FSortIndex");
                if (vNode != null)
                {
                    val = vNode.InnerText;
                    if (val.Trim().Length > 0)
                    {
                        valueString = valueString + "FSortIndex='" + val + "',";
                    }
                }

                if (valueString.Trim().Length > 0)
                {
                    valueString = valueString.Substring(0, valueString.Length - 1);
                    sql         = "Update t_Departments Set " + valueString + " Where FID='" + id + "'";
                    if (runner.ExecuteSqlNone(sql) < 0)//更新消息失败
                    {
                        id = "-1";
                        throw new Exception("更新失败");
                    }
                }
                if (leaderId != "-1")//主管更新,维护t_Workships表
                {
                    WorkShip ws = new WorkShip();
                    ws.Update(leaderId, id);
                }
            }
            catch (Exception err)
            {
                if (id != "-1")//t_tems已插入数据成功,要删除
                {
                    sql = "Delete from t_Items Where FID='" + id + "'  Delete from t_Departments Where FID='" + id + "'";
                    runner.ExecuteSqlNone(sql);
                }
                throw err;
            }
            result = id;

            return(result);
        }
Exemplo n.º 2
0
        public string Update(string dataString)
        {
            string id = "", sql = "", valueString = "", dptId = "";
            string result = "-1";

            SQLServerHelper runner = new SQLServerHelper();

            try
            {
                dataString = dataString.Replace("UpdateEmployee>", "UpdateItem>");

                XmlDocument doc = new XmlDocument();
                XmlNode     vNode;
                doc.LoadXml(dataString);
                //更新消息信息
                vNode = doc.SelectSingleNode("UpdateItem/FDeptID");
                string val = "";
                if (vNode == null || vNode.InnerXml.Trim().Length == 0)
                {
                    throw new Exception("所在部门ID不能为空");
                }
                else
                {
                    val   = vNode.InnerText;
                    dptId = val;
                    if (val.Trim().Length > 0)
                    {
                        valueString = valueString + "FDeptID='" + val + "',";
                    }
                }
                vNode = doc.SelectSingleNode("UpdateItem/FPositionID");
                if (vNode == null || vNode.InnerXml.Trim().Length == 0)
                {
                    throw new Exception("职位ID不能为空");
                }
                else
                {
                    val = vNode.InnerText;
                    if (val.Trim().Length > 0)
                    {
                        valueString = valueString + "FPositionID='" + val + "',";
                    }
                }

                vNode = doc.SelectSingleNode("UpdateItem/FLoginName");
                if (vNode == null || vNode.InnerXml.Trim().Length == 0)
                {
                    throw new Exception("登录名不能为空");
                }
                else
                {
                    val = vNode.InnerText;
                    if (val.Trim().Length > 0)
                    {
                        valueString = valueString + "FLoginName='" + val + "',";
                    }
                }
                vNode = doc.SelectSingleNode("UpdateItem/FLoginPwd");
                if (vNode == null || vNode.InnerXml.Trim().Length == 0)
                {
                    throw new Exception("登录密码不能为空");
                }
                else
                {
                    val = vNode.InnerText;
                    if (val.Trim().Length > 0)
                    {
                        valueString = valueString + "FLoginPwd='" + val + "',";
                    }
                }

                id = iClass.Update(dataString);
                if (id == "-1")//插入t_items表错误
                {
                    result = "-1";
                }
                if (doc.SelectSingleNode("UpdateItem/ID").InnerText.Trim() == "" || doc.SelectSingleNode("UpdateItem/ID").InnerText.Trim() == "-1")//新增
                {
                    sql = "Insert into t_Employees(FID) Values('" + id + "')";
                    if (runner.ExecuteSqlNone(sql) < 0)//插入新日程失败
                    {
                        throw new Exception("新建失败");
                    }
                }
                vNode = doc.SelectSingleNode("UpdateItem/FIntroduce");
                if (vNode != null)
                {
                    val = vNode.InnerText;
                    if (val.Trim().Length > 0)
                    {
                        valueString = valueString + "FIntroduce='" + val + "',";
                    }
                }
                vNode = doc.SelectSingleNode("UpdateItem/FMobile");
                if (vNode != null)
                {
                    val = vNode.InnerText;
                    if (val.Trim().Length > 0)
                    {
                        valueString = valueString + "FMobile='" + val + "',";
                    }
                }

                vNode = doc.SelectSingleNode("UpdateItem/FMail");
                if (vNode != null)
                {
                    val = vNode.InnerText;
                    if (val.Trim().Length > 0)
                    {
                        valueString = valueString + "FMail='" + val + "',";
                    }
                }
                vNode = doc.SelectSingleNode("UpdateItem/FRoleID");
                if (vNode != null)
                {
                    val = vNode.InnerText;
                    if (val.Trim().Length > 0)
                    {
                        valueString = valueString + "FRoleID='" + val + "',";
                    }
                }

                vNode = doc.SelectSingleNode("UpdateItem/FPageID");
                if (vNode != null)
                {
                    val = vNode.InnerText;
                    if (val.Trim().Length > 0)
                    {
                        valueString = valueString + "FPageID='" + val + "',";
                    }
                }
                vNode = doc.SelectSingleNode("UpdateItem/FRemark");
                if (vNode != null)
                {
                    val = vNode.InnerText;
                    if (val.Trim().Length > 0)
                    {
                        valueString = valueString + "FRemark='" + val + "',";
                    }
                }
                vNode = doc.SelectSingleNode("UpdateItem/FWechat");
                if (vNode != null)
                {
                    val = vNode.InnerText;
                    if (val.Trim().Length > 0)
                    {
                        valueString = valueString + "FWechat='" + val + "',";
                    }
                }
                vNode = doc.SelectSingleNode("UpdateItem/FTypeID");
                if (vNode != null)
                {
                    val = vNode.InnerText;
                    if (val.Trim().Length > 0)
                    {
                        valueString = valueString + "FTypeID='" + val + "',";
                    }
                }
                vNode = doc.SelectSingleNode("UpdateItem/FIsAgency");
                if (vNode != null)
                {
                    val = vNode.InnerText;
                    if (val.Trim().Length > 0)
                    {
                        valueString = valueString + "FIsAgency='" + val + "',";
                    }
                }
                vNode = doc.SelectSingleNode("UpdateItem/FSortIndex");
                if (vNode != null)
                {
                    val = vNode.InnerText;
                    if (val.Trim().Length > 0)
                    {
                        valueString = valueString + "FSortIndex='" + val + "',";
                    }
                }

                if (valueString.Trim().Length > 0)
                {
                    valueString = valueString.Substring(0, valueString.Length - 1);
                    sql         = "Update t_Employees Set " + valueString + " Where FID='" + id + "'";
                    if (runner.ExecuteSqlNone(sql) < 0)//更新消息失败
                    {
                        id = "-1";
                        throw new Exception("更新失败");
                    }
                }

                if (dptId != "-1")
                {
                    WorkShip ws = new WorkShip();
                    ws.Update(dptId);
                }
            }
            catch (Exception err)
            {
                if (id != "-1")//t_tems已插入数据成功,要删除
                {
                    sql = "Delete from t_Items Where FID='" + id + "'  Delete from t_Employees Where FID='" + id + "'";
                    runner.ExecuteSqlNone(sql);
                }
                throw err;
            }
            result = id;

            return(result);
        }