Ejemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //在列表里点击删除按钮,通过AJAX执行这里的后台代码,删除一条记录
        if (Request["DelUSERID"] != null)
        {
            int re = BLLTable <HR_CK_USERINFO> .Factory(conn).Delete(HR_CK_USERINFO.Attribute.USERID, Request["DelUSERID"]);

            if (re > 0)
            {
                Response.Write("1");//可以输出数字 大于0 表示操作成功,也可以直接输出 字符串,客户端将弹出此字符串信息作为提示
            }
            else
            {
                Response.Write("删除失败!");
            }
        }

        //在列表顶部点击删除按钮,通过AJAX执行这里的后台代码,删除多条记录
        if (Request["DelKeyIDS"] != null)
        {
            HR_CK_USERINFO cond = new HR_CK_USERINFO();
            cond.In(HR_CK_USERINFO.Attribute.USERID, Request["DelKeyIDS"]);
            int re = BLLTable <HR_CK_USERINFO> .Factory(conn).Delete(cond);

            if (re > 0)
            {
                Response.Write("1");//可以输出数字 大于0 表示操作成功,也可以直接输出 字符串,客户端将弹出此字符串信息作为提示
            }
            else
            {
                Response.Write("删除失败!");
            }
        }

        //在用户详细信息查看编辑页面,点保存时,通过AJAX执行这里的后台代码,实现部门字段的更新
        if (Request["saveInfo"] != null)
        {
            HR_CK_USERINFO val = new HR_CK_USERINFO();
            val.USERID = int.Parse(Request["FieldKeyID"]);
            List <AttributeItem> lstCol = val.af_AttributeItemList;
            for (int i = 0; i < lstCol.Count; i++)
            {
                if (!string.IsNullOrEmpty(Request["txt" + lstCol[i].FieldName]))
                {
                    val.SetValue(lstCol[i].FieldName, Request["txt" + lstCol[i].FieldName]);
                }
            }

            BLLTable <HR_CK_USERINFO> .Factory(conn).Update(val, HR_CK_USERINFO.Attribute.USERID);

            Response.Write("修改用户信息成功");
        }
        Response.End();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        //���б�����ɾ����ť��ͨ��AJAXִ������ĺ�̨���룬ɾ��һ����¼
        if (Request["DelUSERID"] != null)
        {
            int re = BLLTable<HR_CK_USERINFO>.Factory(conn).Delete(HR_CK_USERINFO.Attribute.USERID, Request["DelUSERID"]);
            if (re > 0)
            {
                Response.Write("1");//����������� ����0 ��ʾ�����ɹ���Ҳ����ֱ����� �ַ������ͻ��˽��������ַ�����Ϣ��Ϊ��ʾ
            }
            else
            {
                Response.Write("ɾ��ʧ�ܣ�");
            }
        }

        //���б�������ɾ����ť��ͨ��AJAXִ������ĺ�̨���룬ɾ��������¼
        if (Request["DelKeyIDS"] != null)
        {
            HR_CK_USERINFO cond = new HR_CK_USERINFO();
            cond.In(HR_CK_USERINFO.Attribute.USERID, Request["DelKeyIDS"]);
            int re = BLLTable<HR_CK_USERINFO>.Factory(conn).Delete(cond);
            if (re > 0)
            {
                Response.Write("1");//����������� ����0 ��ʾ�����ɹ���Ҳ����ֱ����� �ַ������ͻ��˽��������ַ�����Ϣ��Ϊ��ʾ
            }
            else
            {
                Response.Write("ɾ��ʧ�ܣ�");
            }
        }

        //���û���ϸ��Ϣ�鿴�༭ҳ�棬�㱣��ʱ��ͨ��AJAXִ������ĺ�̨���룬ʵ�ֲ����ֶεĸ���
        if (Request["saveInfo"] != null)
        {
            HR_CK_USERINFO val = new HR_CK_USERINFO();
            val.USERID = int.Parse(Request["FieldKeyID"]);
            List<AttributeItem> lstCol = val.af_AttributeItemList;
            for (int i = 0; i < lstCol.Count; i++)
            {
                if (!string.IsNullOrEmpty(Request["txt" + lstCol[i].FieldName])) {
                    val.SetValue(lstCol[i].FieldName,Request["txt" + lstCol[i].FieldName]);
                }
            }

            BLLTable<HR_CK_USERINFO>.Factory(conn).Update(val, HR_CK_USERINFO.Attribute.USERID);
            Response.Write("�޸��û���Ϣ�ɹ�");

        }
        Response.End();
    }
Ejemplo n.º 3
0
    private void UpdateStff(OleDbConnection conn2, string fangan)
    {
        if (conn2 == null)
        {
            return;
        }
        Dictionary <string, string> userFields = GetFieldsByFangAn(fangan, "USERINFO");

        if (!userFields.ContainsKey("*USERINFO"))
        {
            Response.Write("同步方案不完整,请修改方案!");
            Response.End();
            return;
        }
        string sql = "select ";

        foreach (string field in userFields.Keys)
        {
            if (field.Contains("*"))
            {
                continue;
            }
            sql += " " + userFields[field] + ",";
        }
        sql  = sql.TrimEnd(',');
        sql += " from " + userFields["*USERINFO"];
        OleDbCommand          com     = new OleDbCommand(sql, conn2);
        OleDbDataReader       dr      = com.ExecuteReader();
        HR_CK_USERINFO        hruser  = new HR_CK_USERINFO();
        List <HR_CK_USERINFO> hrusers = new List <HR_CK_USERINFO>();
        Dictionary <string, HR_CK_USERINFO> userDic = new Dictionary <string, HR_CK_USERINFO>();
        List <HR_CK_USERINFO> chongfuUser           = new List <HR_CK_USERINFO>();

        while (dr.Read())
        {
            try
            {
                hruser = new HR_CK_USERINFO();
                foreach (AttributeItem ai in hruser.af_AttributeItemList)
                {
                    if (userFields.ContainsKey("USERINFO_" + ai.FieldName))
                    {
                        object val = dr[userFields["USERINFO_" + ai.FieldName]];
                        if (val != null && !string.IsNullOrEmpty(val.ToString()))
                        {
                            hruser.SetValue(ai, val.ToString().Replace("?粀", "").Replace("\0", "").Replace("?", "").Replace("粀", ""));
                        }
                    }
                }
                hruser.Remove(new AttributeItem[] { HR_CK_USERINFO.Attribute.STAFF_ID });
                if (!userDic.ContainsKey(hruser.NAME))
                {
                    userDic.Add(hruser.NAME, hruser);
                }
                else
                {
                    chongfuUser.Add(hruser);
                }
                hrusers.Add(hruser);
            }
            catch { }
        }

        foreach (HR_CK_USERINFO user in chongfuUser)
        {
            if (userDic.ContainsKey(user.NAME))
            {
                userDic.Remove(hruser.NAME);
            }
        }

        HR_STAFF stfVal = new HR_STAFF();

        stfVal.STAFF_NAME = "";
        stfVal.STAFF_ID   = 0;
        HR_STAFF        stfCon  = new HR_STAFF();
        List <HR_STAFF> stfList = BLLTable <HR_STAFF> .Factory(conn).Select(stfVal, stfCon);

        Dictionary <string, HR_STAFF> stfDic = new Dictionary <string, HR_STAFF>();
        List <HR_STAFF> chongfuStf           = new List <HR_STAFF>();

        foreach (HR_STAFF stf in stfList)
        {
            if (!stfDic.ContainsKey(stf.STAFF_NAME))
            {
                stfDic.Add(stf.STAFF_NAME, stf);
            }
            else
            {
                chongfuStf.Add(stf);
            }
        }

        foreach (HR_STAFF stf in chongfuStf)
        {
            if (stfDic.ContainsKey(stf.STAFF_NAME))
            {
                stfDic.Remove(stf.STAFF_NAME);
            }
        }

        foreach (string name in userDic.Keys)
        {
            if (stfDic.ContainsKey(name))
            {
                HR_CK_USERINFO stfidcon = new HR_CK_USERINFO();//wcp考虑优化新能
                stfidcon.STAFF_ID = stfDic[name].STAFF_ID;
                if (!BLLTable <HR_CK_USERINFO> .Exists(stfidcon))
                {
                    userDic[name].STAFF_ID = stfDic[name].STAFF_ID;
                }
            }
        }

        int countok = 0;
        int countfi = 0;
        int counter = 0;

        foreach (HR_CK_USERINFO user in hrusers)
        {
            try
            {
                int count = 0;
                count = BLLTable <HR_CK_USERINFO> .SaveOrUpdate(user, HR_CK_USERINFO.Attribute.USERID);

                if (count > 0)
                {
                    countok++;
                }
                else
                {
                    countfi++;
                }
            }
            catch { counter++; }
        }

        Response.Write("同步员工信息数:" + hrusers.Count + "条" + "\n成功:" + countok + "条\n失败:" + countfi + "条\n出错:" + counter + "条");
    }
    private void UpdateStff(OleDbConnection conn2, string fangan)
    {
        if (conn2 == null)
            return;
        Dictionary<string, string> userFields = GetFieldsByFangAn(fangan, "USERINFO");
        if (!userFields.ContainsKey("*USERINFO"))
        {
            Response.Write("同步方案不完整,请修改方案!");
            Response.End();
            return;
        }
        string sql = "select ";
        foreach (string field in userFields.Keys)
        {
            if (field.Contains("*"))
                continue;
            sql += " " + userFields[field] + ",";
        }
        sql = sql.TrimEnd(',');
        sql += " from " + userFields["*USERINFO"];
        OleDbCommand com = new OleDbCommand(sql, conn2);
        OleDbDataReader dr = com.ExecuteReader();
        HR_CK_USERINFO hruser = new HR_CK_USERINFO();
        List<HR_CK_USERINFO> hrusers = new List<HR_CK_USERINFO>();
        Dictionary<string, HR_CK_USERINFO> userDic = new Dictionary<string, HR_CK_USERINFO>();
        List<HR_CK_USERINFO> chongfuUser = new List<HR_CK_USERINFO>();
        while (dr.Read())
        {
            try
            {
                hruser = new HR_CK_USERINFO();
                foreach (AttributeItem ai in hruser.af_AttributeItemList)
                {
                    if (userFields.ContainsKey("USERINFO_" + ai.FieldName))
                    {
                        object val = dr[userFields["USERINFO_" + ai.FieldName]];
                        if (val != null && !string.IsNullOrEmpty(val.ToString()))
                            hruser.SetValue(ai, val.ToString().Replace("?粀", "").Replace("\0", "").Replace("?", "").Replace("粀", ""));
                    }
                }
                hruser.Remove(new AttributeItem[] { HR_CK_USERINFO.Attribute.STAFF_ID });
                if (!userDic.ContainsKey(hruser.NAME))
                    userDic.Add(hruser.NAME, hruser);
                else
                    chongfuUser.Add(hruser);
                hrusers.Add(hruser);
            }
            catch { }
        }

        foreach (HR_CK_USERINFO user in chongfuUser)
        {
            if (userDic.ContainsKey(user.NAME))
                userDic.Remove(hruser.NAME);
        }

        HR_STAFF stfVal = new HR_STAFF();
        stfVal.STAFF_NAME = "";
        stfVal.STAFF_ID = 0;
        HR_STAFF stfCon = new HR_STAFF();
        List<HR_STAFF> stfList = BLLTable<HR_STAFF>.Factory(conn).Select(stfVal, stfCon);
        Dictionary<string, HR_STAFF> stfDic = new Dictionary<string, HR_STAFF>();
        List<HR_STAFF> chongfuStf = new List<HR_STAFF>();
        foreach (HR_STAFF stf in stfList)
        {
            if (!stfDic.ContainsKey(stf.STAFF_NAME))
                stfDic.Add(stf.STAFF_NAME, stf);
            else
                chongfuStf.Add(stf);
        }

        foreach (HR_STAFF stf in chongfuStf)
        {
            if (stfDic.ContainsKey(stf.STAFF_NAME))
                stfDic.Remove(stf.STAFF_NAME);
        }

        foreach (string name in userDic.Keys)
        {
            if (stfDic.ContainsKey(name))
            {
                HR_CK_USERINFO stfidcon = new HR_CK_USERINFO();//wcp考虑优化新能
                stfidcon.STAFF_ID = stfDic[name].STAFF_ID;
                if (!BLLTable<HR_CK_USERINFO>.Exists(stfidcon))
                    userDic[name].STAFF_ID = stfDic[name].STAFF_ID;
            }
        }

        int countok = 0;
        int countfi = 0;
        int counter = 0;
        foreach (HR_CK_USERINFO user in hrusers)
        {
            try
            {
                int count = 0;
                count = BLLTable<HR_CK_USERINFO>.SaveOrUpdate(user, HR_CK_USERINFO.Attribute.USERID);
                if (count > 0)
                    countok++;
                else
                    countfi++;
            }
            catch { counter++; }
        }

        Response.Write("同步员工信息数:" + hrusers.Count + "条" + "\n成功:" + countok + "条\n失败:" + countfi + "条\n出错:" + counter + "条");
    }