public static List <ColorItem> StringToColorItem(string colorList) { string delimiter = "^"; List <ColorItem> rlt = new List <ColorItem>(); if (!string.IsNullOrEmpty(colorList)) { string[] colors = colorList.Split(",".ToCharArray()); foreach (string color in colors) { if (!string.IsNullOrEmpty(color)) { string[] colorString = color.Split(delimiter.ToCharArray()); ColorItemModel itemModel = Settings.ViewModels.ColorSettingsVM.ColorSettings.Items.FirstOrDefault(x => x.Code == colorString[0] && x.Name == colorString[1]); if (itemModel != null) { rlt.Add(new ColorItem() { item = itemModel, codeAid = colorString[2], amount = colorString[3] }); } } } } return(rlt); }
public static void CreateColor(ColorItemModel item) { using (SQLiteConnection conn = new SQLiteConnection(AppSettings.ConnectString)) { conn.Open(); using (SQLiteCommand cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = @"INSERT INTO ColorSettings (Code, Name, UpdatedTime) VALUES (@p1,@p2,@p3)"; cmd.Parameters.Add(new SQLiteParameter("@p1", item.Code)); cmd.Parameters.Add(new SQLiteParameter("@p2", item.Name)); cmd.Parameters.Add(new SQLiteParameter("@p3", DateTime.Now)); cmd.ExecuteNonQuery(); } } }
public static void UpdateColor(string oldCode, string oldName, ColorItemModel item) { using (SQLiteConnection conn = new SQLiteConnection(AppSettings.ConnectString)) { conn.Open(); using (SQLiteCommand cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = @"Update ColorSettings SET Code=@p1, Name=@p2, UpdatedTime=@p3 WHERE Code=@p4 and Name=@p5"; cmd.Parameters.Add(new SQLiteParameter("@p1", item.Code)); cmd.Parameters.Add(new SQLiteParameter("@p2", item.Name)); cmd.Parameters.Add(new SQLiteParameter("@p3", DateTime.Now)); cmd.Parameters.Add(new SQLiteParameter("@p4", oldCode)); cmd.Parameters.Add(new SQLiteParameter("@p5", oldName)); cmd.ExecuteNonQuery(); } } }