private void frmInventoryDoc_Load(object sender, EventArgs e) { if (id > -1) { inv = new Inventory(id); closed = true; DataTable t = new DataTable("i"); t.Columns.Add("no", Type.GetType("System.String")); t.Columns.Add("found", Type.GetType("System.Boolean")); t.Columns.Add("status_t", Type.GetType("System.String")); t.Columns.Add("status_fact_t", Type.GetType("System.String")); t.Columns.Add("in", Type.GetType("System.DateTime")); t.Columns.Add("out", Type.GetType("System.DateTime")); t.Columns.Add("action_t", Type.GetType("System.String")); t.Columns.Add("status", Type.GetType("System.String")); t.Columns.Add("status_fact", Type.GetType("System.String")); t.Columns.Add("show", Type.GetType("System.Boolean")); t.Columns.Add("action", Type.GetType("System.String")); t.Columns.Add("user", Type.GetType("System.Int32")); t.Columns.Add("exported", Type.GetType("System.Boolean")); for (int i = 0; i < inv.body.Count; i++) { if (inv.body[i].date_in.Year > 1901) { t.Rows.Add(new object[13] { inv.body[i].number, inv.body[i].found, inv.body[i].status_t, inv.body[i].status_fact_t, inv.body[i].date_in, inv.body[i].date_out, inv.body[i].action, inv.body[i].status, inv.body[i].status_fact, true, inv.body[i].action_t, inv.body[i].usr.Id_user, inv.body[i].exported } ); } else { t.Rows.Add(new object[13] { inv.body[i].number, inv.body[i].found, inv.body[i].status_t, inv.body[i].status_fact_t, null, null, inv.body[i].action, inv.body[i].status, inv.body[i].status_fact, true, inv.body[i].action_t, inv.body[i].usr.Id_user, inv.body[i].exported } ); } } orders = t; updateTable(); this.Title = "Документ инвентаризации № " + inv.id.ToString("D6"); } LoadStatus(); if (id > -1) btnApply_Click(this, new EventArgs()); CheckStatus(); }
public static List<Inventory> getList() { List<Inventory> lst = new List<Inventory>(); try { InventoryProvider pr = new InventoryProvider(); DataSet ds = pr.GetList(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { Inventory o = new Inventory(); o.id = int.Parse(ds.Tables[0].Rows[i]["id_inventory"].ToString()); o.del = bool.Parse(ds.Tables[0].Rows[i]["del"].ToString()); o.guid = ds.Tables[0].Rows[i]["guid"].ToString(); if (ds.Tables[0].Rows[i]["inventory_date"].ToString() != "") o.date = DateTime.Parse(ds.Tables[0].Rows[i]["inventory_date"].ToString()); o.usr = new Photoland.Security.User.UserInfo(); o.usr.Id_user = int.Parse(ds.Tables[0].Rows[i]["inventory_user"].ToString()); // не правильно, но старые объекты не стал переписывать :) пятница! UserProvider upr = new UserProvider(); o.usr.Name = upr.getNameById(o.usr.Id_user); lst.Add(o); } } catch (Exception ex) { } return lst; }
private void btnCloseInvent_Click(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(settings.Connection_string)) { con.Open(); SqlCommand cmd = con.CreateCommand(); SqlTransaction transaction = con.BeginTransaction("save"); cmd.Connection = con; cmd.Transaction = transaction; int i; try { lblSave.Visible = true; int inventory_id = 0; cmd.CommandText = "INSERT INTO [dbo].[inventory]" + "([inventory_date]" + ",[inventory_user]" + ",[exported])" + "VALUES" + "(getdate()" + "," + usr.Id_user.ToString() + ", 0); SELECT scope_identity();"; inventory_id = int.Parse(cmd.ExecuteScalar().ToString()); pb1.Minimum = 1; pb1.Maximum = data.Rows.Count; pb1.Value = pb1.Minimum; for (i = 1; i < data.Rows.Count; i++) { int show; if (bool.Parse(data.Rows[i][2].ToString())) show = 1; else show = 0; if (data.Rows[i][5].ToString() == "") { cmd.CommandText = "INSERT INTO [dbo].[inventorybody]" + "([id_inventory]" + ",[order_number]" + ",[order_found]" + ",[order_status_t]" + ",[order_status]" + ",[order_status_fact_t]" + ",[order_status_fact]" + ",[order_action_t]" + ",[order_action]" + ",[order_user]" + ",[exported])" + "VALUES" + "(" + inventory_id + ",'" + data.Rows[i][1].ToString() + "'" + "," + show + ",'" + data.Rows[i][3].ToString() + "'" + ",'" + data.Rows[i][8].ToString() + "'" + ",'" + data.Rows[i][4].ToString() + "'" + ",'" + data.Rows[i][9].ToString() + "'" + ",'" + data.Rows[i][7].ToString() + "'" + ",'" + data.Rows[i][11].ToString() + "'" + "," + usr.Id_user.ToString() + "" + "," + data.Rows[i][13].ToString() + ")"; } else { cmd.CommandText = "INSERT INTO [dbo].[inventorybody]" + "([id_inventory]" + ",[order_number]" + ",[order_found]" + ",[order_status_t]" + ",[order_status]" + ",[order_status_fact_t]" + ",[order_status_fact]" + ",[order_in]" + ",[order_out]" + ",[order_action_t]" + ",[order_action]" + ",[order_user] " + ",[exported] " + ")" + "VALUES" + "(" + inventory_id + ",'" + data.Rows[i][1].ToString() + "'" + "," + show + ",'" + data.Rows[i][3].ToString().Trim() + "'" + ",'" + data.Rows[i][8].ToString().Trim() + "'" + ",'" + data.Rows[i][4].ToString().Trim() + "'" + ",'" + data.Rows[i][9].ToString().Trim() + "'" + ",'" + ((DateTime)data.Rows[i][5]).Year.ToString("D4") + "/" + ((DateTime)data.Rows[i][5]).Month.ToString("D2") + "/" + ((DateTime)data.Rows[i][5]).Day.ToString("D2") + " " + ((DateTime)data.Rows[i][5]).ToShortTimeString() + "'" + ",'" + ((DateTime)data.Rows[i][6]).Year.ToString("D4") + "/" + ((DateTime)data.Rows[i][6]).Month.ToString("D2") + "/" + ((DateTime)data.Rows[i][6]).Day.ToString("D2") + " " + ((DateTime)data.Rows[i][6]).ToShortTimeString() + "'" + ",'" + data.Rows[i][7].ToString() + "'" + ",'" + data.Rows[i][11].ToString() + "'" + "," + usr.Id_user.ToString() + "," + data.Rows[i][13].ToString() + ")"; } cmd.ExecuteNonQuery(); pb1.Value = i; Application.DoEvents(); } transaction.Commit(); inv = new Inventory(inventory_id); closed = true; CheckStatus(); } catch (Exception ex) { transaction.Rollback(); MessageBox.Show("Произошла ошибка во время сохранения инвентаризации.\n" + ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace, "Ошибка сохранения", MessageBoxButtons.OK, MessageBoxIcon.Warning); } finally { lblSave.Visible = false; } } }
private void btnAction1_Click(object sender, EventArgs e) { if (lstInventory.SelectedValue != null) { chlstOrderInventory.Items.Clear(); Inventory inv = new Inventory(int.Parse(lstInventory.SelectedValue.ToString())); lblInfo.Text = "Загружена инвентаризация № " + inv.id + "; Табличная часть из " + inv.body.Count.ToString() + " элементов"; pb1.Minimum = 0; pb1.Maximum = inv.body.Count; pb1.Value = pb1.Minimum; foreach (InventoryBody item in inv.body) { using (SqlConnection c = new SqlConnection(settings.Connection_string)) { string info = ""; c.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "SELECT * FROM [order] WHERE [number] = '" + item.number + "'"; cmd.CommandTimeout = 9000; cmd.Connection = c; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable t = new DataTable(); da.Fill(t); if (t.Rows.Count > 0) { info += "Найден заказ №" + t.Rows[0]["number"].ToString().Trim() + " статус заказа " + t.Rows[0]["status"].ToString().Trim(); cmd.CommandText = "SELECT MAX(event_date) AS d FROM orderevent WHERE (id_order =" + t.Rows[0]["id_order"].ToString() + ")"; cmd.CommandTimeout = 9000; if (!item.found) { info += " Заказ не был найден в момент инвентаризации."; DateTime maxevent = new DateTime(); try { maxevent = DateTime.Parse(cmd.ExecuteScalar().ToString()); info += " Последнее событие в заказе произошло " + maxevent.ToString().Trim() + "."; } catch { info += " Дату последнего события определить неудалось."; } if (inv.date > maxevent) { info += " После инвентаризации с заказом не работали, назначаем статус УТЕРЯН."; chlstOrderInventory.Items.Add( t.Rows[0]["number"].ToString().Trim() + ";" + t.Rows[0]["status"].ToString().Trim() , false); } else { info += " После инвентаризации с заказом работали, статус не меняется"; } } else { info += " Заказ был найден в момнет инветаризации. Ни каких действий не будет проводиться."; } } else { info += "Не найден заказ №" + item.number.Trim(); } lstinfo.Items.Add(info); lstinfo.SelectedIndex = lstinfo.Items.Count-1; info = ""; Application.DoEvents(); pb1.Value++; if (stop) return; } } pb1.Value = pb1.Minimum; } }