Ejemplo n.º 1
0
        private string combine(int id)
        {
            try
            {
                var ip = Pdt.FindByid(id).ip.Trim();
                var p  = new cprinter {
                    ip = ip, id = id
                };
                var mod = SNMPget(ip, new string[] { "1.3.6.1.2.1.1.1.0" })[0];
                if (mod == null)
                {
                    return("");
                }
                else if (mod.Contains("Samsung"))
                {
                    p.Model = model.Samsung;
                }
                else if (mod.Contains("KYOCERA"))
                {
                    p.Model = model.Kyocera;
                }
                else if (mod.Contains("HP"))
                {
                    p.Model = model.HP;
                }

                if (p.Model == model.Kyocera)
                {
                    var result = SNMPget(ip, new string[] { "1.3.6.1.2.1.25.3.2.1.3.1",
                                                            "1.3.6.1.4.1.1347.43.10.1.1.12.1.1",
                                                            "1.3.6.1.2.1.25.3.5.1.2.1" });
                    p.name  = "Kyocera " + result[0];
                    p.count = result[1];


                    if (Edt.Rows.Contains(Convert.ToInt32(result[2])))
                    {
                        p.error = Edt.FindById(Convert.ToInt32(result[2])).Error;
                    }
                    else
                    {
                        Invoke((MethodInvoker) delegate
                        {
                            AddError AddError = new AddError(Convert.ToInt32(result[2]), Pdt.FindByid(p.id).coment);
                            AddError.Show();
                        });
                        while (!Edt.Rows.Contains(Convert.ToInt32(result[2])))
                        {
                            Thread.Sleep(1000);
                        }
                        p.error = Edt.FindById(Convert.ToInt32(result[2])).Error;
                    }
                }
                else if (p.Model == model.HP)
                {
                    var result = SNMPget(ip, new string[] { "1.3.6.1.2.1.25.3.2.1.3.1",
                                                            "1.3.6.1.4.1.11.2.3.9.4.2.1.4.1.2.5.0",
                                                            "1.3.6.1.2.1.25.3.5.1.2.1" });
                    p.name  = result[0];
                    p.count = result[1];
                    if (Edt.Rows.Contains(Convert.ToInt32(result[2])))
                    {
                        p.error = Edt.FindById(Convert.ToInt32(result[2])).Error;
                    }
                    else
                    {
                        Invoke((MethodInvoker) delegate
                        {
                            AddError AddError = new AddError(Convert.ToInt32(result[2]), Pdt.FindByid(p.id).coment);
                            AddError.Show();
                        });
                        while (!Edt.Rows.Contains(Convert.ToInt32(result[2])))
                        {
                            Thread.Sleep(1000);
                        }
                        p.error = Edt.FindById(Convert.ToInt32(result[2])).Error;
                    }
                }
                else if (p.Model == model.Samsung)
                {
                    var result = SNMPget(ip, new string[] { "1.3.6.1.2.1.25.3.2.1.3.1",
                                                            "1.3.6.1.2.1.25.3.5.1.2.1" });
                    p.name  = result[0];
                    p.count = "0";
                    if (Edt.Rows.Contains(Convert.ToInt32(result[1])))
                    {
                        p.error = Edt.FindById(Convert.ToInt32(result[1])).Error;
                    }
                    else
                    {
                        Invoke((MethodInvoker) delegate
                        {
                            AddError AddError = new AddError(Convert.ToInt32(result[1]), Pdt.FindByid(p.id).coment);
                            AddError.Show();
                        });
                        while (!Edt.Rows.Contains(Convert.ToInt32(result[1])))
                        {
                            Thread.Sleep(1000);
                        }
                        p.error = Edt.FindById(Convert.ToInt32(result[1])).Error;
                    }
                }
                if (p.name != null && p.count != null && p.name != "" && p.count != "")
                {
                    var good = false;
                    if (p.error != "no error")
                    {
                        good = true;
                        foreach (printersDataSet.CurrentErorrsRow item in CEdt.Rows)
                        {
                            if (item.printer_id == p.id)
                            {
                                good = false;
                                break;
                            }
                        }
                        if (good)
                        {
                            ELadapter.Insert(p.id, DateTime.Now, Convert.ToInt32(p.count), p.error, 0);
                            CEadapter.Insert(p.id, p.error);
                            CEdt.AddCurrentErorrsRow(p.id, p.error);
                        }
                    }
                    else
                    {
                        good = true;
                        foreach (printersDataSet.CurrentErorrsRow item in CEdt.Rows)
                        {
                            if (item.printer_id == p.id)
                            {
                                good = false;
                                break;
                            }
                        }
                        if (!good)
                        {
                            Invoke((MethodInvoker) delegate
                            {
                                good = true;
                                foreach (msng item in msngcentr.Controls)
                                {
                                    if (item.print.id == p.id)
                                    {
                                        good = false;
                                        break;
                                    }
                                }
                                if (good)
                                {
                                    msngcentr.Add(p, Pdt.FindByid(p.id).coment, CEdt.FindByprinter_id(p.id).Error);
                                }
                            });
                        }
                    }
                    return(p.ip + " " + p.name + " " + p.count + " " + p.error + "\n");
                }
            }
            catch (Exception e)
            {
                //throw;
            }
            return("");
        }
Ejemplo n.º 2
0
        private string combine(int id)
        {
            try
            {
                var ip = Pdt.FindByid(id).ip.Trim();
                var p  = new cprinter {
                    ip = ip, id = id
                };
                var mod = SNMPget(ip, new string[] { "1.3.6.1.2.1.1.1.0" })[0];
                if (mod == null)
                {
                    return("");
                }
                else if (mod.Contains("Samsung"))
                {
                    p.Model = model.Samsung;
                }
                else if (mod.Contains("KYOCERA"))
                {
                    p.Model = model.Kyocera;
                }
                else if (mod.Contains("HP"))
                {
                    p.Model = model.HP;
                }

                if (p.Model == model.Kyocera)
                {
                    var result = SNMPget(ip, new string[] { "1.3.6.1.2.1.25.3.2.1.3.1",
                                                            "1.3.6.1.4.1.1347.43.10.1.1.12.1.1",
                                                            "1.3.6.1.2.1.25.3.5.1.2.1" });
                    p.name  = "Kyocera " + result[0];
                    p.count = result[1];
                    p.error = ErrorMessageText[(int)result[2][0]];
                }
                else if (p.Model == model.HP)
                {
                    var result = SNMPget(ip, new string[] { "1.3.6.1.2.1.25.3.2.1.3.1",
                                                            "1.3.6.1.4.1.11.2.3.9.4.2.1.4.1.2.5.0",
                                                            "1.3.6.1.2.1.25.3.5.1.2.1" });
                    p.name  = result[0];
                    p.count = result[1];
                    p.error = ErrorMessageText[Convert.ToInt32(result[2])];
                }
                else if (p.Model == model.Samsung)
                {
                    var result = SNMPget(ip, new string[] { "1.3.6.1.2.1.25.3.2.1.3.1",
                                                            "1.3.6.1.2.1.25.3.5.1.2.1" });
                    p.name  = result[0];
                    p.count = "\"Can't extract the number of sheets\"";
                    p.error = ErrorMessageText[Convert.ToInt32(result[1])];
                }
                if (p.name != null && p.count != null && p.name != "" && p.count != "")
                {
                    var good = false;
                    foreach (printersDataSet.PrintersRow item in Pdt.Rows)
                    {
                        if (item.ip.Trim() == p.ip)
                        {
                            good = true;
                            break;
                        }
                    }

                    /* УБрали автоматическое добавление принтеров в базу
                     *
                     * if (!good)
                     * {
                     *  IPdt.AddPrintersRow(IPid, p.ip, p.name);
                     *  IPadapter.Insert(IPid++, p.ip, p.name);
                     * }*/

                    if (p.error != "no error" && p.error != null)
                    {
                        good = true;
                        foreach (printersDataSet.CurrentErorrsRow item in CEdt.Rows)
                        {
                            if (item.printer_id == p.id)
                            {
                                good = false;
                                break;
                            }
                        }
                        if (good)
                        {
                            ELadapter.Insert(p.id, DateTime.Now, Convert.ToInt32(p.count), p.error ?? "");
                            CEadapter.Insert(p.id, p.error ?? "");
                            CEdt.AddCurrentErorrsRow(p.id, p.error ?? "");
                        }
                    }
                    else
                    {
                        good = true;
                        foreach (printersDataSet.CurrentErorrsRow item in CEdt.Rows)
                        {
                            if (item.printer_id == p.id)
                            {
                                good = false;

                                var result = SNMPget(ip, new string[] { "1.3.6.1.2.1.25.3.5.1.2.1" })[0];

                                if (item.Error == "no tonner" && (p.error = SNMPget(ip, new string[] { "1.3.6.1.2.1.25.3.5.1.2.1" })[0]) == "0")
                                {
                                    Thread.Sleep(10000);
                                    if (item.Error == "no tonner" && (p.error = SNMPget(ip, new string[] { "1.3.6.1.2.1.25.3.5.1.2.1" })[0]) == "0")
                                    {
                                        var i_am_here = true;
                                    }
                                }
                                break;
                            }
                        }
                        if (!good)
                        {
                            CEadapter.Delete(p.id);
                            CEdt = CEadapter.GetData();
                            ELadapter.Insert(p.id, DateTime.Now, Convert.ToInt32(p.count), ErrorMessageText[Convert.ToInt32(p.error)]);
                        }
                    }
                    return(p.ip + " " + p.name + " " + p.count + " " + p.error + "\n");
                }
            }
            catch (Exception)
            {
                //throw;
            }
            return("");
        }