예제 #1
0
        public static bool SelectOneFromType(TypeEntity te)
        {
            try
            {
                string sql = "select * from Type where guid = '" + te.Guid + "'";
                string dbFile = "first";
                int temp = 0;
                TypeEntity je = new TypeEntity();

                using (SQLiteConnection sc1 = new SQLiteConnection(string.Format(SQLiteService.connectionFormat, dbFile)))
                {
                    SQLiteCommand sCom = new SQLiteCommand(sql, sc1);
                    sc1.Open();
                    using (SQLiteDataReader dr1 = sCom.ExecuteReader())
                    {
                        if (dr1.Read())
                        {
                            temp = 1;
                        }
                        dr1.Close();
                    }
                    sc1.Close();
                }

                //返回更新成功或者失败的标志
                if (temp > 0)
                {
                    return true;
                }
                return false;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
예제 #2
0
        public static TypeViewModel LoadDataAsTypeViewModel(string dbFile, string sql)
        {
            try
            {
                TypeViewModel vm = new TypeViewModel();
                vm.OcTypeEntities = new ObservableCollection<TypeEntity>();
                //System.Windows.MessageBox.Show(string.Format(SQLiteService.connectionFormat, dbFile));
                using (SQLiteConnection sc1 = new SQLiteConnection(string.Format(SQLiteService.connectionFormat, dbFile)))
                {
                    SQLiteCommand sCom = new SQLiteCommand(sql, sc1);
                    sc1.Open();
                    using (SQLiteDataReader dr1 = sCom.ExecuteReader())
                    {
                        while (dr1.Read())
                        {
                            //Jewelry je = new Jewelry();
                            //je.Guid = dr1["guid"].ToString();
                            //je.Image = helper.Base64ToImage(dr1["image"].ToString());
                            ////je.SaleWho = dr1["buytime"].ToString();
                            //je.BuyTime = helper.DateToString((DateTime)dr1["buytime"]);
                            //je.BuyPrice = (double)dr1["buyprice"];
                            //je.BuyWho = dr1["buywho"].ToString();
                            //je.GoldPrice = (double)dr1["goldprice"];
                            //je.Type = dr1["type"].ToString();
                            //je.Color = dr1["color"].ToString();
                            //je.Mark = dr1["mark"].ToString();
                            //je.BuySource = dr1["buySource"].ToString();
                            //je.OwnWho = dr1["ownwho"].ToString();
                            //je.State = dr1["state"].ToString();
                            //je.BorrowTime = helper.DateToString((DateTime)dr1["borrowtime"]);
                            //je.BorrowWho = dr1["borrowwho"].ToString();
                            //je.BorrowPirce = (double)dr1["borrowprice"];
                            //je.BorrowReturnTime = helper.DateToString((DateTime)dr1["borrowreturntime"]);
                            //je.SaleTime = helper.DateToString((DateTime)dr1["saletime"]);
                            //je.SaleWho = dr1["salewho"].ToString();
                            //je.SalePirce = (double)dr1["saleprice"];
                            //je.SaleState = dr1["salestate"].ToString();
                            //je.Ohe = LoadHistory(je.Guid);

                            TypeEntity te = new TypeEntity();
                            te.Guid = dr1["guid"].ToString();
                            te.Type = dr1["name"].ToString();
                            _totalCount = int.Parse(dr1["TotalCount"].ToString());
                            vm.OcTypeEntities.Add(te);
                        }
                        dr1.Close();
                    }
                    sc1.Close();
                }
                return vm;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
예제 #3
0
        public static bool SaveType(TypeEntity te, string type)
        {
            try
            {
                //定义temp存储影响行数
                int temp = 0;
                //判断是否是新增,如果是新增的话,选择不同的语句,为了createtime的插入或者不插入
                bool isnew = false;
                //插入数据库的类别
                string insertType = "";
                switch (type)
                {
                    case "JeweleyCategoryType":
                        insertType = GlobalBindingHelper.JewelryType;
                        break;
                    case "JeweleyOwnType":
                        insertType = GlobalBindingHelper.OwnType;
                        break;
                    case "JeweleyColorType":
                        insertType = GlobalBindingHelper.ColorType;
                        break;
                    default:
                        break;
                }

                //判断数据库中是否存在一条记录
                if (!SelectOneFromType(te))
                {
                    isnew = true;
                }

                string connectString = string.Format(connectionFormat, "first");
                string sqlAll, sql;
                //判断是编辑false,还是新增true
                if (isnew)
                {
                    sqlAll = "insert into Type (name,category,createtime,updatetime,guid) Values('{0}','{1}','{2}','{3}','{4}')";
                    sql = string.Format(sqlAll, te.Type, insertType, System.DateTime.Now.ToString("s"), System.DateTime.Now.ToString("s"),te.Guid);
                }
                else
                {
                    sqlAll = "update Type set name = '{0}',updatetime = '{1}' where guid='{2}'";
                    sql = string.Format(sqlAll, te.Type, System.DateTime.Now.ToString("s"), te.Guid);
                }

                using (SQLiteConnection sqlcon = new SQLiteConnection(connectString))
                {
                    SQLiteCommand cmd = new SQLiteCommand(sql, sqlcon);
                    sqlcon.Open();
                    temp = cmd.ExecuteNonQuery();
                    sqlcon.Close();
                }

                //返回更新成功或者失败的标志
                if (temp > 0)
                {
                    return true;
                }
                return false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw ex;
            }
        }
예제 #4
0
        internal static void CreateNew(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                //获取参数,如果为空,就返回
                Dictionary<string, object> paraDic = e.Parameter as Dictionary<string, object>;
                if (paraDic == null)
                    return;
                //定义参数
                string type = ""; //新增哪个页面
                string pageID = ""; //导航页面
                bool isEdit = false; //是否可以编辑,就是是否出现保存和取消按钮
                string title = ""; //页面的标题
                //获取对应的参数
                if (paraDic.ContainsKey("type"))
                {
                    type = (string)paraDic["type"];
                }
                if (paraDic.ContainsKey("pageID"))
                {
                    pageID = (string)paraDic["pageID"];
                }
                if (paraDic.ContainsKey("isEdit"))
                {
                    isEdit = (bool)paraDic["isEdit"];
                }
                if (paraDic.ContainsKey("title"))
                {
                    title = (string)paraDic["title"];
                }
                switch (type)
                {
                    //珠宝增加
                    case "GoodsType":
                        ObservableCollection<Jewelry> main_ic = paraDic["context1"] as ObservableCollection<Jewelry>;
                        if (main_ic != null)
                        {
                            Jewelry _je = new Jewelry(true);
                            //main_ic.Add(_je);
                            WinDetail wd1 = new WinDetail(_je, isEdit, title);
                            wd1.PageFrame.Navigate(new Uri(Tools.PageTool(pageID), UriKind.RelativeOrAbsolute));
                            bool? res = wd1.ShowDialog();

                            if (res.HasValue && res.Value)
                            {

                            }
                            CommonReflashData((FrameworkElement)paraDic["context2"]);
                        }
                        break;
                    //珠宝类别增加
                    case "JeweleyCategoryType":
                    //珠宝归属人增加
                    case "JeweleyOwnType":
                    //珠宝颜色增加
                    case "JeweleyColorType":
                        //上面三个类别都用同一个操作
                        ObservableCollection<TypeEntity> ObTE = paraDic["context1"] as ObservableCollection<TypeEntity>;
                        if (ObTE != null)
                        {
                            TypeEntity _te = new TypeEntity(true);
                            //main_ic.Add(_je);
                            WinDetail2 wd1 = new WinDetail2(_te, isEdit, title);
                            wd1.PageFrame.Navigate(new Uri(Tools.PageTool(pageID), UriKind.RelativeOrAbsolute));
                            bool? res = wd1.ShowDialog();

                            if (res.HasValue && res.Value)
                            {

                            }
                            CommonReflashData((FrameworkElement)paraDic["context2"]);
                        }
                        break;
                    case "":
                        break;
                    default:
                        break;
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
                //记录日志,暂未添加

            }
            finally
            {

            }
        }